Rule
In-order traversal of a BST visits nodes in ascending order. Link each visited node to the previous one, then connect head and tail.
Convert a BST in-place by reusing left as prev and right as next. In-order traversal gives sorted order for free; one final stitch closes the circle.
Key concepts at a glance — for those who already know the basics.
Rule
In-order traversal of a BST visits nodes in ascending order. Link each visited node to the previous one, then connect head and tail.
How to Think
1Run DFS in-order: left, node, right.
2Use head for the first visited node and prev for the last linked node.
3At each node: set prev.right = node and node.left = prev.
4After traversal: head.left = tail, tail.right = head.
Diagram
Complexity
Time
O(n)
Each node is visited exactly once.
Space
O(h)
Recursion stack only. Balanced: O(log n), skewed: O(n).
Common Mistakes