Preorder Tree Traversal

Root -> Left -> Right recursion visualizer

Read Here
Step0/27
Visited0
Back To Trees List

Python Code

10
def recursivePreorder(self, root, arr):
12 # Base case: no node to process
13 if root is None:
14 return
15 arr.append(root.data)
16 self.recursivePreorder(root.left, arr)
17 self.recursivePreorder(root.right, arr)
18
Current Line (11): Function Entry

Tree Structure

1234567
Operation:ENTER:

Traversal Progress

Current Node

-

Phase

Enter Function

Result Array

Traversal result appears here...
Step 1: ENTER:

Recursion Stack

Stack is empty. Click Next to begin!

Step Explanation

Ready to Start

Click "Next Step" to begin. We will follow Root -> Left -> Right and explain each highlighted code line.

  • > Start from recursivePreorder(root, arr).
  • > Watch call stack, highlighted line, and result array together.
Unvisited
Left
Current
Right
Done