Data Structures & Algorithms

Table of Contents

Dijkstra’s algorithm

Problem

Shortest path from single source to all others (unlike Computer Networks, which was between two nodes)

Solution S = {}, Q = {all vertices} distance to every node is infinity, path to every node is nil

extract the one with shortest distance from Q (source) add it to S for each neighbour of extracted node (relax function):

Complexity initialize in ϴ(|V|) init S in constant time init Q: build priority queue using insert while loop:

for loop executed in total |E| times with inside update key of v

depends on how priority queue is implemented: