SQL

Trace the bounded supply network

BOTIE

Create the root record at depth zero. Feed it, the edge list and max_depth into the bounded path expansion. Inspect its path records before grouping them.
Ready to test
0 passed · 0 failed · 2 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

Create the root record at depth zero. Feed it, the edge list and max_depth into the bounded path expansion. Inspect its path records before grouping them.

A supply fault can affect equipment several links away.

Inspect the component calculation
Repeat a bounded relation expansion(
  Anchor rows: Start from one hierarchy node(
    Root node ID: Starting node ID
  )
  Edges with parent_id and child_id: Supply connections
  Maximum depth: Maximum depth
)
Examples and results
Starting node ID
1
Supply connections
[
  {
    "parent_id": 1,
    "child_id": 2
  },
  {
    "parent_id": 1,
    "child_id": 3
  },
  {
    "parent_id": 2,
    "child_id": 4
  },
  {
    "parent_id": 3,
    "child_id": 4
  }
]
Maximum depth
3
Required result
[
  {
    "node_id": 1,
    "depth": 0,
    "path": [
      1
    ]
  },
  {
    "node_id": 2,
    "depth": 1,
    "path": [
      1,
      2
    ]
  },
  {
    "node_id": 3,
    "depth": 1,
    "path": [
      1,
      3
    ]
  },
  {
    "node_id": 4,
    "depth": 2,
    "path": [
      1,
      2,
      4
    ]
  },
  {
    "node_id": 4,
    "depth": 2,
    "path": [
      1,
      3,
      4
    ]
  }
]
Starting node ID
7
Supply connections
[
  {
    "parent_id": 7,
    "child_id": 8
  },
  {
    "parent_id": 1,
    "child_id": 2
  }
]
Maximum depth
3
Required result
[
  {
    "node_id": 7,
    "depth": 0,
    "path": [
      7
    ]
  },
  {
    "node_id": 8,
    "depth": 1,
    "path": [
      7,
      8
    ]
  }
]
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

This bounded traversal is a record demonstration, not a database optimiser or a complete reachability claim beyond max_depth. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Your last tested pieces can start the full construction. An existing draft there keeps its own pieces.

A new root has two routes and a cycle

This check uses the pieces from “Turn discovered paths into an affected-node report”.

BOTIE

Begin at node 10 with maximum depth 3. Two routes reach 13, and 13 points back to 10. Keep each reached node once with its minimum depth.
Starting node ID
10
Maximum depth
3
Supply connections
[
  {
    "parent_id": 10,
    "child_id": 11
  },
  {
    "parent_id": 10,
    "child_id": 12
  },
  {
    "parent_id": 11,
    "child_id": 13
  },
  {
    "parent_id": 12,
    "child_id": 13
  },
  {
    "parent_id": 13,
    "child_id": 10
  },
  {
    "parent_id": 13,
    "child_id": 14
  }
]

Use a number, text, or an array matching the requested result. For a matrix, put each row in brackets. Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

What does a depth-limited result establish, and why is a path guard insufficient to bound a very bushy acyclic graph?

Treat traversal completeness and resource limits as explicit parts of the question, alongside cycle handling.

This bounded traversal is a record demonstration, not a database optimiser or a complete reachability claim beyond max_depth.

Work through the SQL challenges →
Continue the courseKeep Every Reading While Looking at Its Neighbours →