A graph is an ordered pair G = (V, E)
comprising a set V
of vertices or nodes, and a collection of pairs of vertices from V
called edges of the graph.
For example, for the above graph,
V = { 1, 2, 3, 4, 5, 6 }
E = { (1, 4), (1, 6), (2, 6), (4, 5), (5, 6) }
E = { (1, 4), (1, 6), (2, 6), (4, 5), (5, 6) }
In this post, we have listed out commonly asked interview questions that use graph data structure:
- Terminology and Representations of GraphsBeginner
- Graph Implementation – C, C++, C++ STL, Java Collections, PythonBeginner
- Depth First Search (DFS)Medium
- Arrival and departure time of vertices in DFSEasy
- Types of edges involved in DFS and relation between themBeginner
- Determine whether a graph is Bipartite using DFSMedium
- Topological Sort Algorithm for DAGMedium
- Kahn’s Topological Sort AlgorithmMedium
- Transitive closure of a graphEasy
- Determine whether an undirected graph is a tree (Acyclic Connected Graph)Medium
- 2–Edge Connectivity in a graphHard
- 2–Vertex Connectivity in a graphHard
- Check if a digraph is a DAG (Directed Acyclic Graph) or notMedium
- Disjoint–Set Data Structure (Union–Find Algorithm)Medium
- Check if a graph is strongly connected or notEasy
- Check if a graph is strongly connected or not using one DFS TraversalHard
- Union–Find Algorithm for cycle detection in a graphMedium
- Single-Source Shortest Paths – Bellman–Ford AlgorithmMedium
- All-Pairs Shortest Paths – Floyd Warshall AlgorithmEasy
- Find the cost of the shortest path in DAG using one pass of Bellman–FordMedium
- Determine a negative-weight cycle in a graphMedium
- Find all Possible Topological Orderings of a DAGHard
- Find correct order of alphabets in a given dictionary of ancient originHard
- Find the longest path in a Directed Acyclic Graph (DAG)Hard
- Print all k–colorable configurations of a graph (Vertex coloring of a graph)Medium
- Print all Hamiltonian paths present in a graphHard
- Graph Coloring ProblemMedium
- Kruskal’s Algorithm for finding Minimum Spanning TreeHard
- Eulerian cycle in directed graphsHard
- Find root vertex of a graphMedium
- Check whether an undirected graph is EulerianMedium
- Check if a set of words can be rearranged to form a circleHard
- Find itinerary from the given list of departure and arrival airportsEasy
- Single-Source Shortest Paths – Dijkstra’s AlgorithmMedium
- Chess Knight Problem | Find the shortest path from source to destinationHard
- Snake and Ladder ProblemHard
- Breadth-First Search (BFS)Medium
- Check if an undirected graph contains a cycle or notMedium
- Find maximum cost path in a graph from a given source to a given destinationMedium
- Total paths in a digraph from a given source to a destination having exactly
m
edgesMedium - Least cost path in a digraph from a given source to a destination having exactly
m
edgesMedium - Depth-First Search (DFS) vs Breadth-First Search (BFS)Beginner
- Bipartite GraphMedium
- Compute the least cost path in a weighted digraph using BFSMedium
- Find the path between given vertices in a directed graphEasy
- Construct a directed graph from an undirected graph that satisfies given constraintsMedium