Time Complexity · #21 · 2026-04-25
What's the Big-O?
Python ·Difficulty 3/3
How to play
Read the code and pick its time complexity from four Big-O choices. Think about loops, recursion, and hidden costs. Press 1–4 or click to answer.
Graph with V vertices and E edges. What is the time complexity?
import heapq
def dijkstra(graph, start):
dist = {start: 0}
pq = [(0, start)]
while pq:
d, u = heapq.heappop(pq)
if d > dist.get(u, float('inf')):
continue
for v, w in graph[u]:
nd = d + w
if nd < dist.get(v, float('inf')):
dist[v] = nd
heapq.heappush(pq, (nd, v))
return dist
Loading your progress...
Press 1 through 4, or tap a numbered choice, to answer. Back to hub