GATE Computer ScienceModerateGATE CS (PYQ pattern)

A graph has V = 1000 vertices and E = 250000 edges. Two Dijkstra implementations are compared by counting basic steps (ignoring constants): one scans an array for the minimum, the other uses a binary heap. Which is better here?

  1. A. The heap version, since E log V is always below V² for any graph
  2. B. The heap version: its cost is V log V + E ≈ 2.5 × 10⁵ steps
  3. C. The array version: V² = 10⁶ is below E·log₂V ≈ 2.5 × 10⁶
  4. D. Both are equal, since E is Θ(V²) and constants cancel

Correct answer: C. The array version: V² = 10⁶ is below E·log₂V ≈ 2.5 × 10⁶

The array version costs Θ(V²) = 10⁶; the binary heap costs Θ((V + E) log V) ≈ 2.5 × 10⁶. For dense graphs the array version wins, while for sparse graphs the heap wins. Only a Fibonacci heap gives V log V + E.

More Algorithms questions

Exams that ask this topic