Discrete Math Quiz: Shortest Path Algorithms
14 questions · exam conditions
0:00
Shortest Path AlgorithmsQuestion 1 of 14

In a BFS traversal of an unweighted graph, you observe that vertices PP and QQ are discovered at the same level (distance kk from the source). Later in the traversal, when processing vertex PP, you discover a new vertex RR through edge (P,R)(P,R). At what distance will RR be labeled?

Distance kk since RR is adjacent to a vertex at level kk
Distance k+1k+1 following the BFS level-by-level exploration property
Distance k+2k+2 since RR is two steps away from level k1k-1
Distance k1k-1 since RR provides a shorter path back toward the source
← Back to quizzes

Discrete Math Quiz

Discrete Math Quiz: Shortest Path Algorithms

Practice Shortest Path Algorithms in Discrete Math with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.

What this quiz covers

This quiz focuses on Shortest Path Algorithms, giving you a quick way to practice the rules, question types, and explanations that matter most for Discrete Math.

How to use this quiz

Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.

All questions

Question 1

In a BFS traversal of an unweighted graph, you observe that vertices PP and QQ are discovered at the same level (distance kk from the source). Later in the traversal, when processing vertex PP, you discover a new vertex RR through edge (P,R)(P,R). At what distance will RR be labeled?

  1. Distance kk since RR is adjacent to a vertex at level kk
  2. Distance k+1k+1 following the BFS level-by-level exploration property (correct answer)
  3. Distance k+2k+2 since RR is two steps away from level k1k-1
  4. Distance k1k-1 since RR provides a shorter path back toward the source
Explanation: In BFS, when a vertex at distance k discovers a new vertex through an edge, the new vertex is assigned distance k+1. This maintains the level-by-level exploration property where all vertices at distance d are processed before any vertex at distance d+1. Since P is at distance k and discovers R, then R gets distance k+1. A is wrong because adjacent vertices differ by exactly 1 in distance. C is wrong because it adds an extra level. D is wrong because BFS assigns increasing distances as it moves away from the source.

Question 2

In a weighted graph with positive edge weights, you run Dijkstra's algorithm starting from vertex ss. After the algorithm terminates, you discover that vertex vv has distance d(v)=15d(v) = 15. Later, you add a new edge (u,v)(u,v) with weight 33 to the graph, where uu had distance d(u)=10d(u) = 10 in the original run. What can you conclude about the shortest path distance from ss to vv in the new graph?

  1. The new shortest path distance is exactly 1313
  2. The new shortest path distance is at most 1313 (correct answer)
  3. The new shortest path distance remains 1515
  4. The new shortest path distance could be 1212 or 1313
Explanation: Adding edge (u,v) with weight 3 creates a potential path from s to v with total distance d(u) + 3 = 10 + 3 = 13. Since shortest paths can only decrease or stay the same when edges are added, the new distance is min(15, 13) = 13 at most. However, there might be an even shorter path through other vertices that we haven't considered. A is wrong because we can't guarantee it's exactly 13. C is wrong because the path s→u→v gives distance 13 < 15. D is wrong because we have no information suggesting a path of length 12.

Question 3

Consider a graph where BFS is performed starting from vertex ss. The algorithm discovers vertices in this order: s,a,b,c,d,es, a, b, c, d, e. You know that aa and bb are both at distance 11 from ss, and c,d,ec, d, e are all at distance 22. Which statement about the graph structure must be true?

  1. Vertices aa and bb must be adjacent since they're at the same level
  2. Vertex cc must be adjacent to aa since cc was discovered before dd and ee
  3. Each of c,d,ec, d, e is adjacent to at least one vertex in {s,a,b}\{s, a, b\} (correct answer)
  4. Vertices dd and ee cannot be adjacent to ss since they're at distance 22
