← Tree Recursion

Pattern Recognition Drill

#91 — Serialize and deserialize BST

Medium Advanced Trees

The Problem

Serialize a binary tree to a string and reconstruct it.

What approach would you use?

Think about it before scrolling down.

Key Signals

Tree Recursion

Serialize: preorder with '#' for nulls. Deserialize: read values in order, recurse. O(n).

Alt: Queue / BFS

Level-order serialization with null markers also works. Same O(n).

Common Trap

Need null markers to distinguish tree shapes. Without them, different trees can have same traversal.

← #90 #92 →