Aptitude

Graphs Interview Questions

In a coding MCQ: which algorithm finds shortest paths in an unweighted graph? — spoken sample answer for Indian interviews.

  • 5Questions with answers
  • 3Difficulty levels

Questions (5)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Beginner
Question

In a coding MCQ: which algorithm finds shortest paths in an unweighted graph?

Answer:

On an unweighted graph, BFS from the source gives shortest path by number of edges. Dijkstra is for non-negative weights. Bellman-Ford handles negative weights. DFS does not guarantee shortest paths. Prim is for MSTs, not shortest paths. I would mark BFS.

Question 2
Interview Intermediate
Question

Dijkstra versus BFS for shortest path?

Answer:

BFS if unweighted. Dijkstra if non-negative weights. Negative needs Bellman-Ford. I would not Dijkstra an unweighted grid.

Question 3
Interview Beginner
Question

Adjacency list versus matrix for a sparse graph?

Answer:

List O(V+E) , matrix O(V^2) . Sparse social graphs want lists. Matrix is O(1) edge check. I would not matrix a million-node graph.

Question 4
Interview Intermediate
Question

Cycle in a directed graph?

Answer:

DFS with a visiting/grey state, or Kahn failing to process n nodes. Undirected parent-skip DFS is the trap option on a directed MCQ.

Question 5
Interview Beginner
Question

Topological sort exists only if?

Answer:

The graph is a DAG. A cycle means no topo order. I check Kahn count versus n. I would not topo an undirected graph without orienting edges.

Practice with AI mock interviews

Run Aptitude mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required