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

Project: audit a depot forest and incident notes

Last updated: 5 Oct 202625 min read
project
IntermediateBy AITrove Editorial

A depot console keeps an acyclic maintenance network, indexes an arriving incident log, and edits a dispatcher note. Give each operation a reference model before optimizing it. A plain adjacency map answers connected and path-sum requests by breadth-first search. A Python string answers substring membership and gives a brute-force set of distinct substrings for small cases. A second Python string tracks the note after insertion and deletion. The production-oriented structures must agree with these models after every mutation, not only at the end of a prepared trace.

Acceptance trace

Give D-19, D-26, D-47, and D-61 weights 7, 11, 13, and 17. Link D-19 to D-26 and D-26 to D-47: the path sums to 31. Cut the latter edge; the endpoints are disconnected. Link D-47 to D-61, then D-26 to D-61; the path from D-19 to D-47 sums to 48. Append dispatch-dispatch one character at a time. Membership accepts patch and patch-dis, rejects warehouse, and the final distinct-substring count is 117. Insert north and a space into Depot D-19 cleared at position 6, then delete positions [12, 17). The visible note becomes Depot north cleared.

Expected output

Output
path-before=31 disconnected=true path-after=48
patch=true warehouse=false distinct=117
note=Depot north cleared length=19

Boundary and cost review

Reject a forest link that creates a cycle and a cut that does not name a direct edge. Try a one-node path and a disconnected path. Check empty and one-character substrings after every append; no operation here deletes indexed log text. For the editor, test insertion at both ends, deletion across several pieces, and empty edits. Link-cut work is amortized logarithmic, not a deadline bound for an individual call. The suffix automaton consumes growing memory and does not return match positions. The shown piece list and Python string addition buffer may both require linear copying during an edit. Keep these limits visible in any interface built over the examples.

Common Mistakes

  • Do not turn the represented forest into a graph with cycles.
  • Do not count a substring once per occurrence when asked for distinct strings.
  • Do not rewrite source text instead of editing the live piece sequence.
  • Do not claim a worst-case bound from an amortized argument.

Connected lessons

data structures
projects
Storage details