Explanation: In BFS, vertices at distance k are discovered by exploring edges from vertices at distance k-1. Since c, d, e are at distance 2, each must be reachable from some vertex at distance 1 or 0. The vertices at distance ≤ 1 are {s, a, b}, so each of c, d, e must be adjacent to at least one of these. A is wrong because vertices at the same level need not be adjacent. B is wrong because the discovery order among vertices at the same level depends on which vertex processed them, not direct adjacency. D is correct that d and e are not adjacent to s (since they're at distance 2), but this doesn't contradict C.

Question 4

During BFS execution on a graph, the queue at some moment contains vertices [S,T,U][S, T, U] in that order, where SS is at the front. When you dequeue and process SS, you discover that SS has edges to vertices VV (undiscovered) and WW (undiscovered). What will be the state of the queue immediately after processing SS?

  1. [T,U,V,W][T, U, V, W] with new vertices added to the rear (correct answer)
  2. [V,W,T,U][V, W, T, U] with new vertices processed first due to recency
  3. [T,U][T, U] since VV and WW are processed immediately upon discovery
  4. [T,V,U,W][T, V, U, W] with new vertices interleaved by discovery order
Explanation: BFS uses a FIFO queue where vertices are added to the rear when discovered and removed from the front when processed. After dequeuing S, the queue has [T, U]. When S is processed and discovers V and W, these are added to the rear in the order they're discovered, resulting in [T, U, V, W]. B is wrong because BFS is not a stack (LIFO). C is wrong because discovered vertices are queued for later processing, not processed immediately. D is wrong because new vertices are added to the rear, not interleaved.

Question 5

In a weighted graph, you run Dijkstra's algorithm and find that the shortest path from source ss to target tt has length 2525 and passes through vertices suvts \to u \to v \to t. If you increase the weight of edge (u,v)(u,v) by 55, what can you determine about the new shortest path distance from ss to tt?

  1. The new distance is exactly 3030 since the same path is used with increased weight
  2. The new distance is at most 3030 since alternative paths might become optimal
  3. The new distance is at least 2525 since shortest paths cannot decrease when weights increase (correct answer)
  4. The new distance could be less than 2525 if the algorithm finds a better routing
Explanation: When edge weights increase, shortest path distances can only stay the same or increase - they cannot decrease. The original shortest path distance was 25. After increasing edge (u,v) by 5, the path s→u→v→t now has length 30. However, there might be alternative paths from s to t that don't use edge (u,v), and these paths maintain their original lengths. The new shortest path will be the minimum among all possible paths, which is at least 25 (the original distance). A is wrong because alternative paths might be shorter than 30. B gives an upper bound but the question asks what we can determine definitively. D is impossible since increasing weights cannot improve shortest paths.

Question 6

You are implementing Dijkstra's algorithm and need to choose between different priority queue implementations. Your graph has VV vertices and EE edges. You perform VV extract-min operations and up to EE decrease-key operations. If you use a binary heap, what is the total time complexity of the priority queue operations?

  1. O(VlogV+E)O(V \log V + E) for extract-min and decrease-key operations combined
  2. O(VlogV+ElogV)O(V \log V + E \log V) for extract-min and decrease-key operations combined (correct answer)
  3. O(ElogV)O(E \log V) since decrease-key operations dominate the runtime
  4. O(V2)O(V^2) for extract-min operations and O(E)O(E) for decrease-key operations
Explanation: In a binary heap, extract-min takes O(log V) time and there are V such operations, giving O(V log V). Decrease-key also takes O(log V) time and there are up to E such operations, giving O(E log V). Total time is O(V log V + E log V). A is wrong because decrease-key is not O(1) in binary heaps. C misses the extract-min contribution. D is wrong about both complexities - extract-min is O(log V) per operation, not O(V), and decrease-key is O(log V), not O(1).

Question 7

In Dijkstra's algorithm, you maintain a priority queue of vertices with their tentative distances. At some point during execution, the queue contains vertices {B:7,C:12,D:9,E:15}\{B:7, C:12, D:9, E:15\} where the number after each vertex is its current tentative distance. When you extract the minimum and process vertex BB, you find it has edges to CC (weight 22) and DD (weight 55). What will be the state of the priority queue after processing BB?

  1. {C:9,D:9,E:15}\{C:9, D:9, E:15\} with a tie between CC and DD (correct answer)
  2. {D:9,C:12,E:15}\{D:9, C:12, E:15\} with DD having minimum priority
  3. {C:9,D:12,E:15}\{C:9, D:12, E:15\} with CC having minimum priority
  4. {C:12,D:9,E:15}\{C:12, D:9, E:15\} since edge weights don't update distances
Explanation: When processing B (distance 7), we examine its edges. For edge (B,C) with weight 2: new distance = 7+2 = 9 < 12, so C's distance updates to 9. For edge (B,D) with weight 5: new distance = 7+5 = 12 > 9, so D's distance stays 9. The queue becomes {C:9, D:9, E:15} with C and D tied for minimum. B is wrong because D was already at distance 9. C is wrong because D's distance doesn't change from 9. D is wrong because C's distance does improve from the new path through B.

Question 8

Consider a weighted graph where Dijkstra's algorithm is running. At some iteration, vertex ww is about to be processed (extracted from priority queue with distance dd). You notice that ww has an incoming edge from vertex zz with weight cc, where zz was processed earlier with distance dzd_z. What constraint must hold for the algorithm's correctness?

  1. ddz+cd \leq d_z + c to ensure the shortest path property is maintained (correct answer)
  2. d=dz+cd = d_z + c to ensure ww was discovered through zz
  3. ddz+cd \geq d_z + c due to the greedy choice property of Dijkstra's algorithm
  4. d<dz+cd < d_z + c since ww must have been reached via a better path
Explanation: For Dijkstra's correctness, when a vertex w is processed with distance d, this must be the shortest path distance. Since z was processed earlier with distance d_z, and there's an edge (z,w) with weight c, one possible path to w has length d_z + c. The actual shortest path to w (which is d) cannot be longer than any path, so d ≤ d_z + c. B is wrong because w might have been discovered through a different vertex. C is wrong because d could be less than d_z + c if a shorter path exists. D is wrong because the inequality direction is incorrect.

Question 9

Consider running BFS on a graph starting from vertex AA. At some point during execution, the queue contains vertices [P,Q,R][P, Q, R] where PP is at the front. You know that PP and QQ are both at distance 33 from AA, while RR is at distance 44. What can you conclude about the next vertex to be processed after PP?

  1. The next vertex processed depends on the adjacency list ordering of PP
  2. The next vertex processed must be RR since BFS processes by distance
  3. The next vertex could be QQ or any vertex that PP discovers and enqueues
  4. The next vertex processed must be QQ since it's next in the queue (correct answer)
Explanation: When analyzing BFS execution, focus on how the queue operates and what "processing" means. BFS uses a first-in-first-out queue where vertices are added to the back and removed from the front for processing. The correct answer is D because BFS strictly follows queue order. When the queue contains [P,Q,R][P, Q, R] with PP at the front, processing PP means removing it from the queue, leaving [Q,R][Q, R]. The next vertex to be processed is always the new front of the queue, which is QQ. This is fundamental to how BFS works - it's a queue-driven algorithm. Option A is incorrect because adjacency list ordering affects which vertices PP discovers and enqueues, but doesn't change that QQ is next to be processed. Option B misunderstands BFS behavior - while BFS does explore by distance layers, it doesn't skip vertices in the queue to process higher-distance vertices first. RR at distance 4 will eventually be processed, but only after all distance-3 vertices currently in the queue. Option C confuses "processing" with "enqueuing." Any vertices that PP discovers will be added to the back of the queue (after RR), but the next vertex to be processed is still QQ. Remember that BFS has two distinct phases: processing a vertex (removing it from the queue front) and discovering new vertices (adding them to the queue back). Always distinguish between these operations when analyzing BFS execution order.

Question 10

In a BFS tree rooted at vertex rr, you observe that vertex xx is at level 44 and vertex yy is at level 66. The original graph contains edges (x,y)(x,y) and (y,x)(y,x) (since the graph is undirected). During the BFS traversal, when are these edges examined?

  1. Edge (x,y)(x,y) is examined when xx is processed, and (y,x)(y,x) is examined when yy is processed
  2. Both (x,y)(x,y) and (y,x)(y,x) refer to the same undirected edge, examined once when xx is processed
  3. Both (x,y)(x,y) and (y,x)(y,x) refer to the same undirected edge, examined once when yy is processed
  4. The edge is examined twice: once when xx is processed and once when yy is processed (correct answer)
Explanation: In BFS on an undirected graph, each undirected edge {x,y} is represented in the adjacency structure as two directed edges: (x,y) in x's adjacency list and (y,x) in y's adjacency list. When BFS processes vertex x (level 4), it examines edge (x,y) and finds y already discovered at level 6. Later, when BFS processes vertex y (level 6), it examines edge (y,x) and finds x already processed. So the same undirected edge is examined from both endpoints. A and D are correct about examining twice, but A incorrectly treats them as different edges. B and C are wrong because the edge is examined from both vertices.

Question 11

A modified version of Dijkstra's algorithm is run on a graph where instead of selecting the vertex with minimum distance, we select the vertex with maximum distance among all unprocessed vertices with finite distance. If the graph has edge weights 1, 2, 3, 5, 8 and we start from vertex SS, what property does this modified algorithm guarantee about the paths it finds?

  1. It finds the shortest paths from SS to all vertices
  2. It finds the longest simple paths from SS to all vertices
  3. It finds some path from SS to each vertex, but with no optimality guarantee (correct answer)
  4. It finds paths that maximize the minimum edge weight along the path
Explanation: The modified algorithm breaks the fundamental property of Dijkstra's algorithm. In standard Dijkstra's, we select the minimum distance vertex because once a vertex is processed, we're guaranteed to have found its shortest path (no unprocessed vertex can provide a shorter route). By selecting the maximum distance vertex, we lose this guarantee. The algorithm will still find paths to all reachable vertices, but these paths are not guaranteed to be optimal in any meaningful sense. Choice A is wrong because shortest path optimality is lost. Choice B is wrong because longest simple path is NP-hard and this greedy approach won't solve it. Choice D describes a different optimization criterion not achieved by this modification.

Question 12

Consider two implementations of shortest path algorithms on the same weighted graph: Algorithm X processes vertices in order of increasing distance (like Dijkstra), while Algorithm Y processes vertices in decreasing order of their degree (number of neighbors). Both algorithms start from the same source vertex ss. Under what conditions will both algorithms produce the same shortest path tree?

  1. When all edge weights are equal to 1
  2. When the graph is a tree (no cycles) (correct answer)
  3. When vertices with higher degree are closer to the source vertex
  4. When the graph has a unique shortest path from ss to every vertex
Explanation: In a tree, there is exactly one path between any pair of vertices, so this unique path is automatically the shortest path. Since there are no cycles, the order in which vertices are processed doesn't affect the final shortest path tree - there's only one possible tree connecting all vertices. Algorithm X (Dijkstra-like) will find shortest paths, and Algorithm Y will also find the same paths because there are no alternative routes to consider. Choice A is wrong because even with unit weights, the processing order matters in graphs with cycles. Choice C is not sufficient because degree-distance correlation doesn't guarantee same results. Choice D is wrong because having unique shortest paths doesn't mean different processing orders will discover them in the same tree structure.

Question 13

A social network is modeled as an unweighted graph where each vertex represents a person and each edge represents a friendship. The network has the property that any two people are connected by at most 4 intermediate friends (i.e., the diameter is at most 6). A rumor spreading algorithm uses BFS to model how information spreads, where each person tells the rumor to all their friends simultaneously in discrete time steps.

If person AA starts a rumor at time 0, and the rumor reaches person BB at time 3, what can we conclude about adding a friendship edge between AA and person CC, who currently receives the rumor at time 5?

  1. Adding edge (A,C)(A,C) would guarantee that CC receives the rumor at time 1 (correct answer)
  2. Adding edge (A,C)(A,C) could reduce CC's rumor time to at most time 2
  3. Adding edge (A,C)(A,C) would not change when CC receives the rumor
  4. Adding edge (A,C)(A,C) might increase the time when BB receives the rumor
Explanation: In the BFS rumor model, the time when a person receives the rumor equals their shortest path distance from the source. Person B receives the rumor at time 3, meaning the shortest path from A to B has length 3. Person C receives the rumor at time 5, meaning the shortest path from A to C has length 5. If we add a direct edge (A,C), then C would be directly connected to A, creating a path of length 1 from A to C. Since BFS finds shortest paths and this new edge creates a shorter path than any existing path, C would receive the rumor at time 1. Choice B is wrong because the time would be exactly 1, not 'at most 2'. Choice C is wrong because the new edge definitely creates a shorter path. Choice D is wrong because adding edges cannot increase shortest path distances.

Question 14

Consider running Dijkstra's algorithm on a graph where all edge weights are positive integers. At some point during execution, vertex uu has tentative distance 10 and vertex vv has tentative distance 15. If there's an edge (u,v)(u,v) with weight 3, under what condition would this edge NOT cause an update to vv's distance when uu is processed?

  1. When vv has already been processed by the algorithm (correct answer)
  2. When there's a shorter path to vv that doesn't go through uu
  3. When the edge (u,v)(u,v) would create a negative cycle
  4. When vv is not adjacent to any unprocessed vertices
Explanation: In Dijkstra's algorithm, when vertex u is processed, we examine all edges (u,v) and potentially update d(v) = min(d(v), d(u) + weight(u,v)). Here, d(u) + weight(u,v) = 10 + 3 = 13 < 15 = d(v), so normally v's distance would be updated to 13. The only reason this update wouldn't occur is if v has already been processed (finalized) by the algorithm. Once a vertex is processed in Dijkstra's algorithm, its distance is final and never updated again. Choice B is incorrect because even if shorter paths exist, the relaxation step would still be performed. Choice C is irrelevant since all weights are positive. Choice D is unrelated to the relaxation process.