Trees: BST and AVL: past questions

33 questions · 102 marks · 10 papers. Try each one before checking.

Solve them and check answers →Read the notes first

03 Aug 2025

Question 5 MCQ · 3 marks

A tree is said to be a strictly binary tree, if every node contains either 0 or 2 children. If a binary search tree (BST) is a strictly binary tree and has 4 leaves. What is the total number of nodes in this BST?

  1. 7

  2. 8

  3. 9

  4. 10

Question 16 SA · 3 marks

What will be the maximum number of nodes possible in a binary tree of height 5? Consider that the height of the empty binary tree is 0.

Type your answer on the interactive page.

Question 13 MSQ · 3 marks

Which of the following statements is/are false about the worst-case time complexity of the searching operation in a binary search tree of size $n$?

  1. The complexity of searching for an element is $O(\log n)$ whether the tree is balanced or unbalanced.

  2. The complexity of searching for an element is $O(n)$, if the tree is balanced.

  3. The complexity of searching for an element is $O(n)$, if the tree is unbalanced.

  4. The complexity of searching for an element is $O(\log n)$, if the tree is balanced.

Question 8 MCQ · 3 marks

Consider the following AVL Tree (root 10, left child 5 with children 3 and 8, right child 20). Which of the following is the resultant AVL tree after inserting a new element 1 in the given AVL tree?

This question has a figure: open the interactive page.

  1. A

  2. B

  3. C

  4. D

July 2022

Question 5 MCQ · 3 marks

Which one of the following can not be a possible sequence of elements in the path from the root to any leaf in a binary search tree?

  1. 70, 60, 20, 50, 30, 46

  2. 50, 10, 36, 40, 31, 46

  3. 20, 75, 58, 30, 55, 46

  4. 60, 10, 40, 50, 42, 46

Question 12 SA · 4 marks

While inserting the elements 60, 20, 68, 10, 45, 50, 30, 47, and 85 in an empty binary search tree (BST) in the sequence shown, the height of the created binary search tree is ___. Assume that the height of the empty tree is 0.

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Question 4 MCQ · 3 marks

Consider the following class for tree nodes in the given tree (value, left, right). The code is the standard post-order: traversal(t.left), traversal(t.right), then print(t.value, end=''). Which of the following order will be printed by the given code-snippet?

  1. FDKCEJAHBIG

  2. FKDGCHEJAIB

  3. FDKCEAJHBIG

  4. FDKCEJAHIBG

01 Dec 2024

Question 5 MCQ · 3 marks

Consider the following binary search tree. The letters indicate the names of the nodes, not the values that are stored. Which of the following nodes is $6^{th}$ smallest node (in terms of value) in the given binary search tree?

This question has a figure: open the interactive page.

  1. C

  2. E

  3. F

  4. I

Question 11 SA · 3 marks

What will be the minimum number of nodes in an AVL tree of height 9? Consider that the height of the empty tree is 0.

Type your answer on the interactive page.

06 Apr 2026

Question 4 MCQ · 3 marks

The maximum and minimum number of nodes possible in a binary search tree of height 8 are ___. Assume that the height of an empty tree is 0, and the height of a tree with a single node is 1.

  1. 255 and 8, respectively

  2. 256 and 7, respectively

  3. 127 and 8, respectively

  4. 255 and 7, respectively

Question 5 MCQ · 3 marks

Consider a Binary Search Tree (BST) containing distinct keys. Each node of the BST is defined using the class Node with fields key, left, right. The following recursive functions are applied by calling traverse(ptr), where ptr points to the root of the BST. Which of the following implementations will print the keys of the BST in strictly decreasing order?

  1. def traverse(ptr):
        if ptr is None:
            return
        traverse(ptr.left)
        print(ptr.key)
        traverse(ptr.right)
  2. def traverse(ptr):
        if ptr is None:
            return
        print(ptr.key)
        traverse(ptr.left)
        traverse(ptr.right)
  3. def traverse(ptr):
        if ptr is None:
            return
        traverse(ptr.right)
        traverse(ptr.left)
        print(ptr.key)
  4. def traverse(ptr):
        if ptr is None:
            return
        traverse(ptr.right)
        print(ptr.key)
        traverse(ptr.left)

Question 15 SA · 3 marks

An AVL tree contains 120 nodes. What is the maximum possible height of the AVL tree? Assume that the height of an empty AVL tree is 0 and the height of an AVL tree with a single node is 1.

Type your answer on the interactive page.

Aug 2023

Question 8 MCQ · 3 marks

The maximum element of a BST is always guaranteed to be ___

  1. a leaf node

  2. the root node

  3. a node without a right child

  4. a node without a left child

Question 9 MSQ · 3 marks

Define the height of a binary search tree to be the number of nodes in the longest path from root to leaf. Suppose we have a binary search tree $T$ of height $h$. Note that $T$ need not be balanced. Which of the following statements is true?

  1. The number of elements is at most $2^{h-1}$.

  2. The number of elements is at least $h$.

  3. The number of elements is at least $h + 1$.

  4. The number of elements is at most $h \log h$.

  5. The number of elements is at most $2^h - 1$.

Question 10 MCQ · 3 marks

Define the height balance factor or slope of a node as the absolute difference in height of the left subtree and the right subtree of the node. Create a binary search tree by inserting the following elements in the given order one at a time (Do not perform any rotations on this tree as you insert the items. It's just a binary search tree, not necessarily a balanced BST) 3, 1, 2, 4, 6, 5, 7, 8 What is the height balance factor or slope of the root node of this tree? Consider that the height of the empty tree is 0.

This question has a figure: open the interactive page.

  1. 0

  2. 1

  3. 2

  4. 3

Question 11 SA · 4 marks

Create an AVL tree by inserting the following elements in the given order (one at a time): 4, 7, 1, 3, 5, 6, 2, 8 What would be the sum of elements stored in leaf nodes of the resultant AVL tree?

Type your answer on the interactive page.

Dec 2023

Question 16 MSQ · 3 marks

A binary search tree is used to locate the number 43. Which of the following probe sequences of compared elements from the root to 43 is/are not possible?

  1. 2, 3, 50, 40, 60, 43

  2. 61, 52, 14, 17, 40, 43

  3. 10, 65, 31, 48, 37, 43

  4. 17, 77, 27, 66, 18, 43

Question 5 MCQ · 3 marks

Consider the following class for nodes in BST (data, left, right). You are given a binary search tree where each node is created by the given class Node and, the root contains the reference to the root node of the BST. Which of the following implementations is suitable to print the node's data in descending order?

  1. def traverse(root):
        if root is None:
            return
        traverse(root.left)
        traverse(root.right)
        print(root.data, end=' ')
  2. def traverse(root):
        if root is None:
            return
        traverse(root.right)
        traverse(root.left)
        print(root.data, end=' ')
  3. def traverse(root):
        if root is None:
            return
        traverse(root.left)
        print(root.data, end=' ')
        traverse(root.right)
  4. def traverse(root):
        if root is None:
            return
        traverse(root.right)
        print(root.data, end=' ')
        traverse(root.left)

Question 13 SA · 3 marks

What is the maximum possible height of an AVL tree containing 15 nodes? Consider that an AVL tree with a single node has a height of 1.

Type your answer on the interactive page.

Question 6 MCQ · 3 marks

Consider the AVL tree (root 38, left child 14 with children 8 and 23, node 23 has left child 18, right child 56 with children 45 and 82, node 82 has left child 70). What is the updated AVL tree after inserting 19 in the given AVL tree?

This question has a figure: open the interactive page.

  1. A

  2. B

  3. C

  4. D. None of these

16 Mar 2025

Question 3 MCQ · 3 marks

Let $H, I, L$, and $N$ represent height, number of internal nodes, number of leaf nodes, and the total number of nodes respectively in a rooted binary tree. Consider that the height of empty tree is 0. Which of the following statements is/are always true? (I) $H - 1 \le L \le 2^{H-1}$ (II) $H \le N \le 2^H - 1$

  1. Only statement I is true

  2. Only statement II is true

  3. Both statements are true

  4. Both statements are not true

Question 10 MCQ · 4 marks

Consider the following class for nodes in the given tree (value, left, right). The code is traversal(t): if t != None: traversal(t.right), traversal(t.left), print(t.value, end=' '). Which of the following order will be printed by the given traversal(root) function?

This question has a figure: open the interactive page.

  1. 1 3 4 2 7 6 9 8 5

  2. 1 2 3 4 5 6 7 8 9

  3. 9 8 7 6 5 4 3 2 1

  4. 9 7 6 8 3 4 1 2 5

Question 4 MCQ · 3 marks

What is the minimum and maximum number of nodes possible in AVL Trees with height 9? Assume that the height of the empty tree is 0.

  1. Minimum: 255, Maximum: 1023

  2. Minimum: 9, Maximum: 255

  3. Minimum: 88, Maximum: 511

  4. Minimum: 256, Maximum: 511

24 Mar 2024

Question 14 SA · 3 marks

Consider a binary tree with 21 nodes. The maximum number of leaves possible in tree is ___.

Type your answer on the interactive page.

Question 5 MCQ · 3 marks

Consider the following sequence of numbers inserted into an empty Binary Search Tree (BST): 50, 30, 20, 40, 70, 60, 80, 35 What will be the height of the resulting BST? Consider that the height of empty binary search tree is 0.

This question has a figure: open the interactive page.

  1. 3

  2. 4

  3. 5

  4. 6

Question 6 MCQ · 3 marks

Which of the following traversals would visit the nodes of a binary search tree in the following order? 10, 5, 3, 8, 15, 12, 20

  1. In-order traversal

  2. Pre-order traversal

  3. Post-order traversal

Question 11 MSQ · 3 marks

Define the slope of a node as the absolute difference in height between the left subtree and the right subtree of the node. Consider the AVL tree (root 38, left 14 with 8 and 23, 23 has left child 18; right 56 with 45 and 82, 82 has left child 70). After inserting 19 in the given AVL tree (before applying rotation), which of the following node's slopes will become greater than 1? Select all that are correct.

This question has a figure: open the interactive page.

  1. 38

  2. 56

  3. 14

  4. 18

  5. 23

04 Aug 2024

Question 7 MCQ · 3 marks

Which one of the following is a possible sequence of elements in root-to-leaf paths in a top-down fashion in a binary search tree?

  1. 50, 10, 36, 40, 31, 46

  2. 50, 90, 75, 88, 62, 68

  3. 45, 50, 49, 48, 44, 47

  4. 45, 50, 46, 49, 47, 48

Question 8 MCQ · 3 marks

While inserting the elements 45, 75, 15, 55, 5, 40, 62, 25, and 85 in an empty binary search tree in the sequence shown, the elements at maximum depth from root are ___

This question has a figure: open the interactive page.

  1. 40, 85

  2. 25, 40

  3. 62, 85

  4. 25, 62

Question 9 MCQ · 3 marks

Consider the AVL tree with root 15, left child 7 (children 4 and 10) and right child 20. Which of the following is the resultant AVL tree after inserting a new element 2 in the given AVL tree?

This question has a figure: open the interactive page.

  1. A

  2. B

  3. C

  4. D

14 Aug 2026

Question 14 SA · 3 marks

Assume the following definition of height: Height of an empty tree $= 0$. Height of a tree with only a root node $= 1$. What is the height of a complete binary tree that contains 1023 nodes?

Type your answer on the interactive page.

Question 6 MCQ · 3 marks

A Binary Search Tree (BST) is initially empty. The following keys are inserted in the given order: [50, 30, 70, 20, 40, 60, 80] Assume that the tree is a standard BST and no balancing operations are performed after insertion. How many comparisons are required to search for the key 60 in the resulting BST?

This question has a figure: open the interactive page.

  1. 2

  2. 3

  3. 4

  4. 5

Question 7 MCQ · 3 marks

We have $n$ distinct values stored in a height-balanced (AVL) binary search tree. Which of the following statements is always true?

  1. The value at each node is the median of the values in the subtree rooted at that node.

  2. The shortest path between any pair of nodes is at most $O(\log n)$.

  3. For any node, the difference between the size of the left subtree and the size of the right subtree is at most 3.

  4. The number of leaf nodes is greater than or equal to the number of internal nodes.

Check your answers →

Other PDSA topics