約 5,150 件の結果
リンクを新しいタブで開く
  1. The Bellman-Ford algorithm is a single-source shortest path algorithm that works on weighted graphs, including those with negative edge weights. Unlike Dijkstra’s algorithm, it can detect negative weight cycles and report them.

    It works on the principle of relaxation, where distances are iteratively updated until the shortest paths are found or a negative cycle is detected.

    Pseudocode:

    def bellman_ford(vertices, edges, source):
    # Step 1: Initialize distances
    dist = [float("inf")] * vertices
    prev = [None] * vertices
    dist[source] = 0

    # Step 2: Relax edges |V| - 1 times
    for _ in range(vertices - 1):
    for u, v, w in edges:
    if dist[u] != float("inf") and dist[u] + w < dist[v]:
    dist[v] = dist[u] + w
    prev[v] = u

    # Step 3: Check for negative weight cycles
    for u, v, w in edges:
    if dist[u] != float("inf") and dist[u] + w < dist[v]:
    print("Graph contains a negative weight cycle")
    return None, None

    return dist, prev
    コピーしました。

    How it works:

    フィードバック
    ありがとうございました!詳細をお聞かせください
  2. Bellman-Ford Algorithm: Examples, Time Complexity

    2025年12月15日 · Explore the Bellman-Ford Algorithm, its working, pseudocode, complexity, C/C++/Java/Python implementation, Dijkstra comparison, and …

  3. DSA Bellman-Ford Algorithm - W3Schools

    Learn how to use the Bellman-Ford algorithm to find the shortest paths in a directed graph with negative edge weights. See the algorithm steps, a manual run …

  4. Bellman–Ford algorithm - Wikipedia

    When the algorithm is used to find shortest paths, the existence of negative cycles is a problem, preventing the algorithm from finding a correct answer. However, since it terminates upon finding a negative cycle, the Bellman–Ford algorithm can be used for applications in which this is the target to be sought – for example in cycle-cancelling techniques in network flow analysis.

    Wikipedia · CC-BY-SA ライセンス について表示されるテキスト
  5. Bellman-Ford algorithm - Explained with an example!

    2024年8月4日 · The Bellman-Ford algorithm is one of the first algorithms to find the shortest path between a source and all other vertices in a digraph without …

  6. Bellman Ford's Algorithm - Programiz

    Learn how to use Bellman Ford's algorithm to find the shortest path in graphs with negative weights. See pseudocode, examples and applications in Python, Java …

  7. Bellman-Ford Algorithm: Example, Time Complexity, Code

    2024年9月21日 · Learn the Bellman-Ford Algorithm with an example, time complexity analysis, and code implementation for efficient shortest path finding in this tutorial.

  8. Bellman Ford Algorithm (With Visualization and Code …

    2025年7月21日 · Learn how to implement the Bellman Ford algorithm in Python, C++, and Java with complete code examples and handle negative edge weights …

  9. Bellman Ford Shortest Path Algorithm - Baeldung

    2024年3月18日 · In this tutorial, we’ll discuss the Bellman-Ford algorithm in depth. We’ll cover the motivation, the steps of the algorithm, some running examples, …

  10. Bellman Ford’s Algorithm in Data Structures - Working, …

    2025年9月23日 · Explore Bellman Ford’s Algorithm in Data Structures: Understand its working principles and versatile applications for efficient path finding.