Binary Trees and Traversals - Implementations in C++

Download Q&A
Q. What is the output of an in-order traversal of the binary tree with root 1, left child 2, and right child 3?
  • A. 1, 2, 3
  • B. 2, 1, 3
  • C. 3, 1, 2
  • D. 1, 3, 2
Q. What is the output of the following in-order traversal on the binary tree: 1, 2, 3, 4, 5?
  • A. 1, 2, 3, 4, 5
  • B. 5, 4, 3, 2, 1
  • C. 2, 1, 4, 3, 5
  • D. 1, 3, 2, 5, 4
Q. What is the primary purpose of a queue in the context of binary tree traversal?
  • A. To store nodes for post-order traversal
  • B. To store nodes for in-order traversal
  • C. To store nodes for level-order traversal
  • D. To store nodes for pre-order traversal
Q. What is the primary purpose of a stack in the context of binary tree traversal?
  • A. To store tree nodes
  • B. To reverse the order of traversal
  • C. To keep track of visited nodes
  • D. To implement recursion
Q. What is the result of a post-order traversal on a binary tree with nodes 1, 2, and 3, where 1 is the root, 2 is the left child, and 3 is the right child?
  • A. 1, 2, 3
  • B. 2, 3, 1
  • C. 3, 2, 1
  • D. 1, 3, 2
Q. What is the space complexity of a recursive implementation of a binary tree traversal?
  • A. O(1)
  • B. O(n)
  • C. O(log n)
  • D. O(n log n)
Q. Which of the following algorithms can be used to find the height of a binary tree?
  • A. Depth-first search
  • B. Breadth-first search
  • C. Both depth-first and breadth-first search
  • D. None of the above
Q. Which of the following is a valid way to represent a binary tree node in C++?
  • A. struct Node { int data; Node* left; Node* right; };
  • B. class Node { int data; Node* left; Node* right; };
  • C. struct Node { int data; Node left; Node right; };
  • D. class Node { int data; Node left; Node right; };
Q. Which traversal method would you use to create a mirror image of a binary tree?
  • A. In-order
  • B. Pre-order
  • C. Post-order
  • D. Level-order
Q. Which traversal method would you use to get the nodes of a binary tree in post-order?
  • A. Visit left, visit right, visit node
  • B. Visit node, visit left, visit right
  • C. Visit right, visit left, visit node
  • D. Visit left, visit node, visit right
Q. Which traversal method would you use to get the nodes of a binary tree in reverse level order?
  • A. Pre-order
  • B. In-order
  • C. Post-order
  • D. Level-order
Showing 1 to 11 of 11 (1 Pages)
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely