Trees

Inorder, preorder, postorder, and level-order traversals on a fixed BST

Trees: Traversals

Traversal Tree
Pick a traversal order to animate the visit sequence on the same BST.
Traversal Output
The output row grows one value at a time as each node is visited.

Traversal Notes

Inorder visits left subtree, node, then right subtree, which yields sorted output for a BST.

Preorder records the node before exploring children, while Postorder delays the visit until both children are done.

Level-order walks the tree breadth-first with a queue, so each row is processed from top to bottom.

Complexity

Inorder
Time:O(n)
Space:O(h)
Preorder
Time:O(n)
Space:O(h)
Postorder
Time:O(n)
Space:O(h)
Level-order
Time:O(n)
Space:O(w)