Data Structures & AlgorithmsVery hardGATE CS · Advanced

A weighted undirected graph on A–H has the edges (weights): A–D (16), A–E (22), A–F (26), A–G (5), A–H (4), B–C (9), B–H (23), C–D (13), C–H (25), D–E (3), D–F (7), D–G (19), D–H (15), F–H (20). All weights are distinct. Let P be the weight of the 4th edge added by Prim's algorithm started at A, and K the weight of the 4th edge accepted by Kruskal's algorithm (edges examined in increasing order of weight). What is P - K?

  1. A. 4
  2. B. 3
  3. C. -2
  4. D. -4

Correct answer: D. -4

Prim's order of additions (4,5,15,3,7,13,9) depends on the growing tree, while Kruskal's accepted edges (3,4,5,7,9,13,15) follow the global sorted order; the 4th are 3 and 7.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic