Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:44+00:00 2026-06-17T09:09:44+00:00

The way the Bellman Ford algorithm has been explained to me is that it

  • 0

The way the Bellman Ford algorithm has been explained to me is that it goes through n-1 (with n being the number of nodes) iterations, updating the distance between nodes on each iteration. All graphical examples show the nodes initialized to infinity, and the ones closest to the source node being updated on the first iteration, but the rest remaining at infinity until an iteration occurs that reaches them.

However, looking at code for the algorithm, such as that provided here, I’m finding it hard to understand why all of the nodes that are more steps away than the number of iterations are not updated with the algorithm. For instance, if I’m on my second iteration and I have a node d that is only reachable through the path a-b-c-d, the examples I’ve read seem to indicate that d will not be updated until the 4th iteration.

But the main relaxation function of the code:

def relax(node, neighbour, graph, d, p):
    # If the distance between the node and the neighbour is lower than the one I have now
    if d[neighbour] > d[node] + graph[node][neighbour]:
        # Record this lower distance
        d[neighbour]  = d[node] + graph[node][neighbour]
        p[neighbour] = node

updates based on information giving the weight and distance from the source of the predecessor node. If the algorithm iterates over each node in every iteration, what’s to stop d from being properly updated in the FIRST iteration? For instance, if the algorithm iterated over the nodes in order a-b-c-d, I don’t see why the algorithm wouldn’t store the distance information for node b, move on to node c, store distance information for that, and finally reach d with enough information to calculate the shortest path IN THE FIRST ITERATION.

I hope that made some kind of sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:09:45+00:00Added an answer on June 17, 2026 at 9:09 am

    It could happen – but it is not guaranteed. You can only guarantee that you have shortest path of length up to k at the k’th iteration, not earlier.

    The visualizations you saw are just there for explaining the concept of the algorithm, and it is much cleaner and simpler to understand using a transactional memory model.

    Think how hard it was for you to understand the algorithm using the visualization if a node of distance 10 would change in the first iteration…

    Regarding the question in comment:

    Does that mean I could effectively create a tool that tracks the
    number of changes per iteration, and once that counter reaches 0, I
    could exit the iterations early?

    Yes, if there are no changes in iteration k – iteration k+1 wont be able to change anything as well, everything is minimal, and so does for k+2 , …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while programing bellman-ford algorithm I encountered one problem, it's question more theoretical than technical
I want to do a execution time analysis of the bellman ford algorithm on
I've been having a go at writing the Bellman Ford algoritm for finding the
Whichever way I do it, it seems something goes wrong when using the conditional
Way back in the past I accidentally committed a large number of Java artifacts
Any way of using webservice for android through which we can send paramerters to
The way my game and server work is like this: I send messages that
One way to have interprocess communication is through a (named) pipe between the processes.
The way my team currently schedules jobs is through the SQL Server Job Agent.
this way i am generating threads,but after for loop how to check that all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.