Graph Algorithms - Interview Questions

How do you traverse a graph using Breadth First Search (BFS)?

 FAQ

In a Breadth First Search (BFS) traversal of a graph, you traverse all vertices at one level before moving on to the next level.

You start by traversing from any vertex say currentVertex. If adjacent vertices to the currentVertex are not yet visited then print their value. Then repeat the same for children of the currentVertex.

How do you traverse a graph using Depth First Search (DFS)?

 FAQ

In a Depth First Search (DFS) traversal of a graph, you traverse the vertices depth wise rather than breadth wise. You start by traversing from any vertex say currentVertex - pick any one of it's adjacent vertex and keep traversing adjacent vertices until the farthest vertex is reached. Then you move back to the starting vertex and repeat the same for another adjecent vertex. You repeat this process until all the vertices are traversed.

 
Subscribe to our Questions

 

Algorithms - Interview Questions

Basics of AlgorithmsRecursion AlgorithmsGraph Algorithms
 
MASTER Algorithms  

Top ranked courses to help you master Algorithms skills.
Master the Coding Interview: Data Structures + Algorithms

iconicon

Offered By - Andrei Neagoie
Platform - Udemy
Rating - * * * * *
Students Enrolled - 100,000 +

Algorithms

iconicon

Offered By - Princeton University
Platform - Coursera
Rating - * * * * *
Students Enrolled - 850,000 +

RECOMMENDED RESOURCES
Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example