Talk Ai
Talk Ai
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Introduction
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Why AI?
Many problem specific algorithms have been developed and are
now available
Those are well studied in a typical course on algorithms
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Why AI?
Many problem specific algorithms have been developed and are
now available
Those are well studied in a typical course on algorithms
Some algorithms are of a more general nature, eg GraphSearch
Those allow a wide variety of problems to be solved by posing
those as GraphSearch problems
That can be thought of as an “intelligent” way to handle some
problems without having to formulate specific solutions to those
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Why AI?
Many problem specific algorithms have been developed and are
now available
Those are well studied in a typical course on algorithms
Some algorithms are of a more general nature, eg GraphSearch
Those allow a wide variety of problems to be solved by posing
those as GraphSearch problems
That can be thought of as an “intelligent” way to handle some
problems without having to formulate specific solutions to those
Traditional algorithmic approaches tend to find exact or near exact
solutions to problems
Many practical problems such a speech, vision, decision making
are hard to formulate this way
Those require a more “human” style handling
That’s another important class of problems which come under the
AI/ML category
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Why AI?
Many problem specific algorithms have been developed and are
now available
Those are well studied in a typical course on algorithms
Some algorithms are of a more general nature, eg GraphSearch
Those allow a wide variety of problems to be solved by posing
those as GraphSearch problems
That can be thought of as an “intelligent” way to handle some
problems without having to formulate specific solutions to those
Traditional algorithmic approaches tend to find exact or near exact
solutions to problems
Many practical problems such a speech, vision, decision making
are hard to formulate this way
Those require a more “human” style handling
That’s another important class of problems which come under the
AI/ML category
There is also a mingling of the two approaches TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
You are given a binary tree pointed to by binTreePtr btP (see the
typedef below for defining a binary tree type).
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
352 243
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
352 243
For the binary tree T pointed to by btP, let the array bpDPCH[3]
indicate the depth of T , the maximum depth to which T is a perfect
binary tree and the depth to which T is a complete binary tree,
respectively and let
checkBinT(binTreePtr btP, int bpDPCH[3])
return T/F to indicate whether T satisfies the max heap property.
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Historical perspective of AI
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
queen may be placed in each column in the next available
row
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
queen may be placed in each column in the next available
row
Liquid in tubes:
2
3 5
1 4
3
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
queen may be placed in each column in the next available
row
Liquid in tubes:
2
3 5 liquid in non-empty tube can be drained into another tube
1 4
3 until that tube is full or the current tube is empty
liquid quantities in the tubes to be updated accordingly
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
queen may be placed in each column in the next available
row
Liquid in tubes:
2
3 5 liquid in non-empty tube can be drained into another tube
1 4
3 until that tube is full or the current tube is empty
liquid quantities in the tubes to be updated accordingly
8-puzzle:
2 8 3
1 6 4
7 5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Production systems
These derive from a computational formalism proposed by Post (1943)
that was based on string replacement rules
Also called rule-based systems
N-Queen:
Q
queen may be placed in each column in the next available
row
Liquid in tubes:
2
3 5 liquid in non-empty tube can be drained into another tube
1 4
3 until that tube is full or the current tube is empty
liquid quantities in the tubes to be updated accordingly
8-puzzle:
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Search techniques
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Search techniques
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
Adversarial search
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
Adversarial search
Two-player games
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
Adversarial search
Two-player games
Alpha-beta pruning
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
Adversarial search
Two-player games
Alpha-beta pruning
Constraint Satisfaction Problems
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing
Evolutionary algorithms
Adversarial search
Two-player games
Alpha-beta pruning
Constraint Satisfaction Problems
Puzzles are common examples TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Propositional logic
Predicate logic
Inferencing using rules
Planning moves in a state space
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Quantifying uncertainty
Joint distribution
Independence
Bayes rule
Probabilistic reasoning
Knowledge representation
Bayesian network
Conditional independence and D-separation
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
Perceptron
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
Perceptron
ANN with one hidden layer
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
Perceptron
ANN with one hidden layer
DNN with multiple hidden layers
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
Perceptron
ANN with one hidden layer
DNN with multiple hidden layers
CNN using convolution
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities
Reinforcement learning Learning based on feedback on outcomes
(rewards and punishments)
Model-based learning
Model-free learning
Artificial neural networks
Perceptron
ANN with one hidden layer
DNN with multiple hidden layers
CNN using convolution
RNN using the recurrent theme TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Simple searching
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Graph representation
Adjacency matrix
A[ı, ȷ] = A[ȷ, ı] = 1 if and only if there is an edge between
vı and vȷ
A is symmetric for (simple undirected) graphs
Not symmetric for digraphs
|V | × |V2 | enough to store adjacency information
Entries of A may also indicate weights, absence of edge
may be indicated by ∞
Uneconomic for sparse graphs
Adjacency list
A vector L of V linked lists indicate the adjacencies of
each vertex
If vx is adjacent to {v1 , v2 , . . . , vk }, the linked list for L[vx ]
points to the linked list with entries {v1 , v2 , . . . , vk }
Uneconomic for dense graphs
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4 pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8 mark u as in-stack
F
9 push u into S
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4 pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8 mark u as in-stack
F
9 push u into S
10 add edge ⟨v , u⟩ to T
G
A
11 pre-number u as d; incr d
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8 mark u as in-stack
F
9 push u into S
C
10 add edge ⟨v , u⟩ to T
G
A
11 pre-number u as d; incr d
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8 mark u as in-stack
F
9 push u into S
3
C
10 add edge ⟨v , u⟩ to T
G
A
11 pre-number u as d; incr d
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
G
8 mark u as in-stack
F
9 push u into S
3
C
10 add edge ⟨v , u⟩ to T
G
A
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
G
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
G
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
pre-number v as d; incr d
D
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
G
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
E
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
E
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
E
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
E
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
2
D
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2
pre-number v as d; incr d
5 while (S is not empty) do
I
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12
pre-number v as d; incr d
5
B
while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12
pre-number v as d; incr d
5
B
while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12
pre-number v as d; incr d
5
B
while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12
pre-number v as d; incr d
5
B
while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
H
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5,14
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4,15
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5,14
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3,16
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4,15
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5,14
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2,17
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3,16
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4,15
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5,14
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
A
Starting at v of G(V , E); using stack (or list) S
1,18
1 all nodes of G are initially marked unvisited
2 initialise d ← 1; initialise tree T to empty
3 mark v as in-stack; push v into S
B
4
7,10
2,17
12,13
pre-number v as d; incr d
5 while (S is not empty) do
6 v ←top(S)
7
E
if v has an unvisited neighbour u
8,9
8 mark u as in-stack
F
9 push u into S
3,16
10 add edge ⟨v , u⟩ to T
G
11 pre-number u as d; incr d
4,15
S:
12 else
13 mark v as visited; pop S
14 post-number v as d; incr d
H
I
15 done
6,11
5,14
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Section outline
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S:
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: A
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: B C D
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: C D F H
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: D F H E
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: F H E I
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: H E I G
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: E I G
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: I G
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S: G
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S:
mark v as visited
10 enqueue v into S
11 add edge ⟨u, v ⟩ to T
12 done
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4 enqueue v into S
5 while (S is not empty) do E G
6 u ←dequeue(S)
7 foreach unvisited v st D I
8 ⟨u, v ⟩ ∈ E
9
S:
mark v as visited
10 enqueue v into S Depth of a node in the BFS tree is
11 add edge ⟨u, v ⟩ to T independent of the order in which
12 done children of nodes are enqueued
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
3 repeat
4 mark v as visited; enqueue v into S // at the end
5 number v as bj ; incr bj
6 while (S is not empty) do
7 u ←dequeue(S) // remove u from front of S
8 foreach unvisited neighbour v of u
9 mark v as visited; enqueue v into S
// insert v at end of S
10 add edge ⟨u, v ⟩ to T
11 number v as bj ; incr bj
12 done
13 incr(j); bj ← 1 ; choose unvisited vertex v , if any
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
N-queen problem
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
4-queen problem
solved by backtracking
Q Q by way of DFS
Starting board is empty
Only viable partial
placements nodes are
Q Q Q
Q Q Q shown
Dead ends are shown
in violet
Q Q Successful placement
Q Q
Q Q
of all queens is shown
in green
Exploration stops after
Q
Q successful placement
Q of all queens
Q
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Q
Q
Q
Q
Q
Q
Q Q
Q
Q
Q
Q
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Liquids in tubes
2 5 5 7
7 7 7 7
5 5 2 2
5 5 5 5
3 0 3 1
3 3 3 3
7
7
3
5
0
3
7 4 4
7 7 7
0 3 3
5 5 5
3 3 3
3 3 3
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Liquids in tubes
2 5 5 7
7 7 7 7
5 5 2 2
5 5 5 5
3 0 3 1
3 3 3 3
7
7
3
5
0
3
7 4 4
7 7 7
0 3 3
5 5 5
3 3 3
3 3 3
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Liquids in tubes
2 5 5 7
7 7 7 7
5 5 2 2
5 5 5 5
3 0 3 1
3 3 3 3
7
7
3
5
0
3
7 4 4
7 7 7
0 3 3
5 5 5
3 3 3
3 3 3
TECHNO
OF
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1
Liquids in tubes
2 5 5 7
7 7 7 7
5 5 2 2
5 5 5 5
3 0 3 1
3 3 3 3
7
7
3
5
0
3
7 4 4
7 7 7
0 3 3
5 5 5
3 3 3
3 3 3
GY
ITU
IAN INST
KH
01
ARAGPUR
IND
19 5 1