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?
- A. The heap version, since E log V is always below V² for any graph
- B. The heap version: its cost is V log V + E ≈ 2.5 × 10⁵ steps
- C. The array version: V² = 10⁶ is below E·log₂V ≈ 2.5 × 10⁶
- 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
- What is the smallest m such that every simple undirected graph with 12 vertices and m edges is 2-connected (connected, and stays connected…
- Bellman–Ford is run from S on a directed graph with edges S→A 2, A→B 3, B→C −4, C→A 0, C→D 5, D→E 1, E→H 2, S→F 7, F→G −2, S→I 4, I→F 1…
- What is the smallest possible value of the largest edge weight on a path from E to D in the graph with edges AB 6, AC 1, AD 5, BC 5, BE 3…
- Kahn's topological sort uses a min-priority queue, so among available vertices the smallest label is always chosen. The DAG has edges 1→3…
- A DAG has edges s→a, s→b, a→b, a→c, a→d, b→c, b→d, c→d, c→e, c→f, d→e, d→f, e→f, e→t, f→t. How many s–t paths pass through exactly one of…
- How many spanning trees of the complete graph K₅ (vertices 1–5) contain neither the edge 1-2 nor the edge 1-3?