Computer Networks · TEE · papers

Q3(a) · Dijkstra from u

2023-01-27 · AI-only Sem V

Exact historical variant. Current-syllabus questions solved; excluded topics and source limitations stated.

Q3(a). Using Dijkstra’s algorithm calculate shortest paths from u to all nodes, showing every step. The original undirected graph’s edges are reproduced below. [10 marks]

Original diagram data

Edge endpoint1Endpoint2Cost
uv4
uw3
ux5
vw1
vx8
xw7
xy7
wy6
wz7
yz7

Answer

Given

The original diagram is undirected. All edge labels are reproduced below. Source = u.

Swipe across the diagram to read its labels ↔
Original undirected question graph: every edge weight retained; source u
Diagram: Original undirected question graph: every edge weight retained; source u. Labels: Original undirected question graph: every edge weight retained; source u | 4 | 3 | 5 | 1 | 8 | 7 | 7 | 6 | 7 | 7 | u | v | x | w | y | z
FromToCost
uv4
uw3
ux5
vw1
vx8
xw7
xy7
wy6
wz7
yz7

To find

Shortest distance, complete route and predecessor for every node from u.

Formula and why

d(v)\leftarrow\min(d(v),d(u)+w(u,v))LaTeX: d(v)\leftarrow\min(d(v),d(u)+w(u,v))

Relaxation replaces a tentative route when going through u is cheaper. Dijkstra settles the unvisited node of least tentative distance. Nonnegative edge costs make the settled distance final. Equal-distance nodes may be settled in either order.

Step 1. Initialize and relax

Pass / settled nodeStrict improvementsuvwxyz
0Initial0∞∞∞∞∞
uv←u: 0+4=4; w←u: 0+3=3; x←u: 0+5=50435∞∞
wy←w: 3+6=9; z←w: 3+7=100435910
vNo change0435910
xNo change0435910
yNo change0435910
zNo change0435910

Step 2. Read predecessors backwards, then reverse

DestinationDistancePreviousRoute
u0—u
v4uu → v
w3uu → w
x5uu → x
y9wu → w → y
z10wu → w → z

A tie between two equally short paths is valid; this table retains the first predecessor on equal distances.