Q. What is the output of the following Python code for a binary tree traversal: 'preorder_traversal(root)'?
-
A.
Left, Root, Right
-
B.
Root, Left, Right
-
C.
Left, Right, Root
-
D.
Right, Left, Root
Solution
Preorder traversal visits the root node first, followed by the left subtree and then the right subtree, resulting in 'Root, Left, Right'.
Correct Answer:
B
— Root, Left, Right
Learn More →
Q. What is the primary purpose of a binary tree?
-
A.
To store data in a linear fashion
-
B.
To facilitate quick searching and sorting
-
C.
To represent hierarchical data
-
D.
To implement stacks and queues
Solution
Binary trees are primarily used to represent hierarchical data structures, such as file systems or organizational structures.
Correct Answer:
C
— To represent hierarchical data
Learn More →
Showing 1 to 2 of 2 (1 Pages)