Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Project: audit depot connectivity and daily ranges

Last updated: 3 Oct 202616 min read
project
IntermediateBy AITrove Editorial

Review a fictional depot network and daily count dashboard. Sites North, East, West, and South form directed route edges. A breadth-first traversal from North visits East and West before South. A separate undirected connectivity view uses disjoint sets when links are added, but it cannot remove a link from an existing component. Daily counts 47, 31, 26, and 58 support a [1, 4) sum of 115; a correction of +3 to day index two changes it to 118. The project keeps route reachability, undirected grouping, and arithmetic ranges as distinct questions.

Select the correct representation

Use an adjacency list and BFS for reachability from a start site. Mark neighbors when enqueueing. Use DSU for repeated component checks while links only appear; rebuild or choose another method when deletions matter. Use a prefix-sum array for immutable reporting snapshots. Use a Fenwick tree for point deltas and prefix sums or a segment tree for point replacements and chosen associative range aggregates. Record which operation accepts a delta and which accepts a replacement.

Test the edge conditions

Add a disconnected site and confirm BFS omits it without claiming no other route exists from a different start. Close an undirected link and show why the old DSU snapshot must not be reused. Query empty interval [2, 2) and expect zero. Reject out-of-range day indices. Keep the revision of the daily data beside any cached prefix table. A wrong half-open bound can silently add a day's count and still produce a plausible report.

Output
Directed BFS from North: North, East, West, South.
DSU: union-only connectivity; closing a link needs rebuild.
Daily counts: [47, 31, 26, 58].
Range [1, 4): 115; after index 2 gains 3: 118.
Empty [2, 2): 0; invalid bounds: reject.

Cost and review

BFS costs O(V + E) time and storage for the route graph. DSU is near-constant amortized per union or find but cannot answer a path. Prefix sums build in O(n) and answer static ranges in O(1); Fenwick and segment trees update and query in O(log n). The dashboard should report which snapshot each result belongs to. A correct number under a stale revision is not an acceptable current answer.

Common Mistakes

  • Do not use directed reachability and undirected connectivity interchangeably.
  • Do not apply a link deletion to DSU as if it could split a group.
  • Do not reuse a prefix table after a count correction.

Connected lessons

data structures
projects
Storage details