Single-Source Shortest Path (SSSP): Applying Dijkstra to the Given Graph

Single-Source Shortest Path (SSSP): Applying Dijkstra to the Given Graph

Verified Sources
Sep 12, 2026

Dijkstra’s Algorithm (SSSP) - Relaxation + Priority Queue

Single-source shortest path SSSP focuses on computing minimum path costs from a given source ss to every vertex in a weighted graph. The standard approach when all edge weights are nonnegative is Dijkstra’s algorithm, which repeatedly applies relaxation to edges from the currently best-known frontier until no further improvements are possible.

Key idea (relaxation)

For an edge (u,v)(u,v) with weight w(u,v)w(u,v), relaxation updates:

dist[v]min(dist[v], dist[u]+w(u,v)).\text{dist}[v] \leftarrow \min(\text{dist}[v],\ \text{dist}[u] + w(u,v)).

When to use which algorithm

  • If all weights are nonnegative: use Dijkstra’s algorithm.
  • If there may be negative weights: use Bellman–Ford.

⚠️ Note on your prompt: the graph is provided as an image link. In this chat environment I can’t open or read the image content, so I cannot reliably extract the exact vertices, edges, weights, or the required source node. To still help you “apply SSSP,” I provide a complete, fill-in-by-graph workflow (tables, relaxation order, and how to compute final distances/paths) that you can apply directly once you list the edges and weights.

Pro Tip: Turn the image into an edge list first

Write the graph as an edge list like (u, v, w) for each directed edge (or ensure undirected edges appear in both directions). Then run the same Dijkstra workflow below and you’ll get the exact shortest distances and parent pointers.

Dijkstra only works for nonnegative weights

If any edge weight is negative, you must switch to Bellman–Ford; otherwise Dijkstra’s greedy choice can fail.

How to Apply SSSP (Dijkstra) to Your Graph

Extract edges + weights

1) Parse graph

From the image, write each edge as (u→v, w). Decide whether edges are directed."

Set start vertex s

2) Choose source

Identify the required source in the question; set dist[s]=0."

Set up dist and parent

3) Initialize

dist[]=∞ except dist[s]=0; parent[]=NIL."

Pop min dist + relax outgoing edges

4) Relax systematically

Use a priority queue (or a manual min-table for small graphs)."

Final distances + shortest paths

5) Produce output

dist[] gives shortest costs; parent[] reconstructs paths."

Algorithm: Dijkstra for SSSP (Nonnegative weights)

This algorithm maintains:

  • dist: current best distances from ss
  • parent: used to reconstruct the shortest path tree
  • A set of processed vertices, often via a priority queue

Dijkstra pseudocode (conceptual)

  1. Initialize all dist[x]=\text{dist}[x]=\infty; set dist[s]=0\text{dist}[s]=0.
  2. While there are unprocessed vertices:
    • Pick uu with minimum dist[u]\text{dist}[u].
    • For each outgoing neighbor vv of uu, relax edge (u,v)(u,v).
  3. After termination, dist[v]\text{dist}[v] is the shortest distance from ss to vv.

Complexity (why priority queue matters)

With a binary heap priority queue, typical complexity is:

O((V+E)logV),O\big((V+E)\log V\big),

where VV is the number of vertices and EE the number of edges.

Step-by-step: Apply Dijkstra to your (image) graph

  1. 1
    Step 1

    List every edge (u→v) with its weight w. If the graph is undirected, include both (u→v,w) and (v→u,w).

  2. 2
    Step 2

    Let s be the given starting vertex. Set dist[s]=0 and dist[others]=∞.

  3. 3
    Step 3

    Set parent[*]=NIL. When relaxation improves dist[v], store parent[v]=u.

  4. 4
    Step 4

    Maintain a table/notes of dist values and parent updates per extraction of u.

  5. 5
    Step 5

    Repeatedly pick the unprocessed vertex u with smallest dist[u]. Mark u as processed.

  6. 6
    Step 6

    For each edge (u→v,w): compute candidate = dist[u] + w. If candidate < dist[v], set dist[v]=candidate and parent[v]=u.

  7. 7
    Step 7

    At the end, dist[*] are final shortest distances from s.

  8. 8
    Step 8

    To recover the shortest path s→t, follow parent pointers backwards from t until reaching s, then reverse the sequence.

Working template (fill this for your exact graph)

Use this structure to compute shortest paths. Replace vertices/edges with those from the image.

Distance initialization template

Assume vertices V={v1,,vn}V=\{v_1,\dots,v_n\} and source s=v1s=v_1.

Vertexdist (start)parent (start)
ss0NIL
Others\inftyNIL

Iteration log template

At each iteration k, you:

  1. extract uku_k with minimum dist
  2. relax each outgoing edge from uku_k
Iteration kExtract udist[u]Relax edge (u→v,w)candidate dist[v]Updated?parent[v]
1u₁(u₁→v, w)dist[u₁]+wYes/No
2u₂

Final output format

When finished, you should report:

  • shortest distance from ss to every vertex tt
  • the actual path using parent pointers

Example reporting format (template):

  • d(s,a)=d(s,a)=\dots with path sas \to \dots \to a
  • d(s,b)=d(s,b)=\dots with path sbs \to \dots \to b

Graph concept map (what happens internally)

Common pitfalls and checks

Final distances from source (fill with your results)

After running Dijkstra, dist[t] for each vertex t becomes the data.

SSSP Quick Self-Check

1 / 4
Question · Term

What is relaxation?

Click to reveal
Answer · Definition

Attempt to improve dist[v] using an edge (u→v): if dist[u]+w(u,v) < dist[v], update dist[v] and parent[v]=u.

Knowledge Check

Question 1 of 4
Q1Single choice

Dijkstra’s algorithm is guaranteed to produce correct shortest paths when the graph has which property?