← 返回首页
added changes to your bellmanford.js by Ujwal200707 · Pull Request #1861 · TheAlgorithms/JavaScript · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

added changes to your bellmanford.js#1861

Open
Ujwal200707 wants to merge 1 commit into
TheAlgorithms:masterfrom
Ujwal200707:master
Open

added changes to your bellmanford.js#1861
Ujwal200707 wants to merge 1 commit into
TheAlgorithms:masterfrom
Ujwal200707:master

Conversation

Copy link
Copy Markdown

The change replaces the final loop with a direct return statement.
Previously, the code looped through all vertices to find the destination and then returned its distance. This loop was unnecessary because the destination index is already known.
By using:

return dis[dest]

the code becomes more efficient and readable.
It removes redundant iterations, reduces time complexity for that part from O(V) to O(1), and makes the function cleaner without affecting the output.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Footer

© 2026 GitHub, Inc.