Queue length, recursion depth and visit positions in traversals of one tree

A binary tree with nine nodes has root A. Each line gives a node's left child and then its right child; nodes not listed as parents are leaves.

  • A: left child B, right child C
  • B: left child D, right child E
  • C: no left child, right child F
  • E: left child G, right child H
  • F: left child I, no right child

Answer the following, each as a whole number.

  1. A breadth-first traversal starts with only A in a queue. It repeatedly removes the front node, visits it, and adds that node's existing children to the back, left child first. What is the largest number of nodes in the queue at any moment?
  2. A recursive pre-order traversal is called on A and makes a recursive call only on a child that exists. What is the largest number of traversal calls active at the same time, counting the call on A?
  3. In the in-order traversal of the tree, at which position (1 = first visited) is node A visited?
  4. In the post-order traversal of the tree, at which position is node B visited?
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors