Challenge - 5 Problems
Tree Terminology Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
š§ Conceptual
intermediate1:00remaining
Identify the root node in a tree
In a tree data structure, which node is called the root?
Attempts:
2 left
š” Hint
Think about the starting point of the tree.
ā Incorrect
The root node is the topmost node in a tree and has no parent node.
ā Predict Output
intermediate1:30remaining
Find the leaf nodes in a tree
Given the following tree nodes and their children, which nodes are leaves?
DSA C++
Node 1: children = [2, 3] Node 2: children = [4] Node 3: children = [] Node 4: children = []
Attempts:
2 left
š” Hint
Leaves have no children.
ā Incorrect
Nodes 3 and 4 have no children, so they are leaves.
ā Predict Output
advanced1:30remaining
Calculate the height of a node
What is the height of node 2 in the following tree?
Structure:
1
āā 2
ā āā 4
āā 3
DSA C++
Height is the number of edges on the longest path from the node to a leaf.
Attempts:
2 left
š” Hint
Count edges from node 2 down to its farthest leaf.
ā Incorrect
Node 2 has one child (4), which is a leaf. So height is 1 edge.
ā Predict Output
advanced1:30remaining
Determine the depth of a node
What is the depth of node 4 in the tree below?
Structure:
1
āā 2
ā āā 4
āā 3
DSA C++
Depth is the number of edges from the root to the node.
Attempts:
2 left
š” Hint
Count edges from root (1) to node 4.
ā Incorrect
Path from root to node 4 is 1 -> 2 -> 4, which has 2 edges.
š§ Conceptual
expert2:00remaining
Identify the level of a node in a tree
In a tree, what does the level of a node represent?
Attempts:
2 left
š” Hint
Level is closely related to depth but starts counting from 1.
ā Incorrect
Level is depth plus one, counting the root as level 1.