Skip to content
StackDecode
Advanced data structuresExplained

Persistent Segment Tree

Keep every past version by copying only the changed path.

Time

O(log n) per version

Extra space

O(n log n)

Use it for

Historical or k-th smallest queries.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.