Which of the following is the pre-order traversal of the tree below?
Explanation:
Pre-order traversal of a tree is a type of depth-first traversal where the nodes of the tree are visited in the following order:
- Visit the root node first.
- Traverse the left subtree recursively using pre-order.
- Traverse the right subtree recursively using pre-order.
In simple terms, the pre-order traversal visits the root before its child nodes. The general process is summarized as:
- Root → Left → Right
Example:
Consider the following binary tree:
1 / \ 2 3 / \ 4 5
The pre-order traversal would visit the nodes in this order:
1 → 2 → 4 → 5 → 3
Comments
Post a Comment