<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shivam Yadav</title>
    <description>The latest articles on DEV Community by Shivam Yadav (@shivam_yadav_d021044f3153).</description>
    <link>https://dev.to/shivam_yadav_d021044f3153</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3735331%2Fae95c3b2-8d9a-40d9-9adc-c7a1e0cf2ea2.png</url>
      <title>DEV Community: Shivam Yadav</title>
      <link>https://dev.to/shivam_yadav_d021044f3153</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivam_yadav_d021044f3153"/>
    <language>en</language>
    <item>
      <title>Reconstructing the Actual Path in Shortest Path Algorithms</title>
      <dc:creator>Shivam Yadav</dc:creator>
      <pubDate>Tue, 27 Jan 2026 13:45:51 +0000</pubDate>
      <link>https://dev.to/shivam_yadav_d021044f3153/reconstructing-the-actual-path-in-shortest-path-algorithms-3kfm</link>
      <guid>https://dev.to/shivam_yadav_d021044f3153/reconstructing-the-actual-path-in-shortest-path-algorithms-3kfm</guid>
      <description>&lt;p&gt;Systems should not only compute results, but also explain how those results were obtained.&lt;/p&gt;

&lt;p&gt;Parent pointers are a minimal metadata layer that turns an algorithm into a usable system feature.&lt;/p&gt;

&lt;p&gt;Shortest path algorithms are often discussed in terms of computing the minimum distance between two nodes.&lt;br&gt;
However, in real systems, knowing the distance alone is rarely sufficient — we often need the actual path.&lt;/p&gt;

&lt;p&gt;This article explains a simple but powerful technique to reconstruct the shortest path using a parent array.&lt;/p&gt;

&lt;p&gt;The Core Idea: Storing Parent Pointers&lt;/p&gt;

&lt;p&gt;When running BFS on an unweighted graph, we relax edges level by level.&lt;br&gt;
Whenever we discover a node for the first time, we store where it came from.&lt;/p&gt;

&lt;p&gt;vector parent(V, -1);&lt;/p&gt;

&lt;p&gt;For every neighbor visited:&lt;/p&gt;

&lt;p&gt;parent[neighbor] = node;&lt;/p&gt;

&lt;p&gt;This creates an implicit shortest-path tree.&lt;/p&gt;

&lt;p&gt;Reconstructing the Path&lt;/p&gt;

&lt;p&gt;Once BFS completes, we can reconstruct the path by walking backwards from the destination node using the parent pointers.&lt;/p&gt;

&lt;p&gt;vector path;&lt;br&gt;
for (int v = destination; v != -1; v = parent[v]) {&lt;br&gt;
    path.push_back(v);&lt;br&gt;
}&lt;br&gt;
reverse(path.begin(), path.end());&lt;/p&gt;

&lt;p&gt;This converts a distance-only result into an actual navigable route.&lt;/p&gt;

&lt;p&gt;Why This Matters Beyond DSA&lt;/p&gt;

&lt;p&gt;This pattern appears in real-world systems:&lt;/p&gt;

&lt;p&gt;Navigation systems reconstruct routes&lt;/p&gt;

&lt;p&gt;Workflow engines trace execution paths&lt;/p&gt;

&lt;p&gt;Debugging tools track state transitions&lt;/p&gt;

&lt;p&gt;Distributed systems explain decisions&lt;/p&gt;

&lt;p&gt;Optimization without traceability is incomplete.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>designpatterns</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
