Skip to content

bellmanFord: runs in O(V²·E) rather than the O(V·E) / O(E) stated in README #2236

Open

Description

@devladpopov

bellmanFord.js (lines 21–39) finds each edge again via graph.findEdge, which is a linear scan of the vertex's edge list, and has no early exit when a pass relaxes nothing. On complete digraphs with unit weights (a best-case input):

V node visits visits / (V·E) time
20 79,420 10.4 3 ms
40 1.28M 20.5 10 ms
80 20.5M 40.5 136 ms
160 327.6M 80.5 1.8 s

Fix: iterate vertex.getEdges() directly (this also fixes #2230) and stop when an iteration changes nothing.


Found during an independent property-based audit of this repo (full report and reproducible harness: https://github.com/devladpopov/algorithm-autopsy/tree/main/autopsy-02).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions