AlgoViz

Preorder Traversal

Preorder traversal visits nodes in Root-Left-Right order. Useful for copying or serializing trees.

BeginnerTime: O(n)Space: O(h)
Take Quiz
503070204060801025354555657590
Step 1 / 0

Current Step

Click Play to start the visualization


## How Preorder Traversal Works

Preorder traversal visits nodes in the order: Root -> Left subtree -> Right subtree. This is useful for creating a copy of the tree or serializing it.

### Algorithm Steps:
1. Visit the current node (process/print it)
2. Recursively traverse the left subtree
3. Recursively traverse the right subtree

### Key Characteristics:
- **Root first**: Always processes root before children
- **Tree copying**: Useful for duplicating tree structure
- **Prefix expression**: Creates prefix notation for expression trees

Time & Space Complexity

CaseTime Complexity
BestO(n)
AverageO(n)
WorstO(n)
SpaceO(h)

Practice Problems

No Problems Available

Practice problems for this algorithm are coming soon!