Join Nostr
2026-10-25 13:08:00 UTC
in reply to

codementor on Nostr: Time: O(n). Each call creates one node and does O(1) work besides its two recursive ...

Time: O(n). Each call creates one node and does O(1) work besides its two recursive calls, and each value becomes exactly one node.

Recursion depth: O(log n), because each call works on half the range. That is also the height of the tree.

No copying is needed: pass lo and hi indexes instead of making smaller arrays. Copying sub-arrays would add O(n log n) work.

#tg002 · TG-002-A2