What is the order of visiting nodes in Preorder Tree Traversal?
In Preorder traversal, nodes are visited in this order: Root first, then Left subtree, and finally Right subtree.
Click to reveal answer
beginner
Show the Preorder traversal output for this tree: Root: 1, Left child: 2, Right child: 3
The Preorder traversal visits nodes as Root-Left-Right. Output: 1 -> 2 -> 3
Click to reveal answer
beginner
What is the base case in a recursive Preorder traversal function?
The base case is when the current node is nullptr. Then, the function returns without doing anything.
Click to reveal answer
intermediate
Why is Preorder traversal useful in copying a tree?
Because Preorder visits the root before children, it allows copying the root node first, then recursively copying left and right subtrees, preserving structure.
Click to reveal answer
beginner
Write the recursive steps for Preorder traversal in simple words.
1. Visit the current node (root). 2. Traverse the left subtree in Preorder. 3. Traverse the right subtree in Preorder.
Click to reveal answer
In Preorder traversal, which node is visited first?
ALeft child
BRight child
CRoot node
DLeaf node
✗ Incorrect
Preorder traversal always visits the root node first before its children.
What is the correct Preorder traversal sequence for this tree? 1 / \ 2 3
A1 -> 2 -> 3
B2 -> 1 -> 3
C3 -> 2 -> 1
D2 -> 3 -> 1
✗ Incorrect
Preorder visits root first (1), then left child (2), then right child (3).
Which traversal order is Preorder?
ALeft, Right, Root
BRoot, Left, Right
CLeft, Root, Right
DRight, Left, Root
✗ Incorrect
Preorder traversal visits root first, then left subtree, then right subtree.
What happens when the recursive Preorder function reaches a null node?
AIt continues to next node
BIt visits the null node
CIt throws an error
DIt returns immediately
✗ Incorrect
The base case for recursion is when node is null, so the function returns immediately.
Which of these is NOT a use case of Preorder traversal?
APrinting nodes in sorted order
BEvaluating expression trees
CSaving tree structure
DCopying a tree
✗ Incorrect
Printing nodes in sorted order requires Inorder traversal, not Preorder.
Explain how Preorder traversal visits nodes in a binary tree.
Think about the order Root, Left, Right.
You got /4 concepts.
Describe a simple recursive function for Preorder traversal.
Remember the base case and the three main steps.
You got /4 concepts.
Practice
(1/5)
1. What is the order of nodes visited in a preorder tree traversal?
easy
A. Right, Root, Left
B. Left, Root, Right
C. Left, Right, Root
D. Root, Left, Right
Solution
Step 1: Understand preorder traversal definition
Preorder traversal visits the root node first, then the left subtree, and finally the right subtree.
Step 2: Match the order with options
Root, Left, Right matches the order Root, Left, Right exactly.
Final Answer:
Root, Left, Right -> Option D
Quick Check:
Preorder = Root, Left, Right [OK]
Hint: Remember preorder starts with the root node first [OK]
Common Mistakes:
Confusing preorder with inorder or postorder
Visiting left before root
Visiting right before left
2. Which of the following C++ function signatures correctly represents a preorder traversal of a binary tree node Node*?
Preorder visits root first, then left subtree, then right subtree.
Step 2: Check function code order
void preorder(Node* root) { if(root) { cout << root->data; preorder(root->left); preorder(root->right); } } prints root data first, then recursively visits left and right children, matching preorder.
Preorder visits root first, then left subtree, then right subtree.
Step 2: Check given function and options
The given function prints after left subtree, which is inorder traversal. void preorder(Node* root) { if(root == nullptr) return; cout << root->data << " "; preorder(root->left); preorder(root->right); } prints root first, then left, then right, matching preorder.
Print root before recursive calls for preorder [OK]
Hint: Print root data before recursive calls to fix preorder [OK]
Common Mistakes:
Printing after left subtree (inorder)
Swapping left and right subtree calls
Missing null pointer check
5. You have a binary tree where some nodes have only one child. How does preorder traversal help in serializing this tree uniquely, and which sequence below represents the preorder traversal of this tree?
8
/ \
4 10
\ \
6 20
hard
A. [8, 10, 20, 4, 6]
B. [4, 6, 8, 10, 20]
C. [8, 4, 6, 10, 20]
D. [6, 4, 8, 20, 10]
Solution
Step 1: Understand preorder traversal for serialization
Preorder visits root first, then left subtree, then right subtree, capturing structure including nodes with single children.
Step 2: Traverse given tree in preorder
Visit 8 (root), then left subtree: 4, then 6 (right child of 4), then right subtree: 10, then 20 (right child of 10).
Step 3: Write traversal sequence
Sequence is [8, 4, 6, 10, 20].
Final Answer:
[8, 4, 6, 10, 20] -> Option C
Quick Check:
Preorder captures root-left-right including single children [OK]
Hint: Preorder captures tree shape by visiting root before children [OK]
Common Mistakes:
Ignoring nodes with single child
Mixing preorder with inorder
Visiting right subtree before left
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.