Deserialise Tree
An interactive, step-by-step visualisation of Deserialise Tree.
- Category
- Trees
- Time complexity
- O(n)
- Space complexity
- O(n)
Pseudocode
consume tokens in the same preorder order "#" ⇒ null, otherwise build node and recurse
Reference implementation
def deserialize(tokens):
tok = next(tokens)
if tok == '#': return None
node = Node(int(tok))
node.l = deserialize(tokens)
node.r = deserialize(tokens)
return node