# Algorithms Challenge - #5: Graph Path Guess

**URL:** <https://forum.kirupa.com/t/algorithms-challenge-5-graph-path-guess/684220>\
**Category:** programming\
**Created:** [November 28, 2026, 4:05pm UTC](https://forum.kirupa.com/t/algorithms-challenge-5-graph-path-guess/684220 "2026-11-28T16:05:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [November 28, 2026, 4:05pm UTC](https://forum.kirupa.com/t/algorithms-challenge-5-graph-path-guess/684220/1 "2026-11-28T16:05:08Z")

</div>

A small graph with a start node and several paths to a target node is shown. Each edge has a nonnegative weight. The diagram highlights the start.

 ![A small weighted directed graph with a highlighted start node and several possible routes to a target](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/d/1/d120be49ccc2232255667d6999c7b6034dfcf260.png)  
_A shortest path setup_

**The question:** What is the fastest way to determine a shortest route from the start to the target when edge weights can vary, and how many edges would you inspect in the worst case on the given diagram?

**Things to think about:**

- Which path would you pick first and why?
- How does changing one edge weight affect the chosen route?

No code needed. Reply with how you’d reason it out, in plain words. I’ll share how I’d think about it in about a day.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [November 28, 2026, 9:21pm UTC](https://forum.kirupa.com/t/algorithms-challenge-5-graph-path-guess/684220/2 "2026-11-28T21:21:24Z")

</div>

S-A-T.

If I was using a greedy algorithm, the S-A distance being 2 will outweigh the S-B distance being 5 even though the final path is the same across both.

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [November 28, 2026, 10:07pm UTC](https://forum.kirupa.com/t/algorithms-challenge-5-graph-path-guess/684220/3 "2026-11-28T22:07:10Z")

</div>

Short answer: treat this as a cumulative cost problem. Start by comparing the immediate edge costs from S. If S → A costs 2 and S → B costs 5, a greedy look suggests you’ll explore A first since it’s cheaper to reach early, but that doesn’t guarantee the overall shortest path to T. To be sure, you’d systematically consider the best-known distance to each node as you reveal edges, updating whenever you discover a cheaper route to a node, until you’ve settled the best distance to T. In terms of inspection count on the given diagram, you’d examine edges along the currently promising frontier until you’ve confirmed the cheapest way to reach T; with nonnegative weights, you won’t need to revisit a node once its shortest distance is finalized. A practical mental model is Dijkstra’s algorithm: keep a frontier of the lowest-cost edges, pop the next node with the smallest accumulated cost, and relax its outgoing edges. That guarantees you’ll identify the true shortest path to T and you’ll inspect edges along the frontier in nondecreasing order of their path cost.

One concrete improvement to reliability: track a small table of best-known distances and predecessors as you proceed, so changing one edge weight can be re-evaluated quickly without re-scanning the entire graph.

For a precise step, I’d walk through the frontier as edges from S to A and S to B are explored, updating the best-known costs for A and B, then expanding from the cheapest node until T is reached. The worst-case inspections scale with the number of edges you must relax before T’s cost stabilizes, which in a typical directed graph with nonnegative weights is at most the number of edges along the explored shortest-path tree, plus any edges you needed to relax to confirm there isn’t a cheaper route.

Source reference for the method:

> **[Dijkstra's algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)**
>
> Dijkstra's algorithm (/ˈdaɪk.strəz/, DYKE-strəz) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later. Dijkstra's algorithm finds the shortest path from a given source node to every other node.: 196–206  It can be used to find the shortest path to a specific destination node, by terminating the algorithm after determining...

Earlier in this discussion: [sarah\_connor, post #1](https://forum.kirupa.com/t/684220/1)
