Skip to content

STRATEGY BREADTH_FIRST performs a depth-first traversal #5158

Closed

Description

@lvca

TRAVERSE ... STRATEGY BREADTH_FIRST walks the graph depth-first instead of breadth-first.

BreadthFirstTraverseStep consumes entry points from the front of the entryPoints deque (removeFirst) but pushes newly discovered children onto the front as well (addFirst). Front-in/front-out is a LIFO stack, i.e. the exact behavior of DepthFirstTraverseStep - so BREADTH_FIRST produces a depth-first order. Its own prettyPrint even reports DEPTH-FIRST TRAVERSE. The step has behaved this way since its first commit (OrientDB's equivalent is a correct FIFO).

On a balanced binary tree (1 -> {2,3}; 2 -> {4,5}; 3 -> {6,7}) the emitted $depth sequence is [0,1,2,2,1,2,2] (depth-first) instead of the correct [0,1,1,2,2,2,2] (level order). The existing breadthFirst() test could not catch this because it ran on a linear chain, on which BFS and DFS emit identically.

Fix: push discovered nodes to the end of the deque (addLast) so it is a FIFO queue and the traversal is genuinely breadth-first; also correct the prettyPrint label.

Fixed by #5134.

Activity

  1. lvca commented on Jul 9, 2026

    @lvca
    MemberAuthor

    Fixed by #5134, merged in f0a9a56.

  2. self-assigned this
    on Jul 9, 2026
  3. added theissue type on Jul 9, 2026
  4. added this to the 26.7.2 milestone on Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions