Install our extension to search inside any video instantly.

COMP2521 26T2 Week 7 Lecture 2

Added:
105 views2likes1:48:16COMP2521UNSWOriginal Release: 2026-07-16

Dijkstra's algorithm is a single-source shortest path algorithm for weighted graphs with non-negative weights. It maintains three data structures: a distance array (initialized to infinity except the source at 0), a predecessor array (initialized to -1), and a set of unprocessed vertices. The algorithm repeatedly selects the unprocessed vertex with the minimum distance, applies edge relaxation to its neighbors (updating distances if a shorter path is found), and marks it as processed. The time complexity is O(E + V log V) when using a priority queue, or O(V² + E) with a simple array. The algorithm can be applied to both directed and undirected graphs, but requires non-negative edge weights to function correctly.