Question 5
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?
7
8
9
10
Solve them and check answers →Read the notes first
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?
7
8
9
10
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.
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$?
The complexity of searching for an element is $O(\log n)$ whether the tree is balanced or unbalanced.
The complexity of searching for an element is $O(n)$, if the tree is balanced.
The complexity of searching for an element is $O(n)$, if the tree is unbalanced.
The complexity of searching for an element is $O(\log n)$, if the tree is balanced.
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?
A
B
C
D
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?
70, 60, 20, 50, 30, 46
50, 10, 36, 40, 31, 46
20, 75, 58, 30, 55, 46
60, 10, 40, 50, 42, 46
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.
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?
FDKCEJAHBIG
FKDGCHEJAIB
FDKCEAJHBIG
FDKCEJAHIBG
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?
C
E
F
I
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.
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.
255 and 8, respectively
256 and 7, respectively
127 and 8, respectively
255 and 7, respectively
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?
def traverse(ptr):
if ptr is None:
return
traverse(ptr.left)
print(ptr.key)
traverse(ptr.right)def traverse(ptr):
if ptr is None:
return
print(ptr.key)
traverse(ptr.left)
traverse(ptr.right)def traverse(ptr):
if ptr is None:
return
traverse(ptr.right)
traverse(ptr.left)
print(ptr.key)def traverse(ptr):
if ptr is None:
return
traverse(ptr.right)
print(ptr.key)
traverse(ptr.left)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.
The maximum element of a BST is always guaranteed to be ___
a leaf node
the root node
a node without a right child
a node without a left child
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?
The number of elements is at most $2^{h-1}$.
The number of elements is at least $h$.
The number of elements is at least $h + 1$.
The number of elements is at most $h \log h$.
The number of elements is at most $2^h - 1$.
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.
0
1
2
3
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?
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?
2, 3, 50, 40, 60, 43
61, 52, 14, 17, 40, 43
10, 65, 31, 48, 37, 43
17, 77, 27, 66, 18, 43
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?
def traverse(root):
if root is None:
return
traverse(root.left)
traverse(root.right)
print(root.data, end=' ')def traverse(root):
if root is None:
return
traverse(root.right)
traverse(root.left)
print(root.data, end=' ')def traverse(root):
if root is None:
return
traverse(root.left)
print(root.data, end=' ')
traverse(root.right)def traverse(root):
if root is None:
return
traverse(root.right)
print(root.data, end=' ')
traverse(root.left)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.
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?
A
B
C
D. None of these
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$
Only statement I is true
Only statement II is true
Both statements are true
Both statements are not true
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?
1 3 4 2 7 6 9 8 5
1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1
9 7 6 8 3 4 1 2 5
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.
Minimum: 255, Maximum: 1023
Minimum: 9, Maximum: 255
Minimum: 88, Maximum: 511
Minimum: 256, Maximum: 511
Consider a binary tree with 21 nodes. The maximum number of leaves possible in tree is ___.
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.
3
4
5
6
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
In-order traversal
Pre-order traversal
Post-order traversal
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.
38
56
14
18
23
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?
50, 10, 36, 40, 31, 46
50, 90, 75, 88, 62, 68
45, 50, 49, 48, 44, 47
45, 50, 46, 49, 47, 48
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 ___
40, 85
25, 40
62, 85
25, 62
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?
A
B
C
D
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?
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?
2
3
4
5
We have $n$ distinct values stored in a height-balanced (AVL) binary search tree. Which of the following statements is always true?
The value at each node is the median of the values in the subtree rooted at that node.
The shortest path between any pair of nodes is at most $O(\log n)$.
For any node, the difference between the size of the left subtree and the size of the right subtree is at most 3.
The number of leaf nodes is greater than or equal to the number of internal nodes.