Explore topic-wise MCQs in Data Structures and Algorithms.

This section includes 10 Mcqs, each offering curated multiple-choice questions to sharpen your Data Structures and Algorithms knowledge and support exam preparation. Choose a topic below to get started.

1.

Why to prefer red-black trees over AVL trees?

A. Because red-black is more rigidly balanced
B. AVL tree store balance factor in every node which costs space
C. AVL tree fails at scale
D. Red black is more efficient
Answer» C. AVL tree fails at scale
2.

Consider the below left-left rotation pseudo code where the node contains value pointers to left, right child nodes and a height value and Height() function returns height value stored at a particular node. What is missing?

A. Height(w-left), x-height
B. Height(w-right), x-height
C. Height(w-left), x
D. Height(w-left)View Answer
Answer» B. Height(w-right), x-height
3.

Consider the pseudo code: Does the above code can check if a binary search tree is an AVL tree?

A. yes
B. noView Answer
Answer» B. noView Answer
4.

Which of the below diagram is following AVL tree property? i.ii.

A. only i
B. only i and ii
C. only ii
D. i is not a binary search tree
Answer» C. only ii
5.

What maximum difference in heights between the leafs of a AVL tree is possible?

A. log(n) where n is the number of nodes
B. n where n is the number of nodes
C. 0 or 1
D. atmost 1
Answer» B. n where n is the number of nodes
6.

Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?

A. just build the tree with the given input
B. find the median of the set of elements given, make it as root and construct the tree
C. use trial and error
D. use dynamic programming to build the tree
Answer» C. use trial and error
7.

To restore the AVL property after inserting a element, we start at the insertion point and move towards root of that tree. is this statement true?

A. true
B. false
Answer» B. false
8.

What is the maximum height of an AVL tree with p nodes?

A. p
B. log(p)
C. log(p)/2
D. <sup>p</sup>‚ÅÑ<sub>2</sub>
Answer» C. log(p)/2
9.

Why we need to a binary tree which is height balanced?

A. to avoid formation of skew trees
B. to save memory
C. to attain faster memory access
D. to simplify storing
Answer» B. to save memory
10.

What is an AVL tree?

A. a tree which is balanced and is a height balanced tree
B. a tree which is unbalanced and is a height balanced tree
C. a tree with three children
D. a tree with atmost 3 children
Answer» B. a tree which is unbalanced and is a height balanced tree