Q1. What is the time complexity of DFS on a graph with V vertices and E edges?
- A.O(V + E)✓ Correct
- B.O(V × E)
- C.O(E^2)
- D.O(V^2)
Explanation
DFS visits each vertex and explores each edge once, giving O(V + E) time complexity.
Topic in Data Structures & Algorithms
Graph algorithms solve problems on vertices connected by edges, such as exploring reachability, finding shortest paths and building minimum spanning trees. Traversal MCQs compare breadth-first search, which uses a queue, with depth-first search, which uses a stack or recursion, both running in O(V + E). Shortest-path items cover Dijkstra's algorithm and its failure with negative edges, Bellman-Ford for negative weights, and Floyd-Warshall for all pairs. For spanning trees you should contrast Prim's vertex-growing approach with Kruskal's edge-sorting method using union-find to detect cycles. Topological sorting on directed acyclic graphs, cycle detection and Tarjan's strongly connected components complete the set.
Below are 30 practice questions from a pool of 210 Graph Algorithms MCQs, one of 12 topics in Data Structures & Algorithms. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.
Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Q1. What is the time complexity of DFS on a graph with V vertices and E edges?
DFS visits each vertex and explores each edge once, giving O(V + E) time complexity.
Q2. What is a spanning tree of a connected graph?
A spanning tree is a subgraph that includes all vertices of the graph, is connected, and has no cycles (V-1 edges for V vertices).
Q3. What is a cycle in a graph?
A cycle is a path in a graph that starts and ends at the same vertex, visiting at least one other vertex, with no repeated edges.
Q4. What is Depth-First Search (DFS)?
DFS explores as far as possible along each branch before backtracking, using a stack (or recursion).
Q5. What data structure does DFS use?
DFS uses a stack (explicitly or via recursion's call stack) to track vertices to visit.
Q6. What is Breadth-First Search (BFS)?
BFS explores all vertices at the current depth level before moving to the next level, using a queue data structure.
Q7. What is the time complexity of BFS on a graph with V vertices and E edges?
BFS visits each vertex and explores each edge once, giving O(V + E) time complexity.
Q8. What data structure does BFS use?
BFS uses a queue to maintain the order of vertices to visit, processing them in FIFO order.
Q9. Can BFS find the shortest path in an unweighted graph?
BFS finds the shortest path (minimum number of edges) from a source to all other vertices in an unweighted graph.
Q10. What is a connected component in an undirected graph?
A connected component is a maximal subset of vertices where every pair of vertices is connected by a path.
Q11. What is Prim's algorithm used for?
Prim's algorithm finds the MST by starting from a vertex and greedily adding the cheapest edge connecting the tree to a vertex not yet in the tree.
Q12. What is topological sorting?
Topological sort produces a linear ordering of vertices in a Directed Acyclic Graph (DAG) where every directed edge goes from earlier to later in the ordering.
Q13. What type of graph is required for topological sorting?
Topological sorting is only possible on Directed Acyclic Graphs (DAGs). A cycle would make it impossible to define a valid ordering.
Q14. What is the time complexity of Dijkstra's algorithm using a binary heap?
Using a binary heap (priority queue), Dijkstra's algorithm runs in O((V + E) log V) time.
Q15. How can you detect a cycle in a directed graph?
A cycle in a directed graph can be detected using DFS: if a back edge (to an ancestor in the DFS tree) is found, a cycle exists.
Q16. What is the time complexity of the Bellman-Ford algorithm?
Bellman-Ford relaxes all E edges V-1 times, giving O(V × E) time complexity.
Q17. What is Dijkstra's algorithm used for?
Dijkstra's algorithm finds the shortest path from a single source vertex to all other vertices in a graph with non-negative edge weights.
Q18. What is Kruskal's algorithm used for?
Kruskal's algorithm finds the Minimum Spanning Tree by sorting edges by weight and adding them if they don't form a cycle (using Union-Find).
Q19. What is the Bellman-Ford algorithm used for?
Bellman-Ford finds shortest paths from a single source and can handle negative edge weights. It also detects negative weight cycles.
Q20. What is the Union-Find (Disjoint Set Union) data structure used for?
Union-Find efficiently supports union (merge two sets) and find (determine which set an element belongs to) operations, commonly used in Kruskal's MST algorithm.
Q21. What is an articulation point (cut vertex) in a graph?
An articulation point is a vertex whose removal (along with its edges) increases the number of connected components in the graph.
Q22. Which algorithms can find Strongly Connected Components?
Kosaraju's algorithm (two DFS passes) and Tarjan's algorithm (single DFS with stack) both find SCCs in O(V + E) time.
Q23. What is the maximum flow problem?
The maximum flow problem finds the greatest rate of flow through a flow network from a source to a sink, respecting edge capacities.
Q24. What is the Ford-Fulkerson method for maximum flow?
Ford-Fulkerson repeatedly finds augmenting paths from source to sink in the residual graph and increases flow along those paths until no augmenting path exists.
Q25. What is a bridge in a graph?
A bridge is an edge whose removal increases the number of connected components. It can be found using modified DFS in O(V + E) time.
Q26. What are Strongly Connected Components (SCCs) in a directed graph?
An SCC is a maximal set of vertices where every pair of vertices is mutually reachable via directed paths.
Q27. What does the Max-Flow Min-Cut theorem state?
The Max-Flow Min-Cut theorem states that the maximum flow from source to sink equals the minimum total capacity of edges in a cut that separates source and sink.
Q28. What is the time complexity of Dijkstra's algorithm with a Fibonacci heap?
Using a Fibonacci heap, Dijkstra's algorithm achieves O(V log V + E) time, improving the decrease-key operation to amortized O(1).
Q29. What is the Floyd-Warshall algorithm?
Floyd-Warshall computes shortest paths between all pairs of vertices using dynamic programming in O(V^3) time.
Q30. What is the time complexity of Floyd-Warshall algorithm?
Floyd-Warshall uses three nested loops over V vertices, giving O(V^3) time complexity.
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.
Start Graph Algorithms Quiz