Professional Documents
Culture Documents
Advanced Ds Mcqs
Advanced Ds Mcqs
Advanced Ds Mcqs
ST - III
BINARY TREES
a) 2^h-1
b) 2^h
c) 2^(h+1)
d) 2^(h-1)
Answer: a) 2^h-1
2. What type of traversal visits the left sub-tree, the root, and then the right sub-tree of a binary tree?
a) In-order
b) Pre-order
c) Post-order
d) Level-order
Answer: a) In-order
3.What is the time complexity of searching for a node in a binary search tree?
a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: b) O(log n)
a) Breadth-first search
b) Depth-first search
c) AVL rotation
d) Hash table
a) As an array
b) As a linked list
c) As a hash table
d) As a graph
1. What is the property of a binary search tree that the left child of a node must have a value smaller
than that of the node, and the right child must have a value greater than that of the node?
a) Sorted order
b) Complete tree
c) Balanced tree
d) Search property
Answer: d) Search Property
2. What is the time complexity of finding the minimum element in a binary search tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)
3. Which traversal visits the left sub-tree, the root, and then the right sub-tree of a binary search tree?
a) In-order
b) Pre-order
c) Post-order
d) Level-order
Answer: a) In-order
4. What is the technique used to delete a node from a binary search tree?
a) Breadth-first search
b) Depth-first search
c) AVL rotation
d) Node replacement
Answer: d) Node Replacement
5. What is the method used to find the lowest common ancestor of two nodes in a binary search tree?
a) Breadth-first search
b) Depth-first search
c) Backtracking
d) Recursion
Answer: d) Recursion
7. What is the time complexity of searching for a node in a balanced binary search tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
8. What is the time complexity of inserting a node in a balanced binary search tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
9. What is the time complexity of deleting a node in a balanced binary search tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: O(log n)
10. What is the property that must be maintained in a self-balancing binary search tree to ensure that
the tree remains balanced?
a) Sorted order
b) Complete tree
c) Balanced tree
d) Search property
Answer: c) Balanced tree
11.What is the algorithm used to balance a binary search tree when a node is inserted or deleted?
a) Breadth-first search
b) Depth-first search
c) AVL rotation
d) Hash table
Answer: c) AVL rotation
12. How is the height of a binary search tree calculated?
a) Number of nodes
b) Maximum depth
c) Minimum depth
d) Average depth
Answer: b) Maximum depth
AVL Trees: Balanced Trees, Introduction to the AVL trees,
Implementation of AVL Trees
1. What is the name of the algorithm that is used to maintain balance in AVL trees?
a) Breadth-first search
b) Depth-first search
c) AVL rotation
d) Hash table
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
3. What is the maximum number of rotations required to insert or delete a node in an AVL tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
4. What is the property that must be maintained in an AVL tree to ensure that the tree remains
balanced?
a) Sorted order
b) Complete tree
c) Height-balanced
d) Search property
Answer: c) Height-balanced
5. What is the difference between the height of the left subtree and the height of the right subtree in
an AVL tree called?
a) Balance factor
b) Height factor
c) Weight factor
d) Size factor
a) Number of nodes
b) Maximum depth
c) Minimum depth
d) Average depth
7. What are the two types of rotations used in AVL trees to maintain balance?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
9. What is the time complexity of inserting a node in an AVL tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
11. What is the maximum difference in height between the left and right subtrees in an AVL tree?
a) 1
b) 2
c) log n
d) n
Answer: a) 1
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
Advance recursion problems and Optimization
1. What is the technique used to reduce the time complexity of a recursive function by storing the
results of subproblems in a cache?
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
2. What is the technique used to reduce the time complexity of a recursive function by breaking down
the problem into smaller subproblems?
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
3. What is the technique used to reduce the time complexity of a recursive function by making a
choice and then backtracking if the choice leads to an incorrect solution?
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
Answer: b) Backtracking
4. What is the technique used to reduce the time complexity of a recursive function by always making
the locally optimal choice?
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
5. How can the time complexity of a recursive function be reduced by eliminating redundant recursive
calls?
a) Memoization
b) Top-down approach
c) Bottom-up approach
d) Iterative approach
Answer: a) Memoization
6. How can the time complexity of a recursive function be reduced by eliminating overlapping
subproblems?
a) Memoization
b) Top-down approach
c) Bottom-up approach
d) Iterative approach
Answer: a) Memoization
7. What is the technique used to solve a problem by breaking it down into smaller subproblems and
solving each subproblem independently?
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
a) Dynamic programming
b) Backtracking
d) Greedy algorithm
9. What is the technique used to solve a problem by using a combination of recursion and iteration?
b) Iterative deepening
d) Recursive descent
10. What is the technique used to solve a problem by using a combination of recursion and
memorization?
b) Iterative deepening
d) Recursive descent
11. What is the technique used to solve a problem by using a combination of recursion and dynamic
programming?
b) Iterative deepening
d) Recursive descent
b) Iterative deepening
d) Recursive descent
1. What is the name of the algorithm that is used to maintain balance in red-black trees?
a) AVL rotation
b) Red-black rotation
c) B-tree rotation
d) Hash table
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
a) Sorted order
b) Complete tree
c) Height-balanced
d) Color-balanced
Answer: d) Color-balanced
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: O(log n)
a) Using a queue
b) Using a stack
c) Using a tree
a) Using a queue
b) Using a stack
c) Using a tree
9. What is the difference between a red-black tree and a binary search tree?
b) Binary search tree has a search property, red-black tree does not.
c) Red-black tree has a color property, binary search tree does not.
c) By enforcing a balance property between the number of red and black nodes in the tree
d) By enforcing a balance property between the number of left and right nodes in the tree
Answer: c) By enforcing a balance property between the number of red and black nodes in the tree
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
12. What is the time complexity of deleting a node in a red-black tree?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)
13. What is the technique used to find the shortest path between two nodes in a graph?
a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Breadth-first search
d) Depth-first search
14. What is the time complexity of Dijkstra's algorithm for finding the shortest path in a graph?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
A) Hash table
B) Binary tree
C) Prefix tree
D) Heap
B) Using a stack
C) Using a nested class structure with a character, a boolean flag and a map of child nodes
D) Using a queue
Answer: Using the nested class structure with a character, a boolean flag and a map of child nodes
A) A data structure used to store all the possible prefixes of a given string in lexicographically sorted
order
B) A data structure used to store all the possible suffixes of a given string in lexicographically sorted
order
C) A data structure used to store all the possible substrings of a given string in lexicographically sorted
order
D) A data structure used to store all the unique characters of a given string in lexicographically sorted
order
Answer: b) A data structure used to store all the possible suffixes of a given string in lexicographically
sorted order
4. How is a suffix array implemented in Java?
B) Using a stack
D) Using a queue
Answer: c) Using a array of integers sorted lexicographically based on the corresponding suffixes
A) The task of finding the longest substring that appears in the input string only once
B) The task of finding the shortest substring that appears in the input string more than once
C) The task of finding the longest substring that appears in the input string more than once with
overlapping occurrences
D) The task of finding the longest substring that appears in the input string more than once with non-
overlapping occurrences
Answer: d) The task of finding the longest substring that appears in the input string more than once
with non-overlapping occurrences
6. How can we find the longest repeated substring with non-overlapping occurrences using suffix
arrays?
A) By comparing each pair of adjacent suffixes in the sorted array and find the longest common suffix
between them
B) By comparing each pair of adjacent suffixes in the sorted array and find the shortest common suffix
between them
C) By comparing each pair of adjacent suffixes in the sorted array and find the longest common prefix
between them
D) By comparing each pair of adjacent suffixes in the sorted array and find the shortest common
prefix between them
Answer: c) By comparing each pair of adjacent suffixes in the sorted array and find the longest
common prefix between them
7. What is the main advantage of using a tried data structure over a hash table for storing a collection
of strings
A) O(n)
B) O(1)
C) O(log n)
D) O(n log n)
Answer: a) O(n)
9. How can suffix arrays be used to solve the longest common substring problem?
A) By comparing each pair of adjacent suffixes in the sorted array and find the longest common suffix
between them
B) By comparing each pair of adjacent suffixes in the sorted array and find the shortest common suffix
between them
C) By comparing each pair of adjacent suffixes in the sorted array and find the longest common prefix
between them
D) By comparing each pair of adjacent suffixes in the sorted array and find the shortest common
prefix between them
Answer: c) By comparing each pair of adjacent suffixes in the sorted array and find the longest
common prefix between them
10. What is the time complexity of constructing a suffix array for a given string?
A) O(n)
B) O(1)
C) O(log n)
D) O(n log n)
11. What is the time complexity of finding the longest repeated substring with non-overlapping
occurrences using suffix arrays?
A) O(n^2)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: b) O(n)
12. How can we find the longest repeated substring with overlapping occurrences using a tried?
A) By traversing the tried and counting the number of times each word appears
B) By traversing the tried and checking if any word appears more than once
C) By traversing the tried and checking if any word has more than one child
D) By traversing the tried and comparing the length of each word to find the longest one.
Answer: b) By traversing the tried and checking if any word appears more than once