SlideShare une entreprise Scribd logo
1  sur  22
INTRODUCTION TO GRAPH TRAVERSAL
UNDERSTANDING THE BREADTH-FIRST SEARCH ALGORITHM WITH AN EXAMPLE
APPLICATIONS OF BREADTH-FIRST SEARCH
WHAT IS THE BREADTH-FIRST SEARCH?
www.edureka.co
BREADTH-FIRST SEARCH ALGORITHM PSEUDOCODE
INTRODUCTION TO GRAPH TRAVERSAL
www.edureka.co
The process of visiting and exploring a graph for processing is called graph traversal. To be more
specific it is all about visiting and exploring each vertex and edge in a graph such that all the
vertices are explored exactly once.
Introduction To Graph Traversal
www.edureka.co
WHAT IS THE BREADTH-FIRST SEARCH?
www.edureka.co
Breadth-First Search algorithm is a graph traversing technique, where you select a random initial node
(source or root node) and start traversing the graph layer-wise in such a way that all the nodes and their
respective children nodes are visited and explored.
What is the Breadth-First Search Algorithm?
www.edureka.co
a
b
d
c
e
a
b
d
c
e
ExploringVisiting
BREADTH-FIRST SEARCH EXAMPLE
www.edureka.co
Breadth-First Search algorithm follows a simple, level-based approach to solve a problem. Consider
the above binary tree (which is a graph). Our aim is to traverse the graph by using the Breadth-First
Search Algorithm.
Understanding the Breadth-First Search Algorithm with an example
www.edureka.co
a
b c
d e f g
What is a
Queue?
Binary Tree
A queue is an abstract data structure that follows the First-In-First-Out methodology (data inserted
first will be accessed first). It is open on both ends, where one end is always used to insert data and
the other is used to remove data.
What is a Queue?
www.edureka.co
Enqueue operation Dequeue operation
Enqueue operation: To insert data
Dequeue operation: To remove data
www.edureka.co
a
b c
d e f g
Step 1: Take an Empty Queue.
Queue
Binary Tree
www.edureka.co
a
b c
d e f g
Step 2: Select a starting node (visiting a node) and insert it into the Queue.
Queue
Binary Tree
a
www.edureka.co
a
b c
d e f g
Step 3: Provided that the Queue is not empty, extract the node from the Queue and insert its child nodes
(exploring a node) into the Queue.
Queue
Binary Tree
a
www.edureka.co
a
b c
d e f g
Step 3: Provided that the Queue is not empty, extract the node from the Queue and insert its child nodes
(exploring a node) into the Queue.
Queue
Binary Tree
bc a
www.edureka.co
a
b c
d e f g
Step 4: Print the extracted node.
Queue
Binary Tree
bc
Print:
a
a
www.edureka.co
www.edureka.co
• ‘a’ is the root node: insert it into the Queue
• Extract node ‘a’ and insert the child nodes of ‘a’, i.e.,
‘b’ and ‘c
• Print node ‘a’
• The queue is not empty and has node ‘b’ and ‘c’.
Extract ‘b’ and insert the child nodes of ‘b’, i.e., node
‘d’ and ‘e’
• Repeat the steps until the queue gets empty
BREADTH-FIRST SEARCH ALGORITHM
PSEUDOCODE
www.edureka.co
www.edureka.co
(G, s) is input, here G is the graph and s is the root node
A queue ‘Q’ is created and initialized with the source node ‘s’
All child nodes of ‘s’ are marked
Extract ‘s’ from queue and visit the child nodes
Process all the child nodes of v
Stores w (child nodes) in Q to further visit its child nodes
APPLICATIONS OF BREADTH-FIRST SEARCH
ALGORITHM
www.edureka.co
Breadth-first Search is a simple graph traversal method that has a surprising range of applications. Here are a few
interesting ways in which Bread-First Search is being used:
Applications Of Breadth-First Search Algorithm
www.edureka.co
Breadth First
Search Applications
Web crawling
GPS Navigation Finding the
shortest path
Broadcasting
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
www.edureka.co

Contenu connexe

Tendances

Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
 

Tendances (20)

Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 
Binary search tree
Binary search treeBinary search tree
Binary search tree
 
Graph colouring
Graph colouringGraph colouring
Graph colouring
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Dfs
DfsDfs
Dfs
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Uninformed Search technique
Uninformed Search techniqueUninformed Search technique
Uninformed Search technique
 

Similaire à Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutorial | Edureka

(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
Radhika Srinivasan
 

Similaire à Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutorial | Edureka (20)

Ai1.pdf
Ai1.pdfAi1.pdf
Ai1.pdf
 
Search algorithms master
Search algorithms masterSearch algorithms master
Search algorithms master
 
Clustering techniques
Clustering techniquesClustering techniques
Clustering techniques
 
graph2tab, a library to convert experimental workflow graphs into tabular for...
graph2tab, a library to convert experimental workflow graphs into tabular for...graph2tab, a library to convert experimental workflow graphs into tabular for...
graph2tab, a library to convert experimental workflow graphs into tabular for...
 
Advanced c c++
Advanced c c++Advanced c c++
Advanced c c++
 
Web development basics (Part-3)
Web development basics (Part-3)Web development basics (Part-3)
Web development basics (Part-3)
 
Data structure note
Data structure noteData structure note
Data structure note
 
Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...Bidirectional graph search techniques for finding shortest path in image base...
Bidirectional graph search techniques for finding shortest path in image base...
 
Data structure
Data structureData structure
Data structure
 
SEMAC Graph Node Embeddings for Link Prediction
SEMAC Graph Node Embeddings for Link PredictionSEMAC Graph Node Embeddings for Link Prediction
SEMAC Graph Node Embeddings for Link Prediction
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
bfs[1].pptx
bfs[1].pptxbfs[1].pptx
bfs[1].pptx
 
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPHPATH FINDING SOLUTIONS FOR GRID BASED GRAPH
PATH FINDING SOLUTIONS FOR GRID BASED GRAPH
 
Data structures
Data structuresData structures
Data structures
 
Declarativemagic
DeclarativemagicDeclarativemagic
Declarativemagic
 
DDW Clinic Session 1.pdf
DDW Clinic Session 1.pdfDDW Clinic Session 1.pdf
DDW Clinic Session 1.pdf
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
 
Breadth first search
Breadth first search Breadth first search
Breadth first search
 
(Binary tree)
(Binary tree)(Binary tree)
(Binary tree)
 
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxPPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
 

Plus de Edureka!

Plus de Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Breadth First Search Algorithm In 10 Minutes | Artificial Intelligence Tutorial | Edureka

  • 1.
  • 2. INTRODUCTION TO GRAPH TRAVERSAL UNDERSTANDING THE BREADTH-FIRST SEARCH ALGORITHM WITH AN EXAMPLE APPLICATIONS OF BREADTH-FIRST SEARCH WHAT IS THE BREADTH-FIRST SEARCH? www.edureka.co BREADTH-FIRST SEARCH ALGORITHM PSEUDOCODE
  • 3. INTRODUCTION TO GRAPH TRAVERSAL www.edureka.co
  • 4. The process of visiting and exploring a graph for processing is called graph traversal. To be more specific it is all about visiting and exploring each vertex and edge in a graph such that all the vertices are explored exactly once. Introduction To Graph Traversal www.edureka.co
  • 5. WHAT IS THE BREADTH-FIRST SEARCH? www.edureka.co
  • 6. Breadth-First Search algorithm is a graph traversing technique, where you select a random initial node (source or root node) and start traversing the graph layer-wise in such a way that all the nodes and their respective children nodes are visited and explored. What is the Breadth-First Search Algorithm? www.edureka.co a b d c e a b d c e ExploringVisiting
  • 8. Breadth-First Search algorithm follows a simple, level-based approach to solve a problem. Consider the above binary tree (which is a graph). Our aim is to traverse the graph by using the Breadth-First Search Algorithm. Understanding the Breadth-First Search Algorithm with an example www.edureka.co a b c d e f g What is a Queue? Binary Tree
  • 9. A queue is an abstract data structure that follows the First-In-First-Out methodology (data inserted first will be accessed first). It is open on both ends, where one end is always used to insert data and the other is used to remove data. What is a Queue? www.edureka.co Enqueue operation Dequeue operation Enqueue operation: To insert data Dequeue operation: To remove data
  • 10. www.edureka.co a b c d e f g Step 1: Take an Empty Queue. Queue Binary Tree
  • 11. www.edureka.co a b c d e f g Step 2: Select a starting node (visiting a node) and insert it into the Queue. Queue Binary Tree a
  • 12. www.edureka.co a b c d e f g Step 3: Provided that the Queue is not empty, extract the node from the Queue and insert its child nodes (exploring a node) into the Queue. Queue Binary Tree a
  • 13. www.edureka.co a b c d e f g Step 3: Provided that the Queue is not empty, extract the node from the Queue and insert its child nodes (exploring a node) into the Queue. Queue Binary Tree bc a
  • 14. www.edureka.co a b c d e f g Step 4: Print the extracted node. Queue Binary Tree bc Print: a a
  • 16. www.edureka.co • ‘a’ is the root node: insert it into the Queue • Extract node ‘a’ and insert the child nodes of ‘a’, i.e., ‘b’ and ‘c • Print node ‘a’ • The queue is not empty and has node ‘b’ and ‘c’. Extract ‘b’ and insert the child nodes of ‘b’, i.e., node ‘d’ and ‘e’ • Repeat the steps until the queue gets empty
  • 18. www.edureka.co (G, s) is input, here G is the graph and s is the root node A queue ‘Q’ is created and initialized with the source node ‘s’ All child nodes of ‘s’ are marked Extract ‘s’ from queue and visit the child nodes Process all the child nodes of v Stores w (child nodes) in Q to further visit its child nodes
  • 19. APPLICATIONS OF BREADTH-FIRST SEARCH ALGORITHM www.edureka.co
  • 20. Breadth-first Search is a simple graph traversal method that has a surprising range of applications. Here are a few interesting ways in which Bread-First Search is being used: Applications Of Breadth-First Search Algorithm www.edureka.co Breadth First Search Applications Web crawling GPS Navigation Finding the shortest path Broadcasting
  • 21. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co