Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views114 pages

Talk Ai

The document outlines an AI course by Chittaranjan Mandal from IIT Kharagpur, focusing on AI development and intelligent searching. It discusses the importance of AI, the evolution of algorithms, and presents examples of algorithmic versus AI/ML approaches. The course includes sections on historical perspectives, search techniques, and production systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views114 pages

Talk Ai

The document outlines an AI course by Chittaranjan Mandal from IIT Kharagpur, focusing on AI development and intelligent searching. It discusses the importance of AI, the evolution of algorithms, and presents examples of algorithmic versus AI/ML approaches. The course includes sections on historical perspectives, search techniques, and production systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 114

Table of Parts

Introduction Simple searching

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 1 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 2 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Part I

Introduction

1 AI development 3 Beyond searching

2 Intelligent searching 4 AIML

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 2 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development

Section outline

1 AI development Historical perspective of AI


Why AI?

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 3 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 4 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 4 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 4 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 4 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

An example: Algorithmic v/s AIML approach

You are given a binary tree pointed to by binTreePtr btP (see the
typedef below for defining a binary tree type).

typedef struct binTreeTag {


int val;
struct binTreeTag *lC, *rC;
} binTreeNode, *binTreePtr;

You are required to write a recursive C function to determine whether


the given binary tree is also a binary max heap. The function prototype
should be:
int checkBinHeap (binTreePtr btP)
/* retval: F: not Bin Heap, T: is Bin Heap */

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 5 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

A binary max heap


481

352 243

194 175 146 117

18 29 710 811 612 413 314

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 6 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

A binary max heap


481

352 243

194 175 146 117

18 29 710 811 612 413 314

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 6 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Why AI?

Practice problem: Algorithmic vs AIML approach

Given a binary tree, present a recursive method to determine


whether it also satisfies the requirements of a binary min heap
For the same problem develop an AIML oriented solution
Assume you have adequate data samples to cover all the cases
that you needed to cover in your algorithmic solution
You should generate adequate (up to four sample points per
condition) sample data so that you can make sensible conclusions
Present a step by step training procedure which will cover the
various conditions
Finally, your procedure should be able to distinguish between
binary trees which are binary min heaps and those which are not

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 7 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Historical perspective of AI

Historical perspective of AI

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 8 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Historical perspective of AI

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 9 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Historical perspective of AI

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 10 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Historical perspective of AI

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 11 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AI development Historical perspective of AI

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 12 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching

Section outline

2 Intelligent searching Search techniques


Production systems

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 13 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Production systems

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 Move vaccancy up, if possible


1 6 4 Move vaccancy down, if possible
7 5 Move vaccancy left, if possible
Move vaccancy right, if possible
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 14 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques

Notion of search space


Start at a specified place in the search space
Have one or more goals to reach
Traverse efficiently through the search space to reach the goals, if
those are reachable
Otherwise, report that the goals are unreachable

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 15 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques

Notion of search space


Start at a specified place in the search space
Have one or more goals to reach
Traverse efficiently through the search space to reach the goals, if
those are reachable
Otherwise, report that the goals are unreachable
Practical search spaces are large
Specification of the search space may be challenging
May be probabilistically specified
May be partially observable (maze)
May have adversaries

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 15 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


Informed search

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


Informed search
Application of domain-specific heuristics to reduce
search complexity (A* algorithm), iterative deepening
Local search
Hill climbing
Simulated annealing

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Intelligent searching Search techniques

Search techniques (contd.)


Uninformed search
Adaptations of graph traversal algorithms
Bidirectional search
 for better efficiency
(O bℓ → O bℓ/2 )


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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 16 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Beyond searching

Section outline

3 Beyond searching Reasoning under


Knowledge representation uncertainty
and reasoning

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 17 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Beyond searching Knowledge representation and reasoning

Knowledge representation and reasoning

Propositional logic
Predicate logic
Inferencing using rules
Planning moves in a state space

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 18 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Beyond searching Reasoning under uncertainty

Reasoning under uncertainty

Quantifying uncertainty
Joint distribution
Independence
Bayes rule
Probabilistic reasoning
Knowledge representation
Bayesian network
Conditional independence and D-separation

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 19 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML

Section outline

4 AIML Machine learning

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 20 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

Machine learning
Classical learning

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

Machine learning
Classical learning
Linear regression

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

Machine learning
Classical learning
Linear regression
Decision trees

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

Machine learning
Classical learning
Linear regression
Decision trees
Supervised learning Learning based on specific knowledge
(labelling)
Unsupervised learning Learning based on similarities

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


AIML Machine learning

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 21 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Part II

Simple searching

5 Depth first traversal of a 6 Breadth first traversal


graph

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 22 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph

Section outline

5 Depth first traversal of a Graph representation


graph Simple DFTr using a stack

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 23 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Graph representation

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 24 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Depth first traversal of a graph Simple DFTr using a stack

Simple DFTr using a stack

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 25 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal

Section outline

6 Breadth first traversal numbering


Breadth first traversal of a N-queen problem
graph Liquids in tubes
Breadth first traversal with

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 26 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal of a graph

Breadth first traversal of a graph


Start at any v ∈ G(V , E) B H
1 mark all v ∈ V as unvisited
2 initialise tree T to empty
F
3 mark v as visited A C

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 27 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal with numbering

Breadth first traversal with numbering


Start at any v ∈ V ; queue S (or a list S) is used
1 mark all nodes of G as unvisited
2 initialise j ← 1, bj ← 1 ; initialise tree T to empty

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

14 until (no vertex is unvisited)

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 28 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Breadth first traversal with numbering

Breadth first traversal with numbering


Start at any v ∈ V ; queue S (or a list S) is used
T is the breadth first
1 mark all nodes of G as unvisited
2
spanning tree of G, if G
initialise j ← 1, bj ← 1 ; initialise tree T to empty
is simple and undirected
3 repeat
4
If G is a digraph, T may
mark v as visited; enqueue v into S // at the end
5 number v as bj ; incr bj
have multiple roots
6 while (S is not empty) do For simple undirected
7 u ←dequeue(S) // remove u from front of S graphs, the numbering of
8 foreach unvisited neighbour v of u nodes so obtained is the
9 mark v as visited; enqueue v into S breadth first numbering
// insert v at end of S
The repeat-until loop is
10 add edge ⟨u, v ⟩ to T
11
needed for graphs with
number v as bj ; incr bj
12
multiple components
done
13 incr(j); bj ← 1 ; choose unvisited vertex v , if any works trivially for single
14
component undirected
until (no vertex is unvisited)
graphs
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 28 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal N-queen problem

N-queen problem

Constraint satisfaction by backtracking


N queens are to be placed on a N × N chess board so that no two
queens are in attacking positions
No two queens should be on the same row, column or diagonals
Solution representation is important; queen-ȷ may be assumed to
be on row-ȷ, only its column needs to be determined
1-queen has a trivial solution
2-queen and 3-queen don’t have solutions
4-queen has multiple equivalent solutions

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 29 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal N-queen problem

N-queen problem (contd.)


1 nQueen BFS(n) {
2 for each c in 1..n, enQ(Q, newBoard wQueen(n, 1, c))
3 while (Q not empty)
4 b ← deQ(Q); ℓ ← last filled row(b) + 1;
5 if (ℓ > n) return b; // solution found with n queens placed
6 for each c in 1..n
7 b′ = newBoard wQueenAdded(b, ℓ, c)
8 if (viable(b’)) enQ(Q, b′ ) // otherwise b′ gets discarded
9 return ϵ; // failed
10 }

All possible viable queen placements are explored, adding a queen to


the next row at every possible column position
Lot of extra solution candidates are generated in the queue
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 30 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal N-queen problem

N-queen problem (contd.)


1 nQueen DFS(n,b) {
2 ℓ ← last filled row(b) + 1;
3 if (ℓ > n) return b; // solution found with n queens placed
4 for each c in 1..n
5 b′ = newBoard wQueenAdded(b, ℓ, c)
6 if (viable(b’))
7 return nQueen DFS(enQ(Q, b′ ))
8 // else backtrack from dead end to explore next possiblity
9 }

Initial call: nQueen DFS(n,empty board(n))


Now, only one sequence of decisions is pursued at a time
This is an example of backtracking
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 31 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal N-queen problem

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

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 32 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal N-queen problem

Attack constraints significantly restrict possibilities


of queen placements
Simkin: About (0.143n)n solutions for n-queen
problem
Henry V: A linear time algorithm for solving the
N-Queens Problem using only 5 patterns, doi. Q
org/10.1109/CSICC58665.2023.10105390
N-queen problem is in the class NP Q
5-queen problem is easily solved Q

Q
Q
Q
Q
Q
Q
Q Q
Q
Q
Q
Q
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 33 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Liquids in tubes

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

Solution representation: ⟨x, y, z⟩, 0 ≤ x ≤ 3, 0 ≤ y ≤ 5, 0 ≤ z ≤ 7, x + y + z = 10, total


number of configurations?
Can ⟨2, 1, 7⟩ be reached from the initial configuration of ⟨3, 0, 7⟩?
At any move, a jug is either emptied or filled

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 34 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Liquids in tubes

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

Solution representation: ⟨x, y, z⟩, 0 ≤ x ≤ 3, 0 ≤ y ≤ 5, 0 ≤ z ≤ 7, x + y + z = 10, total


number of configurations?
Can ⟨2, 1, 7⟩ be reached from the initial configuration of ⟨3, 0, 7⟩?
At any move, a jug is either emptied or filled
What is the search space, production system?

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 34 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Liquids in tubes

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

Solution representation: ⟨x, y, z⟩, 0 ≤ x ≤ 3, 0 ≤ y ≤ 5, 0 ≤ z ≤ 7, x + y + z = 10, total


number of configurations?
Can ⟨2, 1, 7⟩ be reached from the initial configuration of ⟨3, 0, 7⟩?
At any move, a jug is either emptied or filled
What is the search space, production system?
Scalability when number of jugs and their capacities increased?
Can the resulting graph be stored in memory?

TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 34 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^


Breadth first traversal Liquids in tubes

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

Solution representation: ⟨x, y, z⟩, 0 ≤ x ≤ 3, 0 ≤ y ≤ 5, 0 ≤ z ≤ 7, x + y + z = 10, total


number of configurations?
Can ⟨2, 1, 7⟩ be reached from the initial configuration of ⟨3, 0, 7⟩?
At any move, a jug is either emptied or filled
What is the search space, production system?
Scalability when number of jugs and their capacities increased?
Can the resulting graph be stored in memory?
Effect on search space / production system if tube can be fully discarded or filled from tap?
TECHNO
OF

Chittaranjan Mandal (IIT Kharagpur) AI – CS60045 July 24, 2025 34 / 34


LO
TE

GY
ITU
IAN INST

KH
01

ARAGPUR
IND
 

19 5 1

yog, kms kOflm^

You might also like