GATE Computer ScienceHardGATE CS (PYQ pattern)

Dijkstra's algorithm with a binary min-heap (lazy insertion is not used: a decrease-key is performed whenever an edge improves the label of a vertex that is already in the heap) is run from A on an undirected graph with edges AB 4, AC 8, BC 2, BD 5, CD 9, CE 10, DE 3, DF 11, EF 4, EG 7, FG 5, BG 20. How many decrease-key operations are performed in total?

  1. A. 3
  2. B. 5
  3. C. 6
  4. D. 4

Correct answer: D. 4

Order of extraction: A(0), B(4), C(6), D(9), E(12), F(16), G(19). Decrease-keys of labels already in the heap occur for C (8 → 6), E (16 → 12), F (20 → 16) and G (24 → 19): four in all, counted by simulating the algorithm. The labels of D (9) and the later extractions need no decrease.

More Algorithms questions

Exams that ask this topic