DSA Final Mcqs
DSA Final Mcqs
1. A linear collection of data elements where the linear node is given by means of pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
View Answer
Answer: a
Explanation: In Linked list each node has its own data and the address of next node. These nodes are
linked by using pointers. Node list is an object that consists of a list of all nodes in a document with in a
particular selected set of nodes.
2. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a
head pointer only. Given the representation, which of the following operation can be implemented in
O(1) time?
a) I and II
b) I and III
c) I, II and III
d) I, II and IV
View Answer
Answer: b
Explanation: We know the head node in the given linked list. Insertion and deletion of elements at the
front of the linked list completes in O (1) time whereas for insertion and deletion at the last node
requires to traverse through every node in the linked list. Suppose there are n elements in a linked list,
we need to traverse through each node. Hence time complexity becomes O(n).
3. In linked list each node contains a minimum of two fields. One field is data field to store the data
second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
View Answer
Answer: c
Explanation: Each node in a linked list contains data and a pointer (reference) to the next node. Second
field contains pointer to node.
4. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
View Answer
Answer: c
Explanation: In case of a linked list having n elements, we need to travel through every node of the list
to add the element at the end of the list. Thus asymptotic time complexity is θ(n).
5. What would be the asymptotic time complexity to insert an element at the front of the linked list
(head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
View Answer
Answer: a
Explanation: To add an element at the front of the linked list, we will create a new node which holds the
data to be added to the linked list and pointer which points to head position in the linked list. The entire
thing happens within O (1) time. Thus the asymptotic time complexity is O (1).
6. What would be the asymptotic time complexity to find an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n4)
View Answer
Answer: b
Explanation: If the required element is in the last position, we need to traverse the entire linked list. This
will take O (n) time to search the element.
7. What would be the asymptotic time complexity to insert an element at the second position in the
linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
View Answer
Answer: a
Explanation: A new node is created with the required element. The pointer of the new node points the
node to which the head node of the linked list is also pointing. The head node pointer is changed and it
points to the new node which we created earlier. The entire process completes in O (1) time. Thus the
asymptotic time complexity to insert an element in the second position of the linked list is O (1).
8. The concatenation of two lists can be performed in O(1) time. Which of the following variation of the
linked list can be used?
View Answer
Answer: c
Explanation: We can easily concatenate two lists in O (1) time using singly or doubly linked list, provided
that we have a pointer to the last node at least one of the lists. But in case of circular doubly linked lists,
we will break the link in both the lists and hook them together. Thus circular doubly linked list
concatenates two lists in O (1) time.
struct node
int data;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
View Answer
Answer: a
This set of Data Structure Interview Questions and Answers for freshers focuses on “Singly Linked Lists
Operations – 2”.
1. What kind of linked list is best to answer questions like “What is the item at position n?”
View Answer
Answer: d
Explanation: Arrays provide random access to elements by providing the index value within square
brackets. In the linked list, we need to traverse through each element until we reach the nth position.
Time taken to access an element represented in arrays is less than the singly, doubly and circular linked
lists. Thus, array implementation is used to access the item at the position n.
a) Insertion sort
b) Radix sort
c) Polynomial manipulation
d) Binary search
View Answer
Answer: d
a) Dynamic
b) Static
c) Compile time
d) Heap
View Answer
Answer: a
a) Data
b) Link
d) Node
View Answer
Answer: b
Explanation: A linked list is a collection of objects linked together by references from an object to
another object. By convention these objects are names as nodes. Linked list consists of nodes where
each node contains one or more data fields and a reference(link) to the next node.
b) Space Utilization
d) Speed Utilization
View Answer
Answer: c
6. Which of the following points is/are not true about Linked List data structure when it is compared
with an array?
a) Arrays have better cache locality that can make them better in terms of performance
d) Access of elements in linked list takes less time than compared to arrays
View Answer
Answer: d
Explanation: To access an element in a linked list, we need to traverse every element until we reach the
desired element. This will take more time than arrays as arrays provide random access to its elements.
7. What does the following function do for a given Linked List with first node as head?
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data);
View Answer
Answer: b
8. Which of the following sorting algorithms can be used to sort a random linked list with minimum time
complexity?
a) Insertion Sort
b) Quick Sort
c) Heap Sort
d) Merge Sort
View Answer
Answer: d
5. In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is?
a) log 2 n
b) n⁄2
c) log 2 n – 1
d) n
View Answer
Answer: d
Explanation: In the worst case, the element to be searched has to be compared with all elements of the
linked list.
6. Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not
given, can we delete the node X from given linked list?
View Answer
Answer: a
X->data = temp->data;
X->next = temp->next;
free(temp);
7. You are given pointers to first and last nodes of a singly linked list, which of the following operations
are dependent on the length of the linked list?
View Answer
Answer: c
Explanation: Deletion of the first element of the list is done in O (1) time by deleting memory and
changing the first pointer.
Insertion of an element as a first element can be done in O (1) time. We will create a node that holds
data and points to the head of the given linked list. The head pointer was changed to a newly created
node.
Deletion of the last element requires a pointer to the previous node of last, which can only be obtained
by traversing the list. This requires the length of the linked list.
Adding a new element at the end of the list can be done in O (1) by changing the pointer of the last node
to the newly created node and last is changed to a newly created node.
8. In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is?
a) log2 n
b) n⁄2
c) log2 n – 1
d) n
View Answer
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Singly Linked List”.
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an array are lesser than the
allocated size
View Answer
Answer: d
Explanation: Array elements can be accessed in two steps. First, multiply the size of the data type with
the specified position, second, add this value to the base address. Both of these operations can be done
in constant time, hence accessing elements at a given index/position is faster.
a) O(1)
b) O(n)
c) O(logn)
View Answer
Answer: d
Explanation: Depending on whether the array is full or not, the complexity in dynamic array varies. If you
try to insert into an array that is not full, then the element is simply stored at the end, this takes O(1)
time. If you try to insert into an array which is full, first you will have to allocate an array with double the
size of the current array and then copy all the elements into it and finally insert the new element, this
takes O(n) time.
3. What is the time complexity to count the number of elements in the linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
View Answer
Answer: b
a) O(1)
b) O(n)
d) O(logn)
View Answer
Answer: a
View Answer
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Doubly Linked List”.
View Answer
Answer: d
5. How do you calculate the pointer difference in a memory efficient double linked list?
a) head xor tail
View Answer
Answer: b
Explanation: The pointer difference is calculated by taking XOR of pointer to previous node and pointer
to the next node.
6. What is the worst case time complexity of inserting a node in a doubly linked list?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(1)
View Answer
Answer: c
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Stack using Linked
List”.
1. What is the best case time complexity of deleting a node in a Singly Linked list?
a) O (n)
b) O (n2)
c) O (nlogn)
d) O (1)
View Answer
Answer: d
Explanation: Deletion of the head node in the linked list is taken as the best case. The successor of the
head node is changed to head and deletes the predecessor of the newly assigned head node. This
process completes in O(1) time.
2. Which of the following statements are not correct with respect to Singly Linked List(SLL) and Doubly
Linked List(DLL)?
a) Complexity of Insertion and Deletion at known position is O(n) in SLL and O(1) in DLL
View Answer
Answer: d
View Answer
Answer: b
9. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack
View Answer
Answer: d
Explanation: For every opening brace, push it into the stack, and for every closing brace, pop it off the
stack. Do not take action for any other character. In the end, if the stack is empty, then the input has
balanced parentheses.
a) 3
b) 4
c) 1
d) 2
View Answer
Answer: c
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Queue using Linked
List”.
1. In linked list implementation of queue, if only front pointer is maintained, which of the following
operation take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
View Answer
Answer: d
Explanation: Since front pointer is used for deletion, so worst time for the other two cases.
2. In linked list implementation of a queue, where does a new element be inserted?
View Answer
Answer: c
3. In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers
will change during an insertion into a NONEMPTY queue?
View Answer
Answer: b
4. In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers
will change during an insertion into EMPTY queue?
View Answer
Answer: c
Explanation: Since its the starting of queue, so both values are changed.
5. In case of insertion into a linked queue, a node borrowed from the __________ list is inserted in the
queue.
a) AVAIL
b) FRONT
c) REAR
d) NULL
View Answer
Answer: a
View Answer
Answer: a
Explanation: Since queue follows FIFO so new element deleted from first.
7. In linked list implementation of a queue, the important condition for a queue to be empty is?
a) FRONT is null
b) REAR is null
c) LINK is empty
d) FRONT==REAR-1
View Answer
Answer: a
8. The essential condition which is checked before insertion in a linked queue is?
a) Underflow
b) Overflow
c) Front value
d) Rear value
View Answer
Answer: b
9. The essential condition which is checked before deletion in a linked queue is?
a) Underflow
b) Overflow
c) Front value
d) Rear value
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Queue using Stacks”.
1. A Double-ended queue supports operations such as adding and removing items from both the sides of
the queue. They support four operations like addFront(adding item to top of the queue),
addRear(adding item to the bottom of the queue), removeFront(removing item from the top of the
queue) and removeRear(removing item from the bottom of the queue). You are given only stacks to
implement this data structure. You can implement only push and pop operations. What are the total
number of stacks required for this operation?(you can reuse the stack)
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: The addFront and removeFront operations can be performed using one stack itself as push
and pop are supported (adding and removing element from top of the stack) but to perform addRear
and removeRear you need to pop each element from the current stack and push it into another stack,
push or pop the element as per the asked operation from this stack and in the end pop elements from
this stack to the first stack.
2. You are asked to perform a queue operation using a stack. Assume the size of the stack is some value
‘n’ and there are ‘m’ number of variables in this stack. The time complexity of performing deQueue
operation is (Using only stack operations like push and pop)(Tightly bound).
a) O(m)
b) O(n)
c) O(m*n)
d) Data is insufficient
View Answer
Answer: a
Explanation: To perform deQueue operation you need to pop each element from the first stack and
push it into the second stack. In this case you need to pop ‘m’ times and need to perform push
operations also ‘m’ times. Then you pop the first element from this second stack (constant time) and
pass all the elements to the first stack (as done in the beginning)(‘m-1’ times). Therfore the time
complexity is O(m).
3. Consider you have an array of some random size. You need to perform dequeue operation. You can
perform it using stack operation (push and pop) or using queue operations itself (enQueue and
Dequeue). The output is guaranteed to be same. Find some differences?
d) No differences
View Answer
Answer: a
Explanation: To perform operations such as Dequeue using stack operation you need to empty all the
elements from the current stack and push it into the next stack, resulting in a O(number of elements)
complexity whereas the time complexity of dequeue operation itself is O(1). And there is a need of a
extra stack. Therefore more memory is needed.
5 4 3 2 << top
6 5 4 3 2 << top
The operations that needed to be performed are (You can perform only push and pop):
b) Push(pop()), push(6)
d) Push(6)
View Answer
Answer: a
Explanation: By performing push(pop()) on all elements on the current stack to the next stack you get 2
3 4 5 << top.Push(6) and perform push(pop()) you’ll get back 6 5 4 3 2 << top. You have actually
performed enQueue operation using push and pop.
5. A double-ended queue supports operations like adding and removing items from both the sides of the
queue. They support four operations like addFront(adding item to top of the queue), addRear(adding
item to the bottom of the queue), removeFront(removing item from the top of the queue) and
removeRear(removing item from the bottom of the queue). You are given only stacks to implement this
data structure. You can implement only push and pop operations. What’s the time complexity of
performing addFront and addRear? (Assume ‘m’ to be the size of the stack and ‘n’ to be the number of
elements)
View Answer
Answer: b
Explanation: addFront is just a normal push operation. Push operation is of O(1). Whereas addRear is of
O(n) as it requires two push(pop()) operations of all elements of a stack.
6. Why is implementation of stack operations on queues not feasible for a large dataset (Asssume the
number of elements in the stack to be n)?
View Answer
Answer: a
Explanation: To perform Queue operations such as enQueue and deQueue there is a need of emptying
all the elements of a current stack and pushing elements into the next stack and vice versa. Therfore it
has a time complexity of O(n) and the need of extra stack as well, may not be feasible for a large
dataset.
7. Consider yourself to be in a planet where the computational power of chips to be slow. You have an
array of size 10.You want to perform enqueue some element into this array. But you can perform only
push and pop operations .Push and pop operation both take 1 sec respectively. The total time required
to perform enQueue operation is?
a) 20
b) 40
c) 42
d) 43
View Answer
Answer: d
Explanation: First you have to empty all the elements of the current stack into the temporary stack, push
the required element and empty the elements of the temporary stack into the original stack. Therfore
taking 10+10+1+11+11= 43 seconds.
8. You have two jars, one jar which has 10 rings and the other has none. They are placed one above the
other. You want to remove the last ring in the jar. And the second jar is weak and cannot be used to
store rings for a long time.
a) Empty the first jar by removing it one by one from the first jar and placing it into the second jar
b) Empty the first jar by removing it one by one from the first jar and placing it into the second jar and
empty the second jar by placing all the rings into the first jar one by one
View Answer
Answer: b
Explanation: This is similar to performing dequeue operation using push and pop only. Elements in the
first jar are taken out and placed in the second jar. After removing the last element from the first jar,
remove all the elements in the second jar and place them in the first jar.
9. Given only a single array of size 10 and no other memory is available. Which of the following
operation is not feasible to implement (Given only push and pop operation)?
a) Push
b) Pop
c) Enqueue
d) Returntop
View Answer
Answer: c
Explanation: To perform Enqueue using just push and pop operations, there is a need of another array of
same size. But as there is no extra available memeory, the given operation is not feasible.
10. Given an array of size n, let’s assume an element is ‘touched’ if and only if some operation is
performed on it(for example, for performing a pop operation the top element is ‘touched’). Now you
need to perform Dequeue operation. Each element in the array is touched atleast?
a) Once
b) Twice
c) Thrice
d) Four times
View Answer
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Binary Trees using
Array”.
c) 0 or 1 or 2
d) 0 or 1
View Answer
Answer: c
c) have to know the maximum number of nodes possible before creation of trees
d) difficult to implement
View Answer
Answer: c
Explanation: The size of array is fixed in normal arrays. We need to know the number of nodes in the
tree before array declaration. It is the main disadvantage of using arrays to represent binary trees.
3. What must be the ideal size of array if the height of tree is ‘l’?
a) 2l-1
b) l-1
c) l
d) 2l
View Answer
Answer: a
Explanation: Maximum elements in a tree (complete binary tree in worst case) of height ‘L’ is 2L-1.
Hence size of array is taken as 2L-1.
4. What are the children for node ‘w’ of a complete-binary tree in an array representation?
a) 2w and 2w+1
View Answer
Answer: a
Explanation: The left child is generally taken as 2*w whereas the right child will be taken as 2*w+1
because root node is present at index 0 in the array and to access every index position in the array.
5. What is the parent for a node ‘w’ of a complete binary tree in an array representation when w is not
0?
a) floor(w-1/2)
b) ceil(w-1/2)
c) w-1/2
d) w/2
View Answer
Answer: a
6. If the tree is not a complete binary tree then what changes can be made for easy access of children of
a node in the array?
a) every node stores data saying which of its children exist in the array
View Answer
Answer: a
8. Consider a situation of writing a binary tree into a file with memory storage efficiency in mind, is array
representation of tree is good?
a) yes because we are overcoming the need of pointers and so space efficiency
View Answer
Answer: c
10. Can a tree stored in an array using either one of inorder or post order or pre order traversals be
again reformed?
a) Yes just traverse through the array and form the tree
View Answer
Answer: b
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Binary Trees using
Linked Lists”.
a) dynamic size
b) ease of insertion/deletion
View Answer
Answer: d
Explanation: It has both dynamic size and ease in insertion and deletion as advantages.
b) Extra memory for a pointer is needed with every element in the list
c) Difficulty in deletion
d) Random access is not possible and extra memory with every element
View Answer
Answer: d
a) Post order
b) Pre order
c) Post order
d) Randomized
View Answer
Answer: d
Explanation: Generally, all nodes in a tree are visited by using preorder, inorder and postorder traversing
algorithms.
4. Level order traversal of a tree is formed with the help of
c) dijkstra’s algorithm
d) prims algorithm
View Answer
Answer: a
5. Identify the reason which doesn’t play a key role to use threaded binary trees?
View Answer
Answer: d
Explanation: Threaded binary trees are introduced to make the Inorder traversal faster without using
any stack or recursion. Stack and Queue require more space and pointers in the majority of binary trees
are null and difficulties are raised while finding successor nodes. Size constraints are not taken on
threaded binary trees, but they occupy less space than a stack/queue.
6. The following lines talks about deleting a node in a binary tree.(the tree property must not be violated
after deletion)
ii)
d) ii)-find deepest node,replace with node to be deleted. iii)- delete the deepest node
View Answer
Answer: d
Explanation: We just replace a to be deleted node with last leaf node of a tree. this must not be done in
case of BST or heaps.
7. What may be the psuedo code for finding the size of a tree?
a) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)
b) find_size(root_node–>left_node) + find_size(root_node–>right_node)
c) find_size(root_node–>right_node) – 1
d) find_size(root_node–>left_node + 1
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Binary Tree Operations”.
1. What is the maximum number of children that a binary tree node can have?
a) 0
b) 1
c) 2
d) 3
View Answer
Answer: c
Explanation: In a binary tree, a node can have atmost 2 nodes (i.e.) 0,1 or 2 left and right child.
binary-tree-operations-questions-answers-q2
a) Binary tree
c) Fibonacci tree
d) AVL tree
View Answer
Answer: a
Explanation: The given tree is an example for binary tree since has got two children and the left and
right children do not satisfy binary search tree’s property, Fibonacci and AVL tree.
a) true
b) false
View Answer
Answer: b
Explanation: A binary tree is a rooted tree and also an ordered tree (i.e) every node in a binary tree has
at most two children.
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: c
Explanation: Three common operations are performed in a binary tree- they are insertion, deletion and
traversal.
a) depth-first traversal
b) breadth-first traversal
c) random traversal
d) Priority traversal
View Answer
Answer: b
Explanation: Breadth first traversal, also known as level order traversal is the traversal strategy used in a
binary tree. It involves visiting all the nodes at a given level.
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: Two kinds of insertion operation is performed in a binary tree- inserting a leaf node and
inserting an internal node.
View Answer
Answer: c
Explanation: The above diagram is a depiction of deleting a node with 0 or 1 child since the node D
which has 1 child is deleted.
a) true
b) false
View Answer
Answer: a
Explanation: General ordered tree can be mapped into binary tree by representing them in a left-child-
right-sibling way.
a) n+O(n)
b) 2n+O(n)
c) n/2
d) n
View Answer
Answer: b
Explanation: A succinct binary tree occupies close to minimum possible space established by lower
bounds. A succinct binary tree would occupy 2n+O(n) bits.
a) O(N)
b) O(√N)
c) O(N2)
d) O(log N)
View Answer
Answer: d
Explanation: The average depth of a binary tree is given as O(√N). In case of a binary search tree, it is
O(log N).
11. How many orders of traversal are applicable to a binary tree (In General)?
a) 1
b) 4
c) 2
d) 3
View Answer
Answer: d
Explanation: The three orders of traversal that can be applied to a binary tree are in-order, pre-order
and post order traversal.
12. If binary trees are represented in arrays, what formula can be used to locate a left child, if the node
has an index i?
a) 2i+1
b) 2i+2
c) 2i
d) 4i
View Answer
Answer: a
Explanation: If binary trees are represented in arrays, left children are located at indices 2i+1 and right
children at 2i+2.
a) (i+1)/2
b) (i-1)/2
c) i/2
d) 2i/2
View Answer
Answer: b
Explanation: If a binary tree is represented in an array, parent nodes are found at indices (i-1)/2.
14. Which of the following properties are obeyed by all three tree – traversals?
View Answer
Answer: a
Explanation: In preorder, inorder and postorder traversal the left subtrees are visited before the right
subtrees. In Inorder traversal, the Left subtree is visited first then the Root node then the Right subtree.
In postorder traversal, the Left subtree is visited first, then Right subtree and then the Root node is
visited.
15. Construct a binary tree using the following data.
The preorder traversal of a binary tree is 1, 2, 5, 3, 4. The inorder traversal of the same binary tree is 2,
5, 1, 4, 3.
a) binary-tree-operations-multiple-choice-questions-answers-mcqs-q15a
b) binary-tree-operations-multiple-choice-questions-answers-mcqs-q15b
c) binary-tree-operations-multiple-choice-questions-answers-mcqs-q15c
d) binary-tree-operations-multiple-choice-questions-answers-mcqs-q15d
View Answer
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Preorder Traversal”.
data-structure-questions-answers-preorder-traversal-q1
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
View Answer
Answer: a
data-structure-questions-answers-preorder-traversal-q1
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
View Answer
Answer: c
a)
System.out.println(root.data);
preorder(root.left);
preorder(root.right);
b)
preorder(root.left);
System.out.println(root.data);
preorder(root.right);
c)
public void preorder(Tree root)
System.out.println(root.data);
preorder(root.right);
preorder(root.left);
d)
preorder(root.right);
preorder(root.left);
System.out.println(root.data);
View Answer
a)
System.out.println(root.data);
postorder(root.left);
postorder(root.right);
b)
public void postorder(Tree root)
postorder(root.left);
postorder(root.right);
System.out.println(root.data);
c)
System.out.println(root.data);
postorder(root.right);
postorder(root.left);
d)
postorder(root.right);
System.out.println(root.data);
postorder(root.left);
View Answer
5. Select the code snippet that performs pre-order traversal iteratively.
a)
st.add(root);
while (!stk.empty())
b)
while (!stk.empty())
c)
st.add(root);
while (!stk.empty())
d)
while (!stk.empty())
View Answer
a)
if (root == null)
return;
if (node.right != null)
stk.add(node.left);
stk.add(node);
node = node.right;
node = stk.pop();
stk.push(node);
node = nodeRight;
} else
node = null;
b)
if (root == null)
return;
if (node.right != null)
stk.add(node.right);
stk.add(node);
node = node.left;
node = stk.pop();
stk.push(node);
node = nodeRight;
} else
node = null;
c)
{
if (root == null)
return;
if (node.right != null)
stk.add(node.right);
stk.add(node);
node = node.left;
node = stk.pop();
if (node.right != null)
stk.push(node);
node = nodeRight;
} else
node = null;
}
}
d)
if (root == null)
return;
if (node.right != null)
stk.add(node.left);
stk.add(node);
node = node.left;
node = stk.pop();
if (node.right != null)
stk.push(node);
node = nodeLeft;
} else
{
node = null;
View Answer
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
View Answer
Answer: b
Explanation: Since you have to go through all the nodes, the complexity becomes O(n).
8. What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree depth
and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
View Answer
Answer: d
Explanation: In the worst case we have d stack frames in the recursive call, hence the complexity is O(d).
a) Level-order traversal
b) Pre-order traversal
c) Post-order traversal
d) In-order traversal
View Answer
Answer: b
10. Consider the following data. The pre order traversal of a binary tree is A, B, E, C, D. The in order
traversal of the same binary tree is B, E, A, D, C. The level order sequence for the binary tree is
_________
a) A, C, D, B, E
b) A, B, C, D, E
c) A, B, C, E, D
d) D, B, E, A, C
View Answer
Answer: b
data-structure-questions-answers-preorder-traversal-q10
11. Consider the following data and specify which one is Preorder Traversal Sequence, Inorder and
Postorder sequences.
S1: N, M, P, O, Q
S2: N, P, Q, O, M
S3: M, N, O, P, Q
View Answer
Answer: c
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Postorder Traversal”.
1. In postorder traversal of binary tree right subtree is traversed before visiting root.
a) True
b) False
View Answer
Answer: a
Explanation: Post-order method of traversing involves – i) Traverse left subtree in post-order, ii)
Traverse right subtree in post-order, iii) visit the root.
2. What is the possible number of binary trees that can be created with 3 nodes, giving the sequence N,
M, L when traversed in post-order.
a) 15
b) 3
c) 5
d) 8
View Answer
Answer: c
postorder-traversal-questions-answers-q2
3. The post-order traversal of a binary tree is O P Q R S T. Then possible pre-order traversal will be
________
a) T Q R S O P
b) T O Q R P S
c) T Q O P S R
d) T Q O S P R
View Answer
Answer: c
Explanation: The last, second last nodes visited in post-order traversal are root and it’s right child
respectively. Option T Q R S O P can’t be a pre-order traversal, because nodes O, P are visited after the
nodes Q, R, S. Option T O Q R P S, can’t be valid, because the pre-order sequence given in option T O Q R
P S and given post-order traversal creates a tree with node T as root and node O as left subtree. Option
T Q O P S R is valid. Option T Q O S P R is not valid as node P is visited after visiting node S.
4. A binary search tree contains values 7, 8, 13, 26, 35, 40, 70, 75. Which one of the following is a valid
post-order sequence of the tree provided the pre-order sequence as 35, 13, 7, 8, 26, 70, 40 and 75?
View Answer
Answer: d
Explanation: The binary tree contains values 7, 8, 13, 26, 35, 40, 70, 75. The given pre-order sequence is
35, 13, 7, 8, 26, 70, 40 and 75. So, the binary search tree formed is
postorder-traversal-questions-answers-q4
Thus post-order sequence for the tree is 8, 7, 26, 13, 40, 75, 70 and 35.
5. Which of the following pair’s traversals on a binary tree can build the tree uniquely?
View Answer
Answer: b
Explanation: A binary tree can uniquely be created by post-order and in-order traversals.
b) pre-order traversal
c) post-order traversal
d) in-order traversal
View Answer
Answer: a
Explanation: Every node in a full binary tree has either 0 or 2 children. A binary tree can be generated by
two traversals if one of them is in-order. But, we can generate a full binary tree using post-order and
pre-order traversals.
7. The maximum number of nodes in a tree for which post-order and pre-order traversals may be equal
is ______
a) 3
b) 1
c) 2
d) any number
View Answer
Answer: b
Explanation: The tree with only one node has post-order and pre-order traversals equal.
8. The steps for finding post-order traversal are traverse the right subtree, traverse the left subtree or
visit the current node.
a) True
b) False
View Answer
Answer: b
Explanation: Left subtree is traversed first in post-order traversal, then the right subtree is traversed and
then the output current node.
9. The pre-order and in-order are traversals of a binary tree are T M L N P O Q and L M N T O P Q. Which
of following is post-order traversal of the tree?
a) L N M O Q P T
b) N M O P O L T
c) L M N O P Q T
d) O P L M N Q T
View Answer
Answer: a
Explanation: The tree generated by using given pre-order and in-order traversal is
postorder-traversal-questions-answers-q9
Thus, L N M O Q P T will be the post-order traversal.
10. For a binary tree the first node visited in in-order and post-order traversal is same.
a) True
b) False
View Answer
Answer: b
postorder-traversal-questions-answers-q10
Its post-order traversal- 14 13 19 16. Here the first node visited is not same.
11. Find the postorder traversal of the binary tree shown below.
postorder-traversal-questions-answers-q11
a) P Q R S T U V W X
b) W R S Q P V T U X
c) S W T Q X U V R P
d) S T W U X V Q R P
View Answer
Answer: c
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Inorder Traversal”.
data-structure-questions-answers-inorder-traversal-q1
a) 6, 2, 5, 7, 11, 2, 5, 9, 4
b) 6, 5, 2, 11, 7, 4, 9, 5, 2
c) 2, 7, 2, 6, 5, 11, 5, 9, 4
d) 2, 7, 6, 5, 11, 2, 9, 5, 4
View Answer
Answer: a
data-structure-questions-answers-inorder-traversal-q1
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 11, 9, 6, 5, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
View Answer
Answer: b
a)
System.out.println(root.data);
inorder(root.left);
inorder(root.right);
}
b)
inorder(root.left);
System.out.println(root.data);
inorder(root.right);
c)
System.out.println(root.data);
inorder(root.right);
inorder(root.left);
d)
inorder(root.right);
inorder(root.left);
System.out.println(root.data);
}
View Answer
a)
queue.add(root);
while(!queue.isEmpty())
Node tempNode=queue.poll();
System.out.println("%d ",tempNode.data);
if(tempNode.left!=null)
queue.add(tempNode.left);
if(tempNode.right!=null)
queue.add(tempNode.right);
b)
queue.add(root);
while(!queue.isEmpty())
Node tempNode=queue.poll();
System.out.println("%d ",tempNode.data);
if(tempNode.left!=null)
queue.add(tempNode.right);
if(tempNode.right!=null)
queue.add(tempNode.left);
c)
queue.add(root);
while(!queue.isEmpty())
Node tempNode=queue.poll();
System.out.println("%d ",tempNode.data);
if(tempNode.right!=null)
queue.add(tempNode.left);
if(tempNode.left!=null)
queue.add(tempNode.right);
}
}
d)
queue.add(root);
while(!queue.isEmpty())
Node tempNode=queue.poll();
System.out.println("%d ",tempNode.data);
if(tempNode.right!=null)
queue.add(tempNode.left.left);
if(tempNode.left!=null)
queue.add(tempNode.right.right);
View Answer
5. What is the space complexity of the in-order traversal in the recursive fashion? (d is the tree depth
and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
View Answer
Answer: d
Explanation: In the worst case we have d stack frames in the recursive call, hence the complexity is O(d).
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
View Answer
Answer: b
Explanation: Since you have to go through all the nodes, the complexity becomes O(n).
7. Which of the following graph traversals closely imitates level order traversal of a binary tree?
d) Binary Search
View Answer
Answer: b
Explanation: Both level order tree traversal and breadth first graph traversal follow the principle that
visit your neighbors first and then move on to further nodes.
8. In a binary search tree, which of the following traversals would print the numbers in the ascending
order?
a) Level-order traversal
b) Pre-order traversal
c) Post-order traversal
d) In-order traversal
View Answer
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Binary Tree
Properties”.
1. The number of edges from the root to the node is called __________ of the tree.
a) Height
b) Depth
c) Length
d) Width
View Answer
Answer: b
Explanation: The number of edges from the root to the node is called depth of the tree.
2. The number of edges from the node to the deepest leaf is called _________ of the tree.
a) Height
b) Depth
c) Length
d) Width
View Answer
Answer: a
Explanation: The number of edges from the node to the deepest leaf is called height of the tree.
3. What is a full binary tree?
View Answer
Answer: a
Explanation: A full binary tree is a tree in which each node has exactly 0 or 2 children.
b) A binary tree, which is completely filled, with the possible exception of the bottom level, which is
filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the bottom level, which is
filled from left to right
View Answer
Answer: c
Explanation: A binary tree, which is completely filled, with the possible exception of the bottom level,
which is filled from left to right is called complete binary tree. A Tree in which each node has exactly
zero or two children is called full binary tree. A Tree in which the degree of each node is 2 except leaf
nodes is called perfect binary tree.
5. What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)
View Answer
Answer: d
Explanation: The nodes are either a part of left sub tree or the right sub tree, so we don’t have to
traverse all the nodes, this means the complexity is lesser than n, in the average case, assuming the
nodes are spread evenly, the time complexity becomes O(logn).
a) Hierarchical structure
b) Faster search
c) Router algorithms
View Answer
Answer: d
7. In a full binary tree if number of internal nodes is I, then number of leaves L are?
a) L = 2*I
b) L = I + 1
c) L = I – 1
d) L = 2*I – 1
View Answer
Answer: b
Explanation: Number of Leaf nodes in full binary tree is equal to 1 + Number of Internal Nodes i.e L = I +
1
8. In a full binary tree if number of internal nodes is I, then number of nodes N are?
a) N = 2*I
b) N = I + 1
c) N = I – 1
d) N = 2*I + 1
View Answer
Answer: d
9. In a full binary tree if there are L leaves, then total number of nodes N are?
a) N = 2*L
b) N = L + 1
c) N = L – 1
d) N = 2*L – 1
View Answer
Answer: d
a) Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k
b) Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes
c) Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log (N + 1))
d) Let T be a binary tree with N nodes. Then the number of levels is at least floor(log (N + 1))
View Answer
Answer: d
Explanation: In a binary tree, there are atmost 2k nodes in level k and 2k-1 total number of nodes.
Number of levels is at least ceil(log(N+1)).
11. Construct a binary tree by using postorder and inorder sequences given below.
Inorder: N, M, P, O, Q
Postorder: N, P, Q, O, M
a) data-structure-questions-answers-binary-tree-properties-q11a
b) data-structure-questions-answers-binary-tree-properties-q11b
c) data-structure-questions-answers-binary-tree-properties-q11c
d) data-structure-questions-answers-binary-tree-properties-q11d
View Answer
Answer: d
Explanation: Here,
Postorder Traversal: N, P, Q, O, M
Inorder Traversal: N, M, P, O, Q
Root node of tree is the last visiting node in Postorder traversal. Thus, Root Node = ‘M’.
data-structure-questions-answers-binary-tree-properties-q11e
The second last node in postorder traversal is O. Thus, node P becomes left child of node O and node Q
becomes right child of node Q. Thus, the final tree is:
data-structure-questions-answers-binary-tree-properties-q11d
12. Construct a binary search tree by using postorder sequence given below.
Postorder: 2, 4, 3, 7, 9, 8, 5.
a) data-structure-questions-answers-binary-tree-properties-q12a
b) data-structure-questions-answers-binary-tree-properties-q12b
c) data-structure-questions-answers-binary-tree-properties-q12c
d) data-structure-questions-answers-binary-tree-properties-q12d
View Answer
Answer: b
Inorder sequence is the ascending order of nodes in Binary search tree. Thus, Inorder sequence is 2, 3, 4,
5, 7, 8, 9. The tree constructed using Postorder and Inorder sequence is
13. Construct a binary tree using inorder and level order traversal given below.
Inorder Traversal: 3, 4, 2, 1, 5, 8, 9
a) data-structure-questions-answers-binary-tree-properties-q13a
b) data-structure-questions-answers-binary-tree-properties-q13b
c) data-structure-questions-answers-binary-tree-properties-q13c
d) data-structure-questions-answers-binary-tree-properties-q13d
View Answer
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Binary Search
Tree”.
c) The left and right sub-trees should also be binary search trees
Answer: d
Explanation: In order sequence of binary search trees will always give ascending order of elements.
Remaining all are true regarding binary search trees.
a)
return root;
return search(root.right,key);
else
return search(root.left,key);
b)
return root;
return search(root.left,key);
else
return search(root.right,key);
c)
return root;
return search(root.right,key);
else
return search(root.left,key);
}
d)
return root;
return search(root.right.right,key);
else
return search(root.left.left,key);
View Answer
3. What is the speciality about the inorder traversal of a binary search tree?
View Answer
func(root.left());
func(root.right());
System.out.println(root.data());
a) Preorder traversal
b) Inorder traversal
c) Postorder traversal
View Answer
System.out.println(root.data());
func(root.left());
func(root.right());
a) Preorder traversal
b) Inorder traversal
c) Postorder traversal
6. How will you find the minimum element in a binary search tree?
a)
while(root.left() != null)
root = root.left();
System.out.println(root.data());
b)
while(root != null)
root = root.left();
System.out.println(root.data());
c)
public void min(Tree root)
while(root.right() != null)
root = root.right();
System.out.println(root.data());
d)
while(root != null)
root = root.right();
System.out.println(root.data());
View Answer
7. How will you find the maximum element in a binary search tree?
a)
{
while(root.left() != null)
root = root.left();
System.out.println(root.data());
b)
while(root != null)
root = root.left();
System.out.println(root.data());
c)
while(root.right() != null)
root = root.right();
System.out.println(root.data());
}
d)
while(root != null)
root = root.right();
System.out.println(root.data());
View Answer
8. What are the worst case and average case complexities of a binary search tree?
a) O(n), O(n)
b) O(logn), O(logn)
c) O(logn), O(n)
d) O(n), O(logn)
View Answer
Answer: d
Explanation: Worst case arises when the tree is skewed(either to the left or right) in which case you
have to process all the nodes of the tree giving O(n) complexity, otherwise O(logn) as you process only
the left half or the right half of the tree.
9. Given that 2 elements are present in the tree, write a function to find the LCA(Least Common
Ancestor) of the 2 elements.
a)
public void lca(Tree root,int n1, int n2)
root = root.right();
root = root.left();
else break;
System.out.println(root.data());
b)
root = root.left();
root = root.right();
else break;
}
System.out.println(root.data());
c)
root = root.left();
root = root.right();
else break;
System.out.println(root.data());
d)
root = root.left.left();
else break;
System.out.println(root.data());
View Answer
10. What are the conditions for an optimal binary search tree and what is its advantage?
a) The tree should not be modified and you should know how often the keys are accessed, it improves
the lookup cost
b) You should know the frequency of access of the keys, improves the lookup time
c) The tree can be modified and you should know the number of elements in the tree before hand, it
improves the deletion time
d) The tree should be just modified and improves the lookup time
View Answer
Answer: a
Explanation: For an optimal binary search The tree should not be modified and we need to find how
often keys are accessed. Optimal binary search improves the lookup cost.
a) data-structure-questions-answers-binary-search-tree-q11a
b) data-structure-questions-answers-binary-search-tree-q11b
c) data-structure-questions-answers-binary-search-tree-q11c
d) data-structure-questions-answers-binary-search-tree-q11d
View Answer
Answer: c
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Balanced Binary Tree”.
1. What will be the height of a balanced full binary tree with 8 leaves?
a) 8
b) 5
c) 6
d) 4
View Answer
Answer: d
Explanation: A balanced full binary tree with l leaves has height h, where h = log2l + 1.
So, the height of a balanced full binary tree with 8 leaves = log28 + 1 = 3 + 1 = 4.
View Answer
Answer: c
Explanation: For a node in a binary tree, the difference between the heights of its left subtree and right
subtree is known as balance factor of the node.
3. Figure below is a balanced binary tree. If a node inserted as child of the node R, how many nodes will
become unbalanced?
balanced-binary-tree-questions-answers-q3
a) 2
b) 1
c) 3
d) 0
View Answer
Answer: b
Explanation: Only the node P will become unbalanced, with balance factor +2.
4. A binary tree is balanced if the difference between left and right subtree of every node is not more
than ____
a) 1
b) 3
c) 2
d) 0
View Answer
Answer: a
Explanation: In a balanced binary tree the heights of two subtrees of every node never differ by more
than 1.
5. Which of the following tree data structures is not a balanced binary tree?
a) AVL tree
b) Red-black tree
c) Splay tree
d) B-tree
View Answer
Answer: d
Explanation: All the tree data structures given in options are balanced, but B-tree can have more than
two children.
a)balanced-binary-tree-questions-answers-q6a
b) balanced-binary-tree-questions-answers-q6b
c) balanced-binary-tree-questions-answers-q6c
d)balanced-binary-tree-questions-answers-q6d
View Answer
Answer: b
Explanation: In Some tree diagrams, the root of tree has balance factor +2, so the tree is not balanced. If
every node in the tree is balanced, then it’s a balanced tree.
7. Balanced binary tree with n items allows the lookup of an item in ____ worst-case time.
a) O(log n)
b) O(nlog 2)
c) O(n)
d) O(1)
View Answer
Answer: a
Explanation: Searching an item in balanced binary is fast and worst-case time complexity of the search is
O(log n).
8. Which of the following data structures can be efficiently implemented using height balanced binary
search tree?
a) sets
b) priority queue
c) heap
View Answer
Answer: d
Explanation: Height-Balanced binary search tree can provide an efficient implementation of sets, priority
queues.
9. Two balanced binary trees are given with m and n elements respectively. They can be merged into a
balanced binary search tree in ____ time.
a) O(m+n)
b) O(mn)
c) O(m)
d) O(mlog n)
View Answer
Answer: a
Explanation: First we store the in-order traversals of both the trees in two separate arrays and then we
can merge these sorted sequences in O(m+n) time. And then we construct the balanced tree from this
final sorted array.
10. Which of the following is an advantage of balanced binary search tree, like AVL tree, compared to
binary heap?
View Answer
Answer: a
Explanation: Insertion and deletion, in both the binary heap and balanced binary search tree takes O(log
n). But searching in balanced binary search tree requires O(log n) while binary heap takes O(n).
Construction of balanced binary search tree takes O(nlog n) time while binary heap takes O(n).
a) True
b) False
View Answer
Answer: a
Explanation: AVL tree is more balanced than a Red-black tree because AVL tree has less height than Red-
black tree given that both trees have the same number of elements.
12. The figure shown below is a balanced binary tree. If node P is deleted, which of the following nodes
will get unbalanced?
balanced-binary-tree-questions-answers-q12
a) U
b) M
c) H
d) A
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Self
Balancing Binary Search Tree”.
1. Which of the following is not the self balancing binary search tree?
a) AVL Tree
b) 2-3-4 Tree
d) Splay Tree
View Answer
Answer: b
Explanation: 2-3-4 Tree is balanced search trees. But it is not a binary tree. So, it is not a self balancing
binary tree. AVL tree, Red-Black Tree and Splay tree are self balancing binary search tree.
2. The binary tree sort implemented using a self – balancing binary search tree takes ______ time is
worst case.
a) O(n log n)
b) O(n)
c) O(n2)
d) O(log n)
View Answer
Answer: a
Explanation: The worst case running time of the binary tree sort is O(n2). But, the worst case running
time can be improved to the O(n log n) using a self – balancing binary search tree.
3. An AVL tree is a self – balancing binary search tree, in which the heights of the two child sub trees of
any node differ by _________
a) At least one
b) At most one
c) Two
d) At most two
View Answer
Answer: b
Explanation: In an AVL tree, the difference between heights of the two child sub trees of any node is at
most one. If the height differs by more than one, AVL tree performs rotations to balance the tree.
a) B-tree
View Answer
Answer: d
Explanation: Associative arrays can be implemented using a self balancing binary search tree as the
worst-case time performance of self – balancing binary search trees is O(log n).
5. Self – balancing binary search trees have a much better average-case time complexity than hash
tables.
a) True
b) False
View Answer
Answer: b
Explanation: For lookup, insertion and deletion hash table take O(1) time in average-case while self –
balancing binary search trees takes O(log n). Therefore, hash tables perform better in average-case.
a) 2-3 tree
c) AA tree
d) Treap
View Answer
Answer: c
Explanation: An AA tree, which is a variation of red-black tree, is a self – balancing binary search tree. 2-
3 is B-tree of order 3 and Treat is a randomized binary search tree. A threaded binary tree is not a
balanced tree.
a) Priority queue
b) Hash table
c) Heap sort
View Answer
Answer: a
Explanation: Self-balancing binary search trees can be used to construct and maintain ordered lists, to
achieve the optimal worst case performance. So, self – balancing binary search tree can be used to
implement a priority queue, which is ordered list.
8. In which of the following self – balancing binary search tree the recently accessed element can be
accessed quickly?
a) AVL tree
b) AA tree
c) Splay tree
View Answer
Answer: c
Explanation: In a Splay tree, the recently accessed element can be accessed quickly. In Splay tree, the
frequently accessed nodes are moved towards the root so they are quick to access again.
9. The minimum height of self balancing binary search tree with n nodes is _____
a) log2(n)
b) n
c) 2n + 1
d) 2n – 1
View Answer
Answer: a
Explanation: Self – balancing binary trees adjust the height by performing transformations on the tree at
key insertion times, in order to keep the height proportional to log2(n).
10. Binary tree sort implemented using a self balancing binary search tree takes O(n log n) time in the
worst case but still it is slower than merge sort.
a) True
b) False
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Randomized Binary Search Tree”.
a) Treap
d) AVL Tree
View Answer
Answer: d
Explanation: Treap, also known as random binary search tree, Random binary tree and Uniform
spanning tree are all random tree. Random tree is a tree formed by a random process of addition and
deletion of nodes. AVL tree is a self – balanced binary search tree.
a) Stochastic Process
b) Branching Process
c) Diffusion Process
d) Aggregation Process
View Answer
Answer: a
Explanation: The randomized binary search tree is formed by the stochastic process. The stochastic
process or also called random process is a mathematical tool or object including random variables.
3. How many randomized binary search trees can be formed by the numbers (1, 3, 2)?
a) 2
b) 3
c) 6
d) 5
View Answer
Answer: d
Explanation: As there are 3 numbers (1, 3, 2) so total of 6 combinations can be formed using three
numbers but Since (2, 1, 3) and (2, 3, 1) are same so in total there are 5 randomized binary search tree
that can be formed.
a) log n
b) n!
c) n2
d) 2 log n + O(1)
View Answer
Answer: d
Explanation: The expected value of depth of a node that is for a node a, the expected value of length of
path from root to node a is found to be at most 2 log n + O(1).
5. What is the longest length path for a node x in random binary search tree for the insertion process?
a) log x
b) x2
c) x!
d) 4.311 log x
View Answer
Answer: d
Explanation: Although it is difficult to find the length of the longest path in randomized binary search
tree, but it has been found that the longest length is around 4.311 log x.
6. What is the range of β in finding the length of the longest path in a randomized binary search tree?
a) (-1, 0)
b) (1, 0)
c) (0, 5)
d) (0, 1)
View Answer
Answer: d
Explanation: The longest path in a randomized binary search tree, but it has been found that the longest
length is around 4.311 log x for node x. This is also equal to 1/β log x where β lies in the range (0, 1).
a) n + 1
b) (n + 1)/3
c) (n + 1)/2
d) n + 3
View Answer
Answer: b
Explanation: In a random mathematical model, the expected value of number of leaves in a randomized
binary search tree is found to be exactly (n + 1)/3 using probability.
a) True
b) False
View Answer
Answer: a
Explanation Treap is a type of data structure which is a combination of binary tree and heap. It is an
example of a randomized binary search tree. It stores value in pairs.
View Answer
Answer: d
Explanation: Catalan number is a sequence of natural number that is used in counting problem. Hence it
is found that the selecting off a tree uniformly at random is reciprocal of Catalan number.
a) True
b) False
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “AA
Tree”.
a) Colors
b) Levels
c) Node size
d) Heaps
View Answer
Answer: b
Explanation: AA Trees are implemented using levels instead of colors to overcome the disadvantages of
Red-Black trees.
Answer: a
Explanation: A horizontal link is a connection between a node and a child of equal levels.
View Answer
Answer: a
Explanation: A left horizontal link is removed by right rotation. A right horizontal link is removed by left
rotation.
View Answer
Answer: b
Explanation: A skew removes a left horizontal link by right rotation and a split removes a right horizontal
link by left rotation.
a) True
b) False
View Answer
Answer: b
a) 7
b) 5
c) 2
d) 3
View Answer
Answer: c
Explanation: An AA-Tree needs to consider only two shapes unlike a red-black tree which needs to
consider seven shapes of transformation.
7. What is the prime condition of AA-tree which makes it simpler than a red-black tree?
View Answer
Answer: a
Explanation: The prime condition of AA-Tree is that only the right children can be red to eliminate
possible restructuring cases.
b) B+ Tree
c) AVL Tree
d) Red-Black Tree
View Answer
Answer: d
Explanation: AA- Tree is a small variation of Red-Black tree. AA-Trees overcome the complexity faced in
performing insertion and deletion in Red-Black Trees.
a) O(N)
b) O(log N)
c) O( N log N)
d) O(N2)
View Answer
Answer: b
Explanation: The worst case analysis of an AA-Tree is mathematically found to be O(log N).
a) True
b) False
View Answer
Answer: a
Explanation: AA- trees make more rotations than a red-black tree since only two shapes are considered
for an AA-Tree whereas seven shapes are considered in Red-Black trees.
11. Who is the inventor of AA-Tree?
a) Arne Anderson
b) Daniel Sleator
c) Rudolf Bayer
View Answer
Answer: a
Explanation: AA-tree is invented by Arne Anderson. Daniel Sleator invented Splay Tree. Rudolf Bayer
invented a Red-Black tree. Jon Louis Bentley invented K-d tree.
12. What should be the condition for the level of a left node?
View Answer
Answer: c
Explanation: The level of a left node should be strictly less than that of its parent. The level of a right
node is less than or equal to that of its parent.
13. Of the following rules that are followed by an AA-tree, which of the following is incorrect?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: d
Explanation: In an AA-Tree, both left and right children can be present. The only condition is that only
right children can be red.
14. aa-tree-questions-answers-q14
a) left rotation
b) right rotation
c) insertion
d) deletion
View Answer
Answer: b
Explanation: B is initially the right child of X. It is then rotated right side and now, B is the left child of P.
15. Comparing the speed of execution of Red-Black trees and AA-trees, which one has the faster search
time?
a) AA-tree
b) Red-Black tree
d) It depends
View Answer
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “AVL Tree”.
View Answer
Answer: a
b) to save memory
d) to simplify storing
View Answer
Answer: a
Explanation: In real world dealing with random values is often not possible, the probability that u are
dealing with non random values(like sequential) leads to mostly skew trees, which leads to worst case.
hence we make height balance by rotations.
i.data-structure-questions-answers-avl-tree-q3
ii.data-structure-questions-answers-avl-tree-q3a
a) only i
b) only i and ii
c) only ii
View Answer
Answer: b
Explanation: The property of AVL tree is it is height balanced tree with difference of atmost 1 between
left and right subtrees. All AVL trees are binary search tree.
a) p
b) log(p)
c) log(p)/2
d) p⁄2
View Answer
Answer: b
Explanation: Consider height of tree to be ‘he’, then number of nodes which totals to p can be written in
terms of height as N(he)=N(he-1)+1+N(he-2). since N(he) which is p can be written in terms of height as
the beside recurrence relation which on solving gives N(he)= O(logp) as worst case height.
5. 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
View Answer
Answer: a
Explanation: It is interesting to note that after insertion, only the path from that point to node or only
that subtrees are imbalanced interms of height.
6. Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without
performing any rotations?
b) find the median of the set of elements given, make it as root and construct the tree
View Answer
Answer: b
Explanation: Sort the given input, find the median element among them, make it as root and construct
left and right subtrees with elements lesser and greater than the median element recursively. this
ensures the subtrees differ only by height 1.
7. What maximum difference in heights between the leafs of a AVL tree is possible?
c) 0 or 1
d) atmost 1
View Answer
Answer: a
Explanation: At every level we can form a tree with difference in height between subtrees to be atmost
1 and so there can be log(n) such levels since height of AVL tree is log(n).
return 0
left_tree_height = avl(left_of_root)
if(left_tree_height== -1)
return left_tree_height
right_tree_height= avl(right_of_root)
if(right_tree_height==-1)
return right_tree_height
Does the above code can check if a binary search tree is an AVL tree?
a) yes
b) no
View Answer
Answer: a
Explanation: The condition to check the height difference between left and right subtrees is missing. if
(absolute(left_tree_height – right_tree_height)>1) must be added.
9. 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.
avltreenode w =x-left
x-left=w-right
w-right=x
x-height=max(Height(x-left),Height(x-right))+1
w-height=max(missing)+1
return w
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: a
Explanation: In the code we are trying to make the left rotation and so we need to find maximum of
those two values.
b) AVL tree store balance factor in every node which costs space
View Answer
Answer: b
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Threaded Binary
Tree”.
View Answer
Answer: d
Explanation: This type of tree traversal will not use stack or queue.
a) there are many pointers which are null and thus useless
c) complexity in implementing
d) improper traversals
View Answer
Answer: a
Explanation: As there are majority of pointers with null value going wasted we use threaded binary
trees.
b) leftchild_pointer, left_tag
View Answer
Answer: a
Explanation: It contains additional 2 pointers over normal binary tree node structure.
4. What are null nodes filled with in a threaded binary tree?
a) inorder predecessor for left node and inorder successor for right node information
b) right node with inorder predecessor and left node with inorder successor information
View Answer
Answer: a
Explanation: If preorder or postorder is used then the respective predecessor and successor info is
stored.
5. Which of the following tree traversals work if the null left pointer pointing to the predecessor and null
right pointer pointing to the successor in a binary tree?
b) inorder
c) postorder
d) preorder
View Answer
Answer: a
Explanation: In threaded binary trees, the null left pointer points to the predecessor and the right null
pointer point to the successor. In threaded binary trees, we can use in-order, preorder and postorder
traversals to visit every node in the tree.
a) when both left, right nodes are having null pointers and only right node is null pointer respectively
Answer: a
Explanation: They are properties of double and single threaded binary trees respectively.
7. What is wrong with below code for inorder traversal of inorder threaded binary tree:
inordertraversal(threadedtreenode root):
threadedtreenode q = inorderpredecessor(root)
while(q!=root):
q=inorderpredecessor(q)
print q.data
b) code is correct
View Answer
Answer: a
Explanation: Property of inorder threaded binary tree is left node with inorder predecessor and right
node with inorder successor information are stored.
data-structure-questions-answers-threaded-binary-tree-q8
b) nothing inefficient
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Weight Balanced
Tree”.
View Answer
Answer: a
Explanation: Unlike AVL and redblack trees which uses height and color as book keeping information,
weight balanced trees use the size of subtrees.
b) heaps
c) sorting
d) storing strings
View Answer
Answer: a
Explanation: They are a type of self balancing trees which are mostly used in storing key-value pairs,
which is mostly used in functional programming languages. they are very useful to maintain big set of
ordered objects.
3. A node of the weight balanced tree has
b) key, value
c) key, size
d) key
View Answer
Answer: a
Explanation: As a weight balanced tree stores height of the subtrees, we need to use size as an
additional attribute to every node. also value(for mappings) may be an optional attribute.
leaf – zero
is this true?
a) true
b) false
View Answer
Answer: a
Explanation: Size of a node k is size[k] = size[k.left] + 1 + size[k.right] and based on this the weight will be
given as weight[k] = size[k] + 1.
5. What is the condition for a tree to be weight balanced. where a is factor and n is a node?
Answer: a
Explantion: The tree is said to be a-balanced if the condition is satisfied. and ‘a’ value will be determined
during tree formation. large value of ‘a’ is more effective.
6. What are the operations that can be performed on weight balanced tree?
a) all basic operations and set intersection, set union and subset test
View Answer
Answer: a
Explanation: The speciality of a weight balanced tree is a part from basic operations we can perform
collective operations like set intersection, which helps in rapid prototyping in functional programming
languages.
7. Consider a weight balanced tree such that, the number of nodes in the left sub tree is at least half and
at most twice the number of nodes in the right sub tree. The maximum possible height (number of
nodes on the path from the root to the farthest leaf) of such a tree on k nodes can be described as
a) log2 n
b) log4/3 n
c) log3 n
d) log3/2 n
View Answer
Answer: d
Explanation: Total number of nodes can be described by the recurrence T(n) = T((n-1)/3)) + T(2(n-1)/3) +
1 T(1) = 1. height of the tree will be H(n) = H(2/3(n-1)) + 1, H(1). drawing a recurrence tree and the cost
at each level is 1 and the height will be log(3/2)n.
8. Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert?
if (k == null)
k = rotateWithRightChild (k)
k = rotateWithLeftChild (k)
a) when x>t. element Rotate-with-left-child should take place and vice versa
View Answer
9. What does the below definations convey?
i. A binary tree is balanced if for every node it is gonna hold that the number of inner nodes in the left
subtree and the number of inner nodes in the right subtree differ by at most 1.
ii. A binary tree is balanced if for any two leaves the difference of the depth is at most 1.
View Answer
Answer: a
Explanation: They are the definations of weight and height balanceness. height balanced trees wont
convey weight balanceness but opposite can be true.
10. Elements in a tree can be indexed by its position under the ordering of the keys and the ordinal
position of an element can be determined, both with good efficiency.
a) true
b) false
View Answer
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Splay Tree”.
Answer: a
b) any sequence of j operations starting from an empty tree with h nodes atmost, takes O(jlogh) time
complexity
View Answer
Answer: b
Explanation: This is a property of splay tree that ensures faster access. we push the most recently used
nodes to top which leads to faster access to recently used values.
a) easier to program
b) space efficiency
d) quick searching
View Answer
Answer: c
Explanation: Whenever you insert an element or remove or read an element that will be pushed or
stored at the top which facilitates easier access or recently used stuff.
a) true
b) false
View Answer
Answer: a
Explanation: We go with amortized time complexity when we feel that not all operations are worst and
some can be efficiently done. in splay trees not all splay operations will lead to O(logn) worst case
complexity.
View Answer
Answer: b
Explanation: Splay trees mainly work using splay operations. wheneve we insert, delete and search for a
node we splay the respective nodes to root. we have zig-zag and zig-zig operations.
a) cache Implementation
b) networks
c) send values
d) receive values
View Answer
Answer: a
Explanation: Splay trees can be used for faster access to recently accessed items and hence used for
cache implementations.
7. When we have red-black trees and AVL trees that can perform most of operations in logarithmic
times, then what is the need for splay trees?
b) In real time it is estimated that 80% access is only to 20% data, hence most used ones must be easily
available
d) they are just another type of self balancing binary search trees
View Answer
Answer: b
Explanation: May be the stats showing 80-20% may be not accurate, but in real time that is the widely
spread scenario seen. If you are into this type of situation, you must choose implementing splay trees.
data-structure-questions-answers-splay-tree-q8
a) true
b) false
View Answer
Answer: a
Explanation: There is a zig-zag and right operation(zig) which gives the right hand side tree. refer splay
operations for insertion in splay tree.
Tree_node function(Tree_node x)
Tree_node y = x.left;
x.left = y.right;
y.right = x;
return y;
c) zig-zag operation
d) zig-zig operation
View Answer
Answer: a
Explanation: When a right rotation is done the parent of the rotating node becomes it’s right node and
it’s child becomes it’s left child.
a) height of a splay tree can be linear when accessing elements in non decreasing order.
c) no significant disadvantage
d) splay tree performs unnecessary splay when a node is only being read
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Top
Tree”.
b) Greedy
c) Backtracking
d) Branch
View Answer
Answer: a
Explanation: Top tree is a type of data structure which is based on unrooted dynamic binary tree and is
used to solve path related problems. It allows an algorithm called divide and conquer.
2. For how many vertices in a set, is top tree defined for underlying tree?
a) 3
b) 4
c) 5
d) 2
View Answer
Answer: d
Explanation: Top tree is defined for a set having a maximum of 2 vertices for its underlying tree. Those
sets having at maximum 2 vertices is called External Boundary Vertices.
a) 2
b) 3
c) 6
d) 1
View Answer
Answer: a
Explanation: There are at least 2 edges present in path cluster. Cluster in data structure is defined as the
subtree that is connect having maximum of 2 vertices known as Boundary Vertices.
4. How many edges does a leaf cluster contain?
a) 0
b) 1
c) 2
d) 3
View Answer
Answer: a
Explanation: If a cluster has no edges and contains only one vertex known as boundary vertex then, it is
known as leaf cluster. So a leaf cluster doesn’t contain any edges. It is also known as Point cluster.
a) 0
b) 1
c) 2
d) 4
View Answer
Answer: b
Explanation: A cluster containing only single edge is known as Edge cluster. So there are in total 1 edge
present in edge cluster. Cluster in data structure is defined as the subtree that is connect having
maximum of 2 vertices known as Boundary Vertices.
6. Which data structure is used to maintain a dynamic forest using a link or cut operation?
a) Top Tree
b) Array
c) Linked List
d) Stack
View Answer
Answer: a
Explanation: Top tree data structure is used to maintain a dynamic forest using link or cut operations.
Top tree is a type of data structure which is based on unrooted dynamic binary tree and is used to solve
path related problems.
7. If A ꓵ B (A and B are two clusters) is a singleton set then it is a Merge able cluster.
a) True
b) False
View Answer
Answer: a
Explanation: If A ꓵ B is a singleton set where A and B are two clusters, that is there are only one node
that is common between the clusters then they are known as Merge able cluster.
8. Is Top tree used for maintaining Dynamic set of trees called forest.
a) True
b) False
View Answer
Answer: a
Explanation: Top tree data structure is used to maintain a dynamic forest using link or cut operations.
Top tree is a type of data structure which is based on unrooted dynamic binary tree and is used to solve
path related problems.
a) O (n)
b) O (n2)
c) O (log n)
d) O (n!)
View Answer
Answer: a
Explanation: Generally, trees have weight on its edges. Also there is one to one correspondence of the
edges with the top trees. Therefore, top trees can be initialized in O (n) time.
10. How many top trees are there in a tree with single vertex?
a) 0
b) 1
c) 2
d) 3
View Answer
Answer: a
Explanation: Tree having a single vertex has no clusters of tree present in the structure. Therefore, there
are empty top trees in a tree having a single vertex. Trees with one node are single node.
a) Nodes as Cluster
b) Leaves as Edges
View Answer
Answer: d
Explanation: Top tree can be considered as a binary tree if the nodes form a cluster, leaves act as an
edge and the root of the top tree acts as a tree itself. Then the top tree is called binary tree.
12. Which of the dynamic operations are used in Top Tree data structure implementation?
a) Link
b) Cut
c) Expose
View Answer
Answer: d
Explanation: Link returns a single tree having different vertices from top trees. Cut removes the edge
from the top tree. Expose is used to implement queries on top trees. Hence all of the options are used
as dynamic operations.
13. Which of the following are used as an internal operation in Top tree?
a) Merge
b) Cut
c) Expose
d) Link
View Answer
Answer: a
Explanation: Link returns a single tree having different vertices from top trees. Cut removes the edge
from the top tree. Expose is used to implement queries on top trees. While merge is an internal
operation used to merge two clusters and return as a parent cluster.
14. What is the time complexity for maintaining a dynamic set of weighted trees?
a) O (n)
b) O (n2)
c) O (log n)
d) O (n!)
View Answer
Answer: c
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Graph”.
View Answer
Answer: a
Explanation: In a walk if the vertices are distinct it is called a path, whereas if the edges are distinct it is
called a trail.
data-structure-questions-answers-graph-q2
a) B and E
b) C and D
c) A and E
d) C and B
View Answer
Answer: d
data-structure-questions-answers-graph-q3
a) G is a complete graph
b) G is not a connected graph
View Answer
Answer: c
a) (n*(n+1))/2
b) (n*(n-1))/2
c) n
View Answer
Answer: b
Explanation: Number of ways in which every vertex can be connected to each other is nC2.
data-structure-questions-answers-graph-q5
a) True
b) False
View Answer
Answer: a
Explanation: In a regular graph, degrees of all the vertices are equal. In the given graph the degree of
every vertex is 3.
6. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.
a) True
b) False
View Answer
Answer: b
Explanation: The sum of the degrees of the vertices is equal to twice the number of edges.
a) 15
b) 3
c) 1
d) 11
View Answer
Answer: b
Explanation: By euler’s formula the relation between vertices(n), edges(q) and regions(r) is given by n-
q+r=2.
8. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________
a) (n*n-n-2*m)/2
b) (n*n+n+2*m)/2
c) (n*n-n-2*m)/2
d) (n*n-n+2*m)/2
View Answer
Answer: a
Explanation: The union of G and G’ would be a complete graph so, the number of edges in G’= number
of edges in the complete form of G(nC2)-edges in G(m).
9. Which of the following properties does a simple graph not hold?
a) Must be connected
b) Must be unweighted
View Answer
Answer: a
10. What is the maximum number of edges in a bipartite graph having 10 vertices?
a) 24
b) 21
c) 25
d) 16
View Answer
Answer: c
Explanation: Let one set have n vertices another set would contain 10-n vertices.
Total number of edges would be n*(10-n), differentiating with respect to n, would yield the answer.
View Answer
Answer: b
12. For a given graph G having v vertices and e edges which is connected and has no cycles, which of the
following statements is true?
a) v=e
b) v = e+1
c) v + 1 = e
d) v = e-1
View Answer
Answer: b
Explanation: For any connected graph with no cycles the equation holds true.
13. For which of the following combinations of the degrees of vertices would the connected graph be
eulerian?
a) 1,2,3
b) 2,3,4
c) 2,4,5
d) 1,3,5
View Answer
Answer: a
Explanation: A graph is eulerian if either all of its vertices are even or if only two of its vertices are odd.
14. A graph with all vertices having equal degree is known as a __________
a) Multi Graph
b) Regular Graph
c) Simple Graph
d) Complete Graph
View Answer
Answer: b
b) Incidence Matrix
d) No way to represent
View Answer
Answer: c
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Dijkstra’s Algorithm”.
c) Network flow
d) Sorting
View Answer
Answer: b
Explanation: Dijkstra’s Algorithm is used for solving single source shortest path problems. In this
algorithm, a single node is fixed as a source node and shortest paths from this node to all other nodes in
graph is found.
2. Which of the following is the most commonly used data structure for implementing Dijkstra’s
Algorithm?
b) Stack
c) Circular queue
View Answer
a) O(N)
b) O(N3)
c) O(N2)
d) O(logN)
View Answer
Answer: c
Explanation: Time complexity of Dijkstra’s algorithm is O(N2) because of the use of doubly nested for
loops. It depends on how the table is manipulated.
c) Unweighted graphs
View Answer
Answer: b
Explanation: Dijkstra’s Algorithm cannot be applied on graphs having negative weight function because
calculation of cost to reach a destination node from the source node becomes complex.
5. What is the pseudo code to compute the shortest path in Dijkstra’s algorithm?
a)
if(!T[w].Known)
T[w].path=v; }
b)
if(T[w].Known)
T[w].path=v; }
c)
if(!T[w].Known)
T[w].path=v; }
d)
if(T[w].Known)
if(T[v].Dist + C(v,w) < T[w].Dist) {
Increase(T[w].Dist to T[v].Dist);
T[w].path=v; }
View Answer
a) 1
b) 3
c) 2
d) 4
View Answer
Answer: b
Explanation: The number of priority queue operations involved is 3. They are insert, extract-min and
decrease key.
7. How many times the insert and extract min operations are invoked per vertex?
a) 1
b) 2
c) 3
d) 0
View Answer
Answer: a
Explanation: Insert and extract min operations are invoked only once per vertex because each vertex is
added only once to the set and each edge in the adjacency list is examined only once during the course
of algorithm.
8. The maximum number of times the decrease key operation performed in Dijkstra’s algorithm will be
equal to ___________
c) Number of vertices – 1
d) Number of edges – 1
View Answer
Answer: b
Explanation: If the total number of edges in all adjacency list is E, then there will be a total of E number
of iterations, hence there will be a total of at most E decrease key operations.
9. What is running time of Dijkstra’s algorithm using Binary min- heap method?
a) O(V)
b) O(VlogV)
c) O(E)
d) O(ElogV)
View Answer
Answer: d
Explanation: Time required to build a binary min heap is O(V). Each decrease key operation takes
O(logV) and there are still at most E such operations. Hence total running time is O(ElogV).
10. The running time of Bellmann Ford algorithm is lower than that of Dijkstra’s Algorithm.
a) True
b) False
View Answer
Answer: b
Explanation: The number of iterations involved in Bellmann Ford Algorithm is more than that of
Dijkstra’s Algorithm.
11. Dijkstra’s Algorithm run on a weighted, directed graph G={V,E} with non-negative weight function w
and source s, terminates with d[u]=delta(s,u) for all vertices u in V.
a) True
b) False
View Answer
Answer: a
Explanation: The equality d[u]=delta(s,u) holds good when vertex u is added to set S and this equality is
maintained thereafter by the upper bound property.
2. S=0
3. Q=V[G]
4. While Q != 0
5. Do u=extract-min(Q)
8. Do relax(u,v,w)
View Answer
Answer: b
Explanation: In the normal execution of Dijkstra’s Algorithm, the while loop gets executed V times. The
change in the while loop statement causes it to execute only V – 1 times.
dijkstras-algorithm-questions-answers-q13
a) 8
b) 9
c) 4
d) 6
View Answer
Answer: d
Explanation: The minimum cost to reach f vertex from b vertex is 6 by having vertices g and e as
intermediates.
b to g, cost is 1
g to e, cost is 4
e to f, cost is 1
dijkstras-algorithm-questions-answers-q14
Identify the shortest path having minimum cost to reach vertex E if A is the source vertex
a) a-b-e
b) a-c-e
c) a-c-d-e
d) a-c-d-b-e
View Answer
Answer: b
Explanation: The minimum cost required to travel from vertex A to E is via vertex C
A to C, cost= 3
C to E, cost= 2
a) Greedy algorithm
c) Back tracking
d) Dynamic programming
View Answer
Answer: a
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Huffman Code”.
1. Which of the following algorithms is the best approach for solving Huffman codes?
a) exhaustive search
b) greedy algorithm
View Answer
Answer: b
Explanation: Greedy algorithm is the best approach for solving the Huffman codes problem since it
greedily searches for an optimal solution.
2. How many printable characters does the ASCII character set consists of?
a) 120
b) 128
c) 100
d) 98
View Answer
Answer: c
Explanation: Out of 128 characters in an ASCII set, roughly, only 100 characters are printable while the
rest are non-printable.
a) first
b) seventh
c) eighth
d) tenth
View Answer
Answer: c
Explanation: In an ASCII character set, seven bits are reserved for character representation while the
eighth bit is a parity bit.
4. How many bits are needed for standard encoding if the size of the character set is X?
a) log X
b) X+1
c) 2X
d) X2
View Answer
Answer: a
Explanation: If the size of the character set is X, then [log X] bits are needed for representation in a
standard encoding.
5. The code length does not depend on the frequency of occurrence of characters.
a) true
b) false
View Answer
Answer: b
Explanation: The code length depends on the frequency of occurrence of characters. The more frequent
the character occurs, the less is the length of the code.
a) roots
b) leaves
View Answer
Answer: b
Explanation: In Huffman encoding, data is always stored at the leaves of a tree inorder to compute the
codeword effectively.
7. From the following given tree, what is the code word for the character ‘a’?
huffman-code-questions-answers-q7
a) 011
b) 010
c) 100
d) 101
View Answer
Answer: a
Explanation: By recording the path of the node from root to leaf, the code word for character ‘a’ is
found to be 011.
8. From the following given tree, what is the computed codeword for ‘c’?
huffman-code-questions-answers-q8
a) 111
b) 101
c) 110
d) 011
View Answer
Answer: c
Explanation: By recording the path of the node from root to leaf, assigning left branch as 0 and right
branch as 1, the codeword for c is 110.
9. What will be the cost of the code if character ci is at depth di and occurs at frequency fi?
a) cifi
b) ∫cifi
c) ∑fidi
d) fidi
View Answer
Answer: c
Explanation: If character ci is at depth di and occurs at frequency fi, the cost of the codeword obtained is
∑fidi.
a) true
b) false
View Answer
Answer: a
Explanation: An optimal tree will always have the property that all nodes are either leaves or have two
children. Otherwise, nodes with one child could move up a level.
11. The type of encoding where no character code is the prefix of another character code is called?
a) optimal encoding
b) prefix encoding
c) frequency encoding
d) trie encoding
View Answer
Answer: b
Explanation: Even if the character codes are of different lengths, the encoding where no character code
is the prefix of another character code is called prefix encoding.
a) O(C)
b) O(log C)
c) O(C log C)
d) O( N log C)
View Answer
Answer: c
Explanation: If we maintain the trees in a priority queue, ordered by weight, then the running time is
given by O(C log C).
13. What is the running time of the Huffman algorithm, if its implementation of the priority queue is
done using linked lists?
a) O(C)
b) O(log C)
c) O(C log C)
d) O(C2)
View Answer
Answer: d
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on
“Hamming Code”.
a) Hamming(7, 4) code
b) Hamming(8, 4) code
c) Hamming(6, 3) code
d) Hamming(5, 7) code
View Answer
Answer: a
Explanation: The most common hamming codes generalize to form hamming(7, 4) code. It encodes four
bits of data into seven bits by adding three parity bits.
2. What is the minimal Hamming distance between any two correct codewords?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: c
Explanation: Since we use a generalized version of Hamming(7, 4) code, the minimal hamming distance
is 3. It cannot correct burst errors.
a) Error correction
b) Encryption only
c) Decryption
d) Bit stuffing
View Answer
Answer: a
Explanation: Hamming codes are used for the purpose of error detection and correction. It is also used
for channel encoding and decoding. They are linear-error correcting codes.
4. Hamming codes can be used for both single-bit error and burst error detection and correction.
a) True
b) False
View Answer
Answer: b
Explanation: Hamming bits are suitable only for single-bit error detection and correction and two bit
error detection. It is very unlikely to detect burst errors.
5. Who invented Hamming codes?
a) Richard Hamming
b) Ross Hamming
c) Shannon
d) Huffman
View Answer
Answer: a
Explanation: Richard W. Hamming invented hamming codes in Bell Telephone Laboratory to minimize
the errors in punched card readers. Huffman invented huffman codes. Shannon invented Shannon-
Fanno codes.
a) 2r
b) 2r-1
c) 2r-1-1
d) 2r+1
View Answer
Answer: b
Explanation: Hamming codes are a class of binary linear codes, hence r>=2. For a hamming(7, 4) code,
the block length ‘n’ is 2r-1 where r is the parity bit. Here, r=3.
a) 2r-1
b) 2r-r+1
c) 2r-r-1
d) 2r+1-r
View Answer
Answer: c
Explanation: Hamming codes are a class of binary linear codes, hence r>=2. For a hamming(7,4) code,
the message length ‘k’ is 2r-r-1 where r is the parity bit. Here, r=3.
a) 1-[r/(2r-1)]
b) 1-(r/2r)
c) 1+(r/2r)
d) r/2r+1
View Answer
Answer: a
Explanation: Rate of a hamming code is message length divided by block length (i.e.) 2r-r-1/2r-1 = 1-
[r/(2r-1)]. It is the highest rate for a minimum distance of three.
View Answer
Answer: b
Explanation: A two-out-of-five code consists of three 0s and two 1s. Hence, it contains ten possible
combinations to represent digits from 0-9.
10. Including a parity bit along with the data surely detects the errors.
a) true
b) false
View Answer
Answer: b
Explanation: If error has occurred in a data string, parity will change inorder to indicate errors. However,
if the error occurs in parity bit, the error goes undetected.
11. ________ is the mechanism of sending data bits multiple times to ensure consistency.
a) Repetition
b) Duplication
c) Mirroring
d) Redundancy
View Answer
Answer: a
Explanation: Repeating data bits multiple times is done to ensure consistency. If the data bit to be sent is
a 1, a n=3 repetition code will send 111. If the bits are not the same, an error has occurred.
a) SEDDEC
b) SEDDED
c) SECDED
d) SECDEC
View Answer
Answer: c
Explanation: An Extended Hamming code is also called as SECDED (Single Error Correction Double Error
Detection). The most popular codes are (72, 64) code and (127,120) code.
13. What is the code rate of a repetition Hamming code (3, 1)?
a) 1
b) 3
c) 1/3
d) 1.3
View Answer
Answer: c
Explanation: The code rate of a repetition hamming code is the second number divided by the first
number. Here, it is 1/3.
14. For a hamming code of parity bit m=8, what is the total bits and data bits?
a) (255, 247)
b) (127, 119)
c) (31, 26)
d) (0, 8)
View Answer
Answer: a
15. What is the rate of the hamming code of parity bit m=8?
a) 0.94
b) 0.92
c) 0.90
d) 0.97
View Answer
Answer: d
MCQs on Linked list with answers
ANSWER: B
2. A linear collection of data elements where the linear node is given by means of pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) None
ANSWER: A
3. Which of the following operations is performed more efficiently by doubly linked list than by singly
linked list?
ANSWER: A
4. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a
head and tail pointer. Given the representation, which of the following operation can be implemented in
O(1) time?
a) I and II
b) I and III
d) I,II and IV
ANSWER: C
5. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a
head pointer only. Given the representation, which of the following operation can be implemented in
O(1) time?
a) I and II
b) I and III
d) I,II and IV
ANSWER: B
6. Consider an implementation of unsorted doubly linked list. Suppose it has its representation with a
head pointer and tail pointer. Given the representation, which of the following operation can be
implemented in O(1) time?
a) I and II
b) I and III
d) I,II,III and IV
ANSWER: D
7. Consider an implementation of unsorted doubly linked list. Suppose it has its representation with a
head pointer only. Given the representation, which of the following operation can be implemented in
O(1) time?
i) Insertion at the front of the linked list
a) I and II
b) I and III
d) I,II,III and IV
ANSWER: B
8. Consider an implementation of unsorted circular linked list. Suppose it has its representation with a
head pointer only. Given the representation, which of the following operation can be implemented in
O(1) time?
b) I and III
d) None
ANSWER: D
9. Consider an implementation of unsorted circular doubly linked list. Suppose it has its representation
with a head pointer only. Given the representation, which of the following operation can be
implemented in O(1) time?
a) I and II
b) I and III
c) I, II and III
d) I,II,III and IV
10. In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
ANSWER: C
11. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ (n)
d) θ (1)
View Answer / Hide Answer
ANSWER: C
12. What would be the asymptotic time complexity to add an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) None
ANSWER: B
13. What would be the asymptotic time complexity to find an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) None
ANSWER: B
14. What would be the asymptotic time complexity to insert an element at the second position in the
linked list?
a) O(1)
b) O(n)
c) O(n2)
d) None
ANSWER: A
15. The concatenation of two list can performed in O(1) time. Which of the following variation of linked
list can be used?
ANSWER: C
struct node
int data;
NODE *ptr;
a) ptr=(NODE*)malloc(sizeof(NODE));
b) ptr=(NODE*)malloc(NODE);
c) ptr=(NODE*)malloc(sizeof(NODE*));
d) ptr=(NODE)malloc(sizeof(NODE));
ANSWER: A
17. A variant of linked list in which last node of the list points to the first node of the list is?
ANSWER: C
d) None
ANSWER: C
19. What kind of linked list is best to answer question like “What is the item at position n?”
ANSWER: D
20. A variation of linked list is circular linked list, in which the last node in the list points to first node of
the list. One problem with this type of list is?
a) It waste memory space since the pointer head already points to the first node and thus the list node
does not need to point to the first node.
c) It is difficult to traverse the list as the pointer of the last node is now not NULL
d) All of above
ANSWER: C
21. A variant of the linked list in which none of the node contains NULL pointer is?
d) None
ANSWER: C
b) Two pointer
c) Three pointer
d) None
ANSWER: B
23. Which of the following statements about linked list data structure is/are TRUE?
a) Addition and deletion of an item to/ from the linked list require modification of the existing pointers
b) The linked list pointers do not provide an efficient way to search an item in the linked list
d) The linked list data structure provides an efficient way to find kth element in the list
ANSWER: B
24. Linked lists are not suitable to for the implementation of?
a) Insertion sort
b) Radix sort
c) Polynomial manipulation
d) Binary search
ANSWER: D
25. In worst case, the number of comparison need to search a singly linked list of length n for a given
element is
a) log n
b) n/2
c) log2n-1
d) n
ANSWER: D
a) 2h-1 -1
b) 2h+1 -1
c) 2h +1
d) 2h-1 +1
ANSWER: B
2. The no of external nodes in a full binary tree with n internal nodes is?
a) n
b) n+1
c) 2n
d) 2n + 1
ANSWER: B
3. The difference between the external path length and the internal path length of a binary tree with n
internal nodes is?
a) 1
b) n
c) n + 1
d) 2n
ANSWER: D
4. Suppose a binary tree is constructed with n nodes, such that each node has exactly either zero or two
children. The maximum height of the tree will be?
a) (n+1)/2
b) (n-1)/2
c) n/2 -1
d) (n+1)/2 -1
ANSWER: B
5. Which of the following statement about binary tree is CORRECT?
ANSWER: C
6. Suppose we have numbers between 1 and 1000 in a binary search tree and want to search for the
number 363. Which of the following sequence could not be the sequence of the node examined?
ANSWER: C
7. In full binary search tree every internal node has exactly two children. If there are 100 leaf nodes in
the tree, how many internal nodes are there in the tree?
a) 25
b) 49
c) 99
d) 101
ANSWER: C
8. Which type of traversal of binary search tree outputs the value in sorted order?
a) Pre-order
b) In-order
c) Post-order
d) None
9. Suppose a complete binary tree has height h>0. The minimum no of leaf nodes possible in term of h
is?
a) 2h -1
b) 2h -1 + 1
c) 2h -1
d) 2h +1
ANSWER: C
b) 5
c) 6
d) 7
ANSWER: A, D
11. If a node having two children is to be deleted from binary search tree, it is replaced by its
a) In-order predecessor
b) In-order successor
c) Pre-order predecessor
d) None
ANSWER: B
12. A binary search tree is formed from the sequence 6, 9, 1, 2, 7, 14, 12, 3, 8, 18. The minimum number
of nodes required to be added in to this tree to form an extended binary tree is?
a) 3
b) 6
c) 8
d) 11
ANSWER: D
13. In a full binary tree, every internal node has exactly two children. A full binary tree with 2n+1 nodes
contains
a) n leaf node
b) n internal nodes
ANSWER: B
14. the run time for traversing all the nodes of a binary search tree with n nodes and printing them in an
order is
a) O(nlg(n))
b) O(n)
c) O(√n)
d) O(log(n))
ANSWER: B
15. When a binary tree is converted in to an extended binary tree, all the nodes of a binary tree in the
external node becomes
a) Internal nodes
b) External nodes
c) Root nodes
d) None
ANSWER: A
16. If n numbers are to be sorted in ascending order in O(nlogn) time, which of the following tree can be
used
a) Binary tree
c) Max-heap
d) Min-heap
ANSWER: D
17. If n elements are sorted in a binary search tree. What would be the asymptotic complexity to search
a key in the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: C
18. If n elements are sorted in a balanced binary search tree. What would be the asymptotic complexity
to search a key in the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: B
a) 2h+1
b) 2h
c) 2h -1
d) 2h-1
a) 2h+1 -1
b) 2h
c) 2h -1
d) 2h -1
ANSWER: A
21. A threaded binary tree is a binary tree in which every node that does not have right child has a
thread to its
a) Pre-order successor
b) In-order successor
c) In-order predecessor
d) Post-order successor
22. In which of the following tree, parent node has a key value greater than or equal to the key value of
both of its children?
d) Max-heap
ANSWER: D
23. A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is
a) log2n
b) n-1
c) n
d) 2n
View Answer / Hide Answer
ANSWER: B
24. A binary search tree is generated by inserting in order the following integers:
The number of the node in the left sub-tree and right sub-tree of the root, respectively, is
a) (4, 7)
b) (7, 4)
c) (8, 3)
d) (3, 8)
ANSWER: B
A. ? A = 01
B = 111
C = 110
D = 10
B. ? A=0
B = 111
C = 11
D = 101
C. ? A=0
B = 11
C = 10
D = 111
D. ? A=0
B = 111
C = 110
D = 10
A. X expand data by using fewer bits to encode more frequently occuring characters
B. ? compress data by using more bits to encode more frequently occuring characters
C. :-) compress data by using fewer bits to encode more frequently occuring characters
D. ? compress data by using fewer bits to encode fewer frequently occuring characters
D. X broadband systems
4. A Huffman encoder takes a set of characters with fixed length and produces a set of characters of
A. X constant length
B. X fixed length
C. X random length
D. ? variable length
5. A Huffman code: A = 1, B = 000, C = 001, D = 01
P(A) = 0.4, P(B) = 0.1, P(C) = 0.2, P(D) = 0.3
The average number of bits per letter is
B. X 2.0 bit
C. X 2.1 bit
D. ? 8.0 bit
B. ? square functions
C. ? sinus functions
D. ? lines
B. ? adding pixels
C. ? removing noise
D. ? adding noise
A. X bright
C. ? equal
A. ? 2000:1
B. X 2:1
C. :-) 200:1
D. ? 20:1
A. ? Wavelets
B. X Dolby
C. X Fourier transform
D. X
1.
The null left pointer pointing to predecessor and null right pointer pointing to successor. how many
types of threaded tree are possible with this convention?
A.) preorder
C.) inorder
D.) postorder
3.
A.) when both left, right nodes are having null pointers and only right node is null pointer respectively
when both left, right nodes are having null pointers and only right node is null pointer respectively
4.
What is a threaded binary tree traversal?
5.
What is wrong with below code for inorder traversal of inorder threaded binary tree:
inordertraversal(threadedtreenode root):
threadedtreenode q = inorderpredecessor(root)
while(q!=root):
q=inorderpredecessor(q)
print q.data
6.
A.) there are many pointers which are null and thus useless
there are many pointers which are null and thus useless
7.
A.) inorder predecessor for left node and inorder successor for right node information
B.) right node with inorder predecessor and left node with inorder successor information
View Answer
Ans : A
Explanation: In a walk if the vertices are distinct it is called a path, whereas if the edges are distinct it is
called a trail.
2. What is the maximum number of possible non zero values in an adjacency matrix of a simple graph
with n vertices?
A. (n*(n-1))/2
B. (n*(n+1))/2
C. n*(n-1)
D. n*(n+1)
View Answer
Ans : C
Explanation: Out of n*n possible values for a simple graph the diagonal values will always be zero.
3. Which of the following is an advantage of adjacency list representation over adjacency matrix
representation of a graph?
C. Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
View Answer
Ans : D
Explanation: No explanation.
4.A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
A. 15
B. 3
C. 1
D. 11
View Answer
Ans : B
Explanation: By euler’s formula the relation between vertices(n), edges(q) and regions(r) is given by n-
q+r=2.
5.On which of the following statements does the time complexity of checking if an edge exists between
two particular vertices is not, depends?
A. Depends on the number of edges
View Answer
Ans : C
Explanation:To check if there is an edge between to vertices i and j, it is enough to see if the value of
A[i][j] is 1 or 0, here A is the adjacency matrix.
6. The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in
decreasing order. Which of the following sequences can not be the degree sequence of any graph?
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1
A. I and II
B. III and IV
C. IV only
D. II and IV
View Answer
Ans : D
Explanation: No explanation
7. What is the maximum number of edges in a bipartite graph having 10 vertices?
A. 24
B. 21
C. 25
D. 16
View Answer
Ans : C
Explanation: Let one set have n vertices another set would contain 10-n vertices.
Total number of edges would be n*(10-n), differentiating with respect to n, would yield the answer.
8. Possible number of labelled simple Directed, Pseudo and Multigarphs exist having 2 vertices?
A. 3, Infinite, 4
B. 4, 3, Infinite
C. 4, Infinite, infinite
D. 4, Infinite, Infinite
View Answer
Ans : D
Explanation: MultiGraphs and PseudoGraphs may have infinite number of edges, while 4 possible simple
graphs exist.
9.The most efficient algorithm for finding the number of connected components in an undirected graph
on n vertices and m edges has time complexity.
(A) \theta(n)
(B) \theta(m)
(C) \theta(m + n)
(D) \theta(mn)
A. A
B. B
C. C
D. D
View Answer
Ans : C
Explanation: Connected components can be found in O(m + n) using Tarjan's algorithm. Once we have
connected components, we can count them.
10. What is time complexity to check if a string(length S1) is a substring of another string(length S2)
stored in a Directed Acyclic Word Graph, given S2 is greater than S1?
A. O(S1)
B. O(S2)
C. O(S1+S2)
D. O(1)
View Answer
Ans : A
11. What is the number of edges present in a complete graph having n vertices?
A. (n*(n+1))/2
B. (n*(n-1))/2
C. n
View Answer
Ans : B
Explanation: Number of ways in which every vertex can be connected to each other is nC2.
12. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.
A. True
B. False
View Answer
Ans : B
Explanation: The sum of the degrees of the vertices is equal to twice the number of edges.
13. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph
G'(Complement of G) is ___________
A. (n*n-n-2*m)/2
B. (n*n+n+2*m)/2
C. (n*n-n-2*m)/2
D. (n*n-n+2*m)/2
View Answer
Ans : A
Explanation: The union of G and G’ would be a complete graph so, the number of edges in G’= number
of edges in the complete form of G(nC2)-edges in G(m).
14. Which of the following properties does a simple graph not hold?
A. Must be connected
B. Must be unweighted
View Answer
Ans : A
View Answer
Ans : B
16. For a given graph G having v vertices and e edges which is connected and has no cycles, which of the
following statements is true?
A. v=e
B. v = e+1
C. v + 1 = e
View Answer
Ans : B
Explanation: For any connected graph with no cycles the equation holds true.
17. for which of the following combinations of the degrees of vertices would the connected graph be
eulerian?
A. 1,2,3
B. 2,3,4
C. 2,4,5
D. 1,3,5
View Answer
Ans : A
Explanation: A graph is eulerian if either all of its vertices are even or if only two of its vertices are odd.
18. A graph with all vertices having equal degree is known as a __________
A. Multi Graph
B. Regular Graph
C. Simple Graph
D. Complete Graph
View Answer
Ans : B
Explanation: The given statement is the definition of regular graphs.Explanation: The given statement is
the definition of regular graphs.
B. Incidence Matrix
View Answer
Ans :C
Explanation: The 3 listed methods can be used, the choice depends on the ease of use.
20. The time complexity to calculate the number of edges in a graph whose information in stored in
form of an adjacency matrix is ____________
A. O(V)
B. O(E2)
C. O(E)
D. O(V2)
View Answer
Ans : D
1. The no of external nodes in a full binary tree with n internal nodes is?
A. n
B. n+1
C. 2n
D. 2n + 1
View Answer
Ans : B
Explanation: The no of external nodes in a full binary tree with n internal nodes is n+1.
View Answer
Ans : E
Explanation: A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in
which every node other than the leaves has two children. A complete binary tree is a binary tree in
which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. A)
is incorrect.
View Answer
Ans : D
Explanation: A Binary Tree can have 0, 1, 2 children
A. Hierarchical structure
B. Faster search
C. Router algorithms
View Answer
Ans : D
5.The difference between the external path length and the internal path length of a binary tree with n
internal nodes is?
A. 1
B. n
C. n + 1
D. 2n
View Answer
Ans : D
6. In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves
in such a tree with n internal nodes is:
A. nk
B. (n – 1) k+ 1
C. n( k – 1) + 1
D. n(k – 1)
View Answer
Ans : C
Explanation: For an k-ary tree where each node has k children or no children, following relation holds L =
(k-1)*n + 1 Where L is the number of leaf nodes and n is the number of internal nodes.
View Answer
Ans : A
Explanation: Height of Height of a binary tree is MAX( Height of left Subtree, Height of right subtree)+1.
B. networks
C. send values
D. receive values
View Answer
Ans : A
Explanation: Splay trees can be used for faster access to recently accessed items and hence used for
cache implementations.
9. Suppose a complete binary tree has height h>0. The minimum no of leaf nodes possible in term of h
is?
A. 2h -1
B. 2h -1 + 1
C. 2h -1
D. 2h +1
View Answer
Ans : C
Explanation: Suppose a complete binary tree has height h>0. The minimum no of leaf nodes possible in
term of h is 2h -1.
10. A weight-balanced tree is a binary tree in which for each node. The number of nodes in the left sub
tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible
height (number of nodes on the path from the root to the farthest leaf) of such a tree on n nodes is best
described by which of the following?
A. log2 n
B. log4/3 n
C. log3 n
D. log3/2 n
View Answer
Ans : D
1. What does the following function do for a given Linked List with first node as head?
if(head == NULL)
return;
fun1(head->next);
View Answer
2. A linear collection of data elements where the linear node is given by means of pointer is called?
A. linked list
B. node list
C. primitive list
D. None of these
View Answer
Ans : A
Explanation: A linear collection of data elements where the linear node is given by means of pointer is
called linked list.
3. What is the time complexity to count the number of elements in the linked list?
A. O(1)
B. O(n)
C. O(logn)
View Answer
Ans : B
Explanation: To count the number of elements, you have to traverse through the entire list, hence
complexity is O(n).
4. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?
A. O(1)
B. O(n)
C. θ (n)
D. θ (1)
View Answer
Ans : C
Explanation: No Explanation.
5. What is the output of following function for start pointing to first node of following linked list? 1->2-
>3->4->5->6
if(start == NULL)
return;
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
A. 1 4 6 6 4 1
B. 1 3 5 1 3 5
C. 1 2 3 5
D. 1 3 5 5 3 1
View Answer
Ans : D
Explanation:fun() prints alternate nodes of the given Linked List, first from head to end, and then from
end to head. If Linked List has even number of nodes, then skips the last node.
int var = 0;
while(temp != null)
if(temp.getData() == data)
return var;
}
var = var+1;
temp = temp.getNext();
return Integer.MIN_VALUE;
C. Find and return the position of the given element in the list
View Answer
Ans : C
A. Insertion sort
B. Radix sort
C. Polynomial manipulation
D. Binary search
View Answer
Ans : D
Explanation: Linked lists are not suitable to for the implementation of Binary search.
8. In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is
A. log 2 n
B. n/2
C. log 2 n – 1
D. n
View Answer
Ans : D
Explanation: In the worst case, the element to be searched has to be compared with all elements of
linked list.
View Answer
Ans : D
Explanation: Linked lists can be used to implement all of the above mentioned applications.
10. In circular linked list, insertion of node requires modification of?
A. One pointer
B. Two pointer
C. Three pointer
D. None
View Answer
Ans : B
11. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a
head pointer only.
Given the representation, which of the following operation can be implemented in O(1) time?
A. I and II
B. I and III
C. I, II and III
D. I, II and IV
View Answer
Ans : B
Explanation: None.
12. In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?
A. Pointer to character
B. Pointer to integer
C. Pointer to node
D. Node
View Answer
Ans : C
Explanation: None.
13. What would be the asymptotic time complexity to find an element in the linked list?
A. O(1)
B. O(n)
C. O(n2)
View Answer
Ans : B
Explanation: None.
14. The concatenation of two list can performed in O(1) time. Which of the following variation of linked
list can be used?
View Answer
Ans : C
Explanation: None.
15. Consider the following definition in c programming language.Which of the following c code is used to
create new node?
struct node
int data;
NODE *ptr;
A. ptr = (NODE*)malloc(sizeof(NODE));
B. ptr = (NODE*)malloc(NODE);
C. ptr = (NODE*)malloc(sizeof(NODE*));
D. ptr = (NODE)malloc(sizeof(NODE));
View Answer
Ans :A
16. What kind of linked list is best to answer question like "What is the item at position n"?
View Answer
Ans : D
Explanation: None.
17. Linked lists are not suitable to for the implementation of?
A. Insertion sort
B. Radix sort
C. Polynomial manipulation
D. Binary search
View Answer
Ans : D
A. Dynamic
B. Static
C. Compile time
View Answer
Ans : A
A. Data
B. Link
Ans : B
Explanation: None.
A. Computational Time
B. Space Utilization
View Answer
Ans : C
This set of solved MCQ on tree and graph in data structure includes multiple-choice questions on the
introduction of trees, definitions, binary tree, tree traversal, various operations of a binary tree, and
extended binary tree.
A. sorting
B. merging
C. inserting
D. traversal
A. Direct graph
B. Digraph
C. Dir-graph
D. Digraph
A. Threaded trees
B. Pointer trees
C. Special trees
4) Graph G is ………….. if for any pair u, v of nodes in G there is a path from u to v or path from v to u.
A. Literally connected
B. Widely Connected
C. Unliterally connected
D. Literally connected
A. End nodes
B. Terminal nodes
C. Final nodes
D. Last nodes
A. free graph
B. no cycle graph
C. non-cycle graph
D. circular graph
7) Trees are said ………. if they are similar and have the same contents at corresponding nodes.
A. Duplicate
B. Carbon copy
C. Replica
D. Copies
A. A tree graph
B. Free tree
C. A tree d
9) Every node N in a binary tree T except the root has a unique parent called the ……… of N.
A. Antecedents
B. Predecessor
C. Forerunner
D. Precursor
D. both b and c
Read Also: Interview Questions on Stack and Queue in Data Structure set-2
C. Two-dimensional arrays
D. Three-dimensional arrays
A. Endpoints of e
B. Adjacent nodes
C. Neighbors
A. Overflow
B. Underflow
C. Empty
D. Full
14) A binary tree whose every node has either zero or two children is called …….
A. 4
B. 2
C. 3
D. 5
A. Dn = n log2n
B. Dn= n log2n+1
C. Dn = log2n
D. Dn = log2n+1
A. Exterior node
B. Outside node
C. Outer node
D. External node
A. Interior node
B. Domestic node
C. Internal node
D. Inner node
A. Root
B. Leaf
C. Child
D. Branch
Answers:
1) D. traversal
2) D. Digraph
3) A. Threaded trees
4) C. Unliterally connected
5) B. Terminal nodes
6) A. free graph
7) D. Copies
9) B. Predecessor
13) C. Empty
15) C. 3
16) D. Dn = log2n+1
20) B. Leaf
Question: 1
Ans: C
Linear Array
Question: 2
(A) 2
(B) 3
(C) 4
Ans: B
Question: 3
Ans: A
Complete graph
Question: 4
(C) Sink
Ans: C
Sink
Question: 5
A graph is a tree if and only if graph is
(C) Planar
Ans: B
Contains no cycles
1. From a complete graph, by removing maximum _______________ edges, we can construct a spanning tree.
a. e-n+1
b. n-e+1
c. n+e-1
d. e-n-1
Answer: (a).e-n+1
a. n
b. n(n - 1)
c. 1
d. 0
Answer: (c).1
a. n
b. n+1
c. n-1
d. 2n
Answer: (a).n
5. What will be the running-time of Dijkstra's single source shortest path algorithm, if the graph G(V,E) is stored i
heap is used −
a. Ο(|V|2)
d. None of these
a. 2n - 1
b. n
c. n+1
d. n-1
Answer: (d).n - 1
7. If the data collection is in sorted form and equally distributed then the run time complexity of interpolation sear
a. Ο(n)
b. Ο(1)
c. Ο(log n)
8. A directed graph is ………………. if there is a path from each vertex to every other vertex in the digraph.
a. Weakly connected
b. Strongly Connected
c. Tightly Connected
d. Linearly Connected
iii) A graph is said to be complete if there is no edge between every pair of vertices.
ii) A graph is said to be complete if there is an edge between every pair of vertices.
a. True, True
b. False, True
c. False, False
d. True, False
Answer: (a).
a. Partite
b. Bipartite
c. Rooted
d. Bisects
Answer: (b).Bipartite
12. A graph is a collection of nodes, called ………. And line segments called arcs or ……….. that connect pair of
a. vertices, edges
b. edges, vertices
c. vertices, paths
13. A ……….. is a graph that has weights of costs associated with its edges.
a. Network
b. Weighted graph
c. Both A and B
14. A …………… is an acyclic digraph, which has only one node with indegree 0, and other nodes have in-degree
a. Directed tree
b. Undirected tree
c. Dis-joint tree
a. endpoints of e
b. adjacent nodes
c. neighbors
d. all of above
a. a tree graph
b. free tree
c. a tree
d. All of above
View Answer Report Discuss Too Difficult! Search Google
d. both b and c
a. isolated
b. complete
c. finite
d. strongly connected
Answer: (b).complete
a. Direct graph
b. Bigraph
c. Dir-graph
d. Digraph
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).Digraph
20. Graph G is .............. if for any pair u, v of nodes in G there is a path from u to v or path from v to u.
a. Leterally connected
b. Widely Connected
c. Unliterally connected
d. Literally connected
Answer: (c).
a. free graph
b. no cycle graph
d. circular graph
d. both b and c
23. Let G = (V, E) be any connected undirected edge-weighted graph. The weights of the edges in E are positive
following statements:
I. Minimum Spanning Tree of G is always unique.
II. Shortest path between any two vertices of G is always unique.
Which of the above statements is/are necessarily true?
a. I only
b. II only
c. both I and II
d. neither I and II
24. Let A be an adjacency matrix of a graph G. The ij th entry in the matrix Ak , gives
25. For an undirected graph with n vertices and e edges, the sum of the degree of each vertex is equal to
a. 2n
b. (2n-1)/2
c. 2e
d. 4n
Answer: (c).2e
26. An undirected graph G with n vertices and e edges is represented by adjacency list. What is the time required
components?
a. O (n)
b. O (e)
c. O (e+n)
d. O (e-n)
27. A graph with n vertices will definitely have a parallel edge or self loop if the total number of edges are
a. more than n
b. more than n
28. The maximum degree of any vertex in a simple graph with n vertices is
a. n–1
b. n+1
c. 2n–1
d. n
Answer: (a).n–1
29. The data structure required for Breadth First Traversal on a graph is
a. queue
b. stack
c. array
d. tree
Answer: (a).queue
30. In Breadth First Search of Graph, which of the following data structure is used?
a. Stack
b. Queue
c. Linked List
Answer: (b).
a. ne
b. 2n
c. 2e
d. e^n
Answer: (c).2e
d. None of these
a. n*(n-2)
b. n*(n-1)
c. n*(n-1)/2
d. n*(n-1)*(n-2)
Answer: (c).n*(n-1)/2
a. Adjacency tree
c. Adjacency graph
d. Adjacency queue
36. The spanning tree of connected graph with 10 vertices contains ..............
a. 9 edges
b. 11 edges
c. 10 edges
d. 9 vertices
37. If locality is a concern, you can use ................ to traverse the graph.
38. Which of the following algorithms solves the all-pair shortest path problem?
a. Floyd's algorithm
b. Prim's algorithm
c. Dijkstra's algorithm
d. Warshall's algorithm
39. The minimum number of colors needed to color a graph having n (>3) vertices and 2 edges is
a. 1
b. 2
c. 3
d. 4
Answer: (b).2
40. Which of the following is useful in traversing a given graph by breadth first search?
a. set
b. List
c. stacks
d. Queue
Answer: (d).
a. n
b. n+1
c. n-1
Answer: (a).n
a. nd
b. n+d
c. nd/2
d. maximum of n,d
Answer: (c).nd/2
b. C and D
c. A and E
d. C and B
44. For the given graph(G), which of the following statements is true?
a. G is a complete graph
a. True
b. False
c. May be
d. Can't say
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).True
46. In the following DAG find out the number of required Stacks in order to represent it in a Graph Structured Stac
a. 1
b. 2
c. 3
d. 4
Answer: (c).3
48. In the given graph which edge should be removed to make it a Bipartite Graph?
a. A-C
b. B-E
c. C-D
d. D-E
Answer: (a).A-C
b. AEDCB
c. EDCBA
d. ADECB
Answer: (a).ABCED
50. What is the number of words that can be formed from the given Directed Acyclic Word Graph?
a. 2
b. 4
c. 12
d. 7
Answer: (b).
a. BATS
b. BOATS
c. BOT
Answer: (a).BATS
53. What is the number of edges present in a complete graph having n vertices?
a. (n*(n+1))/2
b. (n*(n-1))/2
c. n
Answer: (b).(n*(n-1))/2
54. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
55. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
a. 15
b. 3
c. 1
d. 11
Answer: (b).3
56. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph G'(Complement of G
a. (n*n-n-2*m)/2
b. (n*n+n+2*m)/2
c. (n*n-n-2*m)/2
d. (n*n-n+2*m)/2
Answer: (c).(n*n-n-2*m)/2
57. Which of the following properties does a simple graph not hold?
a. Must be connected
b. Must be unweighted
58. What is the maximum number of edges in a bipartite graph having 10 vertices?
a. 24
b. 21
c. 25
d. 16
Answer: (c).25
60. For a given graph G having v vertices and e edges which is connected and has no cycles, which of the followi
a. v=e
b. v = e+1
c. v+1=e
Answer: (b).
a. 1,2,3
b. 2,3,4
c. 2,4,5
d. 1,3,5
Answer: (a).1,2,3
62. A graph with all vertices having equal degree is known as a __________
a. Multi Graph
b. Regular Graph
c. Simple Graph
d. Complete Graph
b. Incidence Matrix
64. The number of elements in the adjacency matrix of a graph having 7 vertices is __________
a. 7
b. 14
c. 36
d. 49
Answer: (d).49
65. What would be the number of zeros in the adjacency matrix of the given graph?
a. 10
b. 6
c. 16
d. 0
Answer: (b).6
a. False
b. True
c. May be
d. Can't say
Answer: (a).False
67. The time complexity to calculate the number of edges in a graph whose information in stored in form of an adj
a. O(V)
b. O(E^2)
c. O€
d. O(V^2)
Answer: (d).O(V^2)
68. For the adjacency matrix of a directed graph the row sum is the _________ degree and the column sum is the
a. in, out
b. out, in
c. in, total
d. total, out
Answer: (b).out, in
69. What is the maximum number of possible non zero values in an adjacency matrix of a simple graph with n ver
a. (n*(n-1))/2
b. (n*(n+1))/2
c. n*(n-1)
d. n*(n+1)
Answer: (c).n*(n-1)
70. On which of the following statements does the time complexity of checking if an edge exists between two part
a. 2, 3
b. 3, 2
c. 2, 2
d. 3, 3
Answer: (a).2, 3
73. Given an adjacency matrix A = [ [0, 1, 1], [1, 0, 1], [1, 1, 0] ], how many ways are there in which a vertex can w
a. 2
b. 4
c. 6
d. 8
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).6
74. If A[x+3][y+5] represents an adjacency matrix, which of these could be the value of x and y.
a. x=5, y=3
b. x=3, y=5
c. x=3, y=3
d. x=5, y=5
75. Two directed graphs(G and H) are isomorphic if and only if A=PBP-1, where P and A are adjacency matrices
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
76. Given the following program, what will be the 3rd number that’d get printed in the output sequence for the give
#include <bits/stdc++.h>
int cur=0;
int G[10][10];
bool visited[10];
deque <int> q;
int main()
int num=0;
int n;
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>G[i][j];
for(int i=0;i<n;i++)
visited[i]=false;
fun(n);
return 0;
}
void fun(int n)
cout<<cur<<" ";
visited[cur]=true;
q.push_back(cur);
do
for(int j=0;j<n;j++)
q.push_back(j);
cout<<j<<" ";
visited[j]=true;
q.pop_front();
if(!q.empty())
cur=q.front();
}while(!q.empty());
}
Input Sequence:-
0 1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 1
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 1 1
0 0 0 0 1 0 1 0 0
1 0 1 0 0 0 1 0 0
a. 2
b. 6
c. 8
d. 4
77. For which type of graph, the given program would run infinitely? The Input would be in the form of an adjacenc
(1<n<10).
#include <bits/stdc++.h>
int G[10][10];
int main()
int num=0;
int n;
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>G[i][j];
fun(n);
return 0;
void fun(int n)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(G[i][j]==1)
j--;
}
78. Given the following adjacency matrix of a graph(G) determine the number of components in the G.
[0 1 1 0 0 0],
[1 0 1 0 0 0],
[1 1 0 0 0 0],
[0 0 0 0 1 0],
[0 0 0 1 0 0],
[0 0 0 0 0 0].
a. 1
b. 2
c. 3
d. 4
Answer: (c).3
79. Incidence matrix and Adjacency matrix of a graph will always have same dimensions?
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
80. The column sum in an incidence matrix for a simple graph is __________
c. equal to 2
Answer: (c).
82. The column sum in an incidence matrix for a directed graph having no self loop is __________
a. 0
b. 1
c. 2
Answer: (a).0
83. Time complexity to check if an edge exists between two vertices would be ___________
a. O(V*V)
b. O(V+E)
c. O(1)
d. O(E)
Answer: (d).O(E)
84. The graphs G1 and G2 with their incidences matrices given are Isomorphic.
e1 e2 e3 e4 e5 e6
v1 1 0 0 0 0 0
v2 1 1 0 0 0 1
v3 0 1 1 0 1 0
v4 0 0 1 1 0 0
v5 0 0 0 1 1 1
e1 e2 e3 e4 e5 e6
v1 0 0 1 0 0 0
v2 1 0 1 0 1 0
v3 1 1 0 1 0 0
v4 0 1 0 0 0 1
v5 0 0 0 1 1 1
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
85. If a connected Graph (G) contains n vertices what would be the rank of its incidence matrix?
a. n-1
Answer: (a).n-1
a. Undirected Graph
b. Directed Graph
d. Regular Graph
87. If a Graph Structured Stack contains {1,2,3,4} {1,5,3,4} {1,6,7,4} and {8,9,7,4}, what would be the source and s
c. Source – 1, 8 Sink – 4
a. Bogo Sort
b. Tomita’s Algorithm
c. Todd–Coxeter algorithm
89. If in a DAG N sink vertices and M source vertices exists, then the number of possible stacks in the Graph Stru
come out to be N*M.
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
90. Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edge
a. O(E)
b. O(V*V)
c. O(E+V)
d. O(V)
Answer: (c).
91. For some sparse graph an adjacency list is more space eff
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
92. Time complexity to find if there is an edge between 2 particular vertices is _________
a. O(V)
b. O(E)
c. O(1)
d. O(V+E)
Answer: (a).O(V)
93. For the given conditions, which of the following is in the correct order of increasing space requirement?
i) Undirected, no weight
a. ii iii i iv
b. i iii ii iv
c. iv iii i ii
d. i ii iii iv
94. Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edge
a. O(V)
b. O(E*E)
c. O(E)
d. O(E+V)
Answer: (c).O(E)
95. Complete the given snippet of code for the adjacency list representation of a weighted directed graph.
class neighbor
____ next;
}
class vertex
string name;
_____ adjlist;
vertex adjlists[101];
a. vertex, vertex
b. neighbor, vertex
c. neighbor, neighbor
d. vertex, neighbor
a. Dense graph
b. Sparse graph
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
98. What would be the time complexity of the following function which adds an edge between two vertices i and j,
graph having V vertices?
vector<int> adjacent[15] ;
vector<int> weight[15];
adjacent[a].push_back(i);
adjacent[b].push_back(j);
weight[a].push_back(weigh);
weight[b].push_back(weigh);
a. O(1)
b. O(V)
c. O(V*V)
d. O(log V)
a. 1
b. 2
c. 3
d. 4
Answer: (b).2
100. Number of vertices with odd degrees in a graph having a eulerian walk is ________
a. 0
b. Can’t be predicted
c. 2
d. either 0 or 2
Answer: (d).
a. 1
b. 2
c. 3
d. 4
Answer: (b).2
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
103. What is the number of vertices of degree 2 in a path graph having n vertices,here n>2.
a. n-2
b. n
c. 2
d. 0
Answer: (a).n-2
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
105. What would the time complexity to check if an undirected graph with V vertices and E edges is Bipartite or no
a. O(E*E)
b. O(V*V)
c. O(E)
d. O(V)
Answer: (b).O(V*V)
106. Dijkstra’s Algorithm will work for both negative and positive weights?
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
107. A graph having an edge from each vertex to every other vertex is called a ___________
a. Tightly Connected
b. Strongly Connected
c. Weakly Connected
d. Loosely Connected
108. What is the number of unlabeled simple directed graph that can be made with 1 or 2 vertices?
a. 2
b. 4
c. 5
d. 9
Answer: (b).4
109. Floyd Warshall Algorithm used to solve the shortest path problem has a time complexity of __________
a. O(V*V)
b. O(V*V*V)
c. O(E*V)
d. O(E*E)
Answer: (b).O(V*V*V)
a. True
b. False
c. May be
d. Can't say
Answer: (b).
112. What is the maximum possible number of edges in a directed graph with no self loops having 8 vertices?
a. 28
b. 64
c. 256
d. 56
Answer: (d).56
113. What would be the value of the distance matrix, after the execution of the given code?
#include <bits/stdc++.h>
};
int distance[V][V], i, j, k;
distance[i][j] = graph[i][j];
return 0;
a)
{
};
b)
};
c)
};
a. a
b. b
c. c
d. d
114. What is the maximum number of edges present in a simple directed graph with 7 vertices if there exists no cy
a. 21
b. 7
c. 6
d. 49
Answer: (c).6
115. Every Directed Acyclic Graph has at least one sink vertex.
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
116. With V(greater than 1) vertices, how many edges at most can a Directed Acyclic Graph possess?
a. (V*(V-1))/2
b. (V*(V+1))/2
c. (V+1)C2
d. (V-1)C2
Answer: (a).(V*(V-1))/2
117. The topological sorting of any DAG can be done in ________ time.
a. cubic
b. quadratic
c. linear
d. logarithmic
Answer: (c).linear
118. If there are more than 1 topological sorting of a DAG is possible, which of the following is true.
a. Many Hamiltonian paths are possible
119. What would be the output of the following C++ program if the given input is
00011
00001
00010
10100
11000
#include <bits/stdc++.h>
bool visited[5];
int G[5][5];
void fun(int i)
cout<<i<<" ";
visited[i]=true;
for(int j=0;j<5;j++)
if(!visited[j]&&G[i][j]==1)
fun(j);
int main()
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cin>>G[i][j];
for(int i=0;i<5;i++)
visited[i]=0;
fun(0);
return 0;
a. 02314
b. 03241
c. 02341
d. 03214
Answer: (a).
a. True
b. False
c. May be
d. Can't say
Answer: (b).False
122. What is the value of the sum of the minimum in-degree and maximum out-degree of an Directed Acyclic Grap
a. Depends on a Graph
123. In which of the following does a Directed Acyclic Word Graph finds its application in?
a. String Matching
b. Number Sorting
c. Manipulations on numbers
124. What is time complexity to check if a string(length S1) is a substring of another string(length S2) stored in a D
S2 is greater than S1?
a. O(S1)
b. O(S2)
c. O(S1+S2)
d. O(1)
Answer: (a).O(S1)
125. In which of the following case does a Propositional Directed Acyclic Graph is used for?
b. String Matching
c. Searching
d. Sorting of number
126. Every Binary Decision Diagram is also a Propositional Directed Acyclic Graph.
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
127. In a Propositional Directed Acyclic Graph Leaves maybe labelled with a boolean variable.
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
i) {{1,0} {0,1}}
ii) {{0,1}{1,0}}
iii) {{0,0,1}{0,1,0}{1,0,0}}
a. only i)
c. i) and iii)
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
130. Determine the number of vertices for the given Graph or Multigraph?
G is a 4-regular Graph having 12 edges.
a. 3
b. 6
c. 4
Answer: (b).
Answer: (b).There exists a MultiGraph having 10 vertices such that minimum degree of the graph is 0 and maximum
ii) {{0,1}{1,0}}
iii) {{0,0,1}{0,1,0}{1,0,0}}
a. only i)
c. i) and iii)
133. Possible number of labelled simple Directed, Pseudo and Multigarphs exist having 2 vertices?
a. 3, Infinite, 4
b. 4, 3, Infinite
c. 4, Infinite
d. 4, Infinite, Infinite
134. Which of the following is a HyperGraph, where V is the set of vertices, E is the set of edges?
c. V = {v1, v2, v3} E = {e1, e2, e3} = {{v2, v3}{v3, v1}{v2, v1}}
a. {{1,0,1,0},
{1,1,0,1},
{0,0,1,1}}
b. {{1,1,0,0},
{0,1,0,0},
{1,1,1,0}}
c. {{0,1,0,1},
{0,0,1,0},
{1,1,0,0}}
Answer: (a).{{1,0,1,0},
{1,1,0,1},
{0,0,1,1}}
136. What is the degree sequence of the given HyperGraph, in non-increasing order.
V = {v1,v2,v3,v4,v5,v6} E = {{v1,v4,v5} {v2,v3,v4,v5} {v2} {v1} {v1,v6}}
a. 3,2,1,1,1,1
b. 3,2,2,2,1,1
c. 3,2,2,2,2,1
d. 3,2,2,1,1,1
Answer: (b).3,2,2,2,1,1
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
a. Multigraph
b. Cyclic Graph
139. In which of the following case does a Binary Decision Diagram is used for?
b. String Matching
c. Searching
d. Sorting of number
a. 1
b. 2
c. 3
d. 4
Answer: (b).
a. dashed, bold
b. bold, dashed
c. dotted, bold
d. dotted, dashed
142. How many nodes are required to create a Binary Decision Tree having 4 variables?
a. 2^4
b. 2^(4-1)
c. 2^5
d. 2^(5-1)
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).2^(5-1)
143. Two or more And Inverter Graphs can represent same function.
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
144. Size of an And Inverter Graph is the number of _______ gates and the number of logic levels is number of __
path from a primary input to a primary output.
a. Multigraph
b. Cyclic Graph
146. The And Inverter Graph representation of a Boolean function is more efficient than the Binary Decision Diagr
a. True
b. False
c. May be
d. Can't say
Answer: (a).True
147. Which of the following logical operation can be implemented by polynomial time graph manipulation algorithm
Diagrams?
a. Conjunction
b. Disjunction
c. Negation
148. Depth First Search is equivalent to which of the traversal in the Binary Trees?
a. Pre-order Traversal
b. Post-order Traversal
c. Level-order Traversal
d. In-order Traversal
a. O(V + E)
b. O(V)
c. O(E)
Answer: (a).O(V + E)
150. The Data structure used in standard implementation of Breadth First Search is?
a. Stack
b. Queue
c. Linked List
Answer: (a).
155. Regarding implementation of Depth First Search using stacks, what is the maximum distance between two no
(considering each edge length 1)
a. Can be anything
b. 0
c. At most 1
d. Insufficient Information
a. Once
b. Twice
157. Breadth First Search is equivalent to which of the traversal in the Binary Trees?
a. Pre-order Traversal
b. Post-order Traversal
c. Level-order Traversal
d. In-order Traversal
158. Time Complexity of Breadth First Search is? (V – number of vertices, E – number of edges)
a. O(V + E)
b. O(V)
c. O(E)
Answer: (a).O(V + E)
159. The Breadth First Search traversal of a graph will result into?
a. Linked List
b. Tree
Answer: (b).Tree
160. A person wants to visit some places. He starts from a vertex and then wants to visit every place connected to
algorithm he should use?
c. Trim’s algorithm
Answer: (b).
163. Regarding implementation of Breadth First Search using queues, what is the maximum distance between two
(considering each edge length 1)
a. Can be anything
b. 0
c. At most 1
d. Insufficient Information
a. Once
b. Twice
Answer: (c).
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on
“Array and Array Operations”.
1. Which of these best describes an array?
a) A data structure that shows a hierarchical behavior
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
Answer: b
2. How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Answer: c
3. How do you instantiate an array in Java?
a) int arr[] = new int(3);
b) int arr[];
c) int arr[] = new int[3];
d) int arr() = new int(3)
Answer: c
4. Which of the following is the correct way to declare a multidimensional array in Java?
a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;
Answer: c
7. When does the ArrayIndexOutOfBoundsException occur?
a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all
Answer: b
8. Which of the following concepts make extensive use of arrays?
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
Answer: d
9. What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
Answer: d
10. What are the disadvantages of arrays?
a) Data structure like queue or stack cannot be implemented
b) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed
Answer: b
11. Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Answer: d
12. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Answer: a
13. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on
“Stack Operations – 1”.
4. Which of the following statement(s) about stack data structure is/are NOT
correct?
a) Linked List are used for implementing Stacks
b) Top of the Stack always contain the new node
c) Stack is the FIFO data structure
d) Null link is present in the last node at the bottom of the stack
Answer: c
5. Which of the following is not an inherent application of stack?
a) Reversing a string
b) Evaluation of postfix expression
c) Implementation of recursion
d) Job scheduling
Answer: d
6. The type of expression in which operator succeeds its operands is?
a) Infix Expression
b) Prefix Expression
c) Postfix Expression
d) Both Prefix and Postfix Expressions
Answer: c
7. Assume that the operators +,-, X are left associative and ^ is right associative.
The order of precedence (from highest to lowest) is ^, X, +, -. The postfix
expression for the infix expression a + b X c – d ^ e ^ f is?
a) abc X+ def ^^ –
b) abc X+ de^f^ –
c) ab+c Xd – e ^f^
d) -+aXbc^ ^def
Answer: b
8. If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one
at a time, what is the order of removal?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: b
This set of Data Structure Multiple Choice Questions & Answers (MCQs)
focuses on “Queue Operations”.
1. A linear list of elements in which deletion can be done from one end
(front) and insertion can take place only at the other end (rear) is known
as _____________
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
2. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
Answer: c
3. A queue follows __________
a) FIFO (First In First Out) principle
b) LIFO (Last In First Out) principle
c) Ordered array
d) Linear tree
Answer: a
4. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted
one at a time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: a
6. A data structure in which elements can be inserted or deleted at/from both
ends but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
1. A linear collection of data elements where the linear node is given by means of
pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer: a
2. In linked list each node contains a minimum of two fields. One field is data field to
store the data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
Answer: c
3. What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
Answer: c
4. What would be the asymptotic time complexity to insert an element at the front of the
linked list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
5. What would be the asymptotic time complexity to find an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n4)
Answer: b
6. What would be the asymptotic time complexity to insert an element at the second
position in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
7. The concatenation of two lists can be performed in O(1) time. Which of the following
variation of the linked list can be used?
a) Singly linked list
b) Doubly linked list
c) Circular doubly linked list
d) Array implementation of list
Answer: c
This set of Data Structure Interview Questions and Answers for freshers
focuses on “Singly Linked Lists Operations – 2”.
1. What kind of linked list is best to answer questions like “What is the item at
position n?”
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Array implementation of linked list
Answer: d
2. Linked lists are not suitable for the implementation of ___________
a) Insertion sort
b) Radix sort
c) Polynomial manipulation
d) Binary search
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs)
focuses on “Singly Linked List”.
1. Which of the following is not a disadvantage to the usage of array?
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an
array are lesser than the allocated size
c) Insertion based on position
d) Accessing elements at specified positions
Answer: d
2. What is the time complexity of inserting at the end in dynamic arrays?
a) O(1)
b) O(n)
c) O(logn)
d) Either O(1) or O(n)
Answer: d
3. What is the time complexity to count the number of elements in the linked
list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
Answer: b
4. What is the space complexity for deleting a linked list?
a) O(1)
b) O(n)
c) Either O(1) or O(n)
d) O(logn)
Answer: a
5. Which of these is not an application of a linked list?
a) To implement file systems
b) For separate chaining in hash-tables
c) To implement non-binary trees
d) Random Access of elements
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs)
focuses on “Stack using Array”.
1. Which of the following real world scenarios would you associate with a stack
data structure?
a) piling up of chairs one above the other
b) people standing in a line to be serviced at a counter
c) offer services based on the priority of the customer
d) tatkal Ticket Booking in IRCTC
Answer: a
2. What does ‘stack underflow’ refer to?
a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception
Answer: c
3. What is the time complexity of pop() operation when the stack is implemented
using an array?
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
Answer: a
4. Which of the following array position will be occupied by a new element being
pushed for a stack of size N elements(capacity of stack > N)?
a) S[N-1]
b) S[N]
c) S[1]
d) S[0]
Answer: b
5. What happens when you pop from an empty stack while implementing using
the Stack ADT in Java?
a) Undefined error
b) Compiler displays a warning
c) EmptyStackException is thrown
d) NoStackException is thrown
Answer: c
6. Array implementation of Stack is not dynamic, which of the following
statements supports this argument?
a) space allocation for array is fixed and cannot be changed during run-time
b) user unable to give the input for stack operations
c) a runtime exception halts execution
d) improper program compilation
Answer: a
7. Which of the following array element will return the top-of-the-stack-element
for a stack of size N elements(capacity of stack > N)?
a) S[N-1]
b) S[N]
c) S[N-2]
d) S[N+1]
Answer: a
This set of Data Structure Multiple Choice Questions & Answers
(MCQs) focuses on “Stack using Linked List”.
1. What is the best case time complexity of deleting a node in a Singly
Linked list?
a) O (n)
b) O (n2)
c) O (nlogn)
d) O (1)
Answer: d
2. Which of the following statements are not correct with respect to
Singly Linked List(SLL) and Doubly Linked List(DLL)?
a) Complexity of Insertion and Deletion at known position is O(n) in
SLL and O(1) in DLL
b) SLL uses lesser memory per node than DLL
c) DLL has more searching power than SLL
d) Number of node fields in SLL is more than DLL
Answer: d
3. What does ‘stack overflow’ refer to?
a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception
Answer: b
4. Which of the following data structures can be used for parentheses
matching?
a) n-ary tree
b) queue
c) priority queue
d) stack
Answer: d
5. Minimum number of queues to implement stack is ___________
a) 3
b) 4
c) 1
d) 2
Answer: c
This set of Data Structure Multiple Choice Questions & Answers
(MCQs) focuses on “Queue using Array”.
3. What is the term for inserting into a full queue known as?
a) overflow
b) underflow
c) null pointer exception
d) program won’t be compiled
Answer: a
4. What is the time complexity of enqueue operation?
a) O(logn)
b) O(nlogn)
c) O(n)
d) O(1)
Answer: d
5. What is the need for a circular queue?
a) effective usage of memory
b) easier computations
c) to delete elements based on priority
d) implement LIFO principle in queues
Answer: a
6. What is the space complexity of a linear queue having n elements?
a) O(n)
b) O(nlogn)
c) O(logn)
d) O(1)
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs)
focuses on “Priority Queue”.
1. With what data structure can a priority queue be implemented?
a) Array
b) List
c) Heap
d) Tree
Answer: d
2. Which of the following is not an application of priority queue?
a) Huffman codes
b) Interrupt handling in operating system
c) Undo operation in text editors
d) Bayesian spam filter
Answer: c
3. What is the time complexity to insert a node based on key in a priority
queue?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: c
4. What is not a disadvantage of priority scheduling in operating systems?
a) A low priority process might have to wait indefinitely for the CPU
b) If the system crashes, the low priority systems may be lost permanently
c) Interrupt handling
d) Indefinite blocking
Answer: c
5. Which of the following is not an advantage of a priority queue?
a) Easy to implement
b) Processes with different priority can be efficiently handled
c) Applications with differing requirements
d) Easy to delete elements in any case
Answer: d
6. What is the time complexity to insert a node based on position in a priority
queue?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: c
This set of Data Structure Multiple Choice Questions & Answers
(MCQs) focuses on “Double Ended Queue (Dequeue)”.
1. What is a dequeue?
a) A queue with insert/delete defined for both front and rear ends
of the queue
b) A queue implemented with a doubly linked list
c) A queue implemented with both singly and doubly linked lists
d) A queue with insert/delete defined for front side of the queue
Answer: a
a) abc*+
b) abc+*
c) ab+c*
d) a+bc*
Answer: a
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Evaluation of an Infix
Expression (Not Parenthesized)”.
1. How many stacks are required for applying evaluation of infix
expression algorithm?
a) one
b) two
c) three
d) four
Answer: b
2. How many passes does the evaluation of infix expression
algorithm makes through the input?
a) One
b) Two
c) Three
d) Four
Answer: a
3. Identify the infix expression from the list of options given below.
a) a/b+(c-d)
b) abc*+d+ab+cd+*ce-f-
c) ab-c-
d) +ab
Answer: a
4. Which of the following statement is incorrect with respect to
evaluation of infix expression algorithm?
a) Operand is pushed on to the stack
b) If the precedence of operator is higher, pop two operands and
evaluate
c) If the precedence of operator is lower, pop two operands and
evaluate
d) The result is pushed on to the operand stack
Answer: b
5. Evaluate the following statement using infix evaluation algorithm
and choose the correct answer. 1+2*3-2
a) 3
b) 6
c) 5
d) 4
Answer: c
6. Evaluation of infix expression is done based on precedence of
operators.
a) True
b) False
Answer: a
7. Of the following choices, which operator has the lowest
precedence?
a) ^
b) +
c) /
d) #
Answer: d
8. The system throws an error if parentheses are encountered in an
infix expression evaluation algorithm.
a) True
b) False
Answer: b
9. Evaluate the following and choose the correct answer.
a/b+c*d where a=4, b=2, c=2, d=1.
a) 1
b) 4
c) 5
d) 2
Answer: b
10. Evaluate the following statement using infix evaluation algorithm
and choose the correct answer. 4*2+3-5/5
a) 10
b) 11
c) 16
d) 12
Answer: a
11. Using the evaluation of infix expression, evaluate a^b+c and
choose the correct answer. (a=2, b=2, c=2)
a) 12
b) 8
c) 10
d) 6
Answer: d
12. Evaluate the following infix expression using algorithm and choose
the correct answer. a+b*c-d/e^f where a=1, b=2, c=3, d=4, e=2,
f=2.
a) 6
b) 8
c) 9
d) 7
Answer: a
13. From the given expression tree, identify the infix expression,
evaluate it and choose the correct result.
a) 5
b) 10
c) 12
d) 16
Answer: c
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Evaluation of a
Prefix Expression”.
A+(B*C)
a)+A*CB
b)*B+AC
c)+A*BC
d) *A+CB
Answer: c
(A*B)+(C*D)
a)+*AB*CD
b)*+AB*CD
c)**AB+CD
d) +*BA*CD
Answer: a
A+B*C^D
a)+A*B^CD
b)+A^B*CD
c)*A+B^CD
d) ^A*B+CD
Answer: a
5. Out of the following operators (^, *, +, &, $), the one having highest priority is _________
a) +
b) $
c) ^
d) &
Answer: c
6.Out of the following operators (|, *, +, &, $), the one having lowest
priority is ________
a) +
b) $
c) |
d) &
Answer: c
7. What would be the Prefix notation for the given equation?
A^B^C^D
a)^^^ABCD
b)^A^B^CD
c)ABCD^^^
d) AB^C^D
Answer: a
8. What would be the Prefix notation for the given equation?
a+b-c/d&e|f
a)|&-+ab/cdef
b)&|-+ab/cdef
c)|&-ab+/cdef
d) |&-+/abcdef
Answer: a
(a+(b/c)*(d^e)-f)
a)-+a*/^bcdef
b)-+a*/bc^def
c)-+a*b/c^def
d) -a+*/bc^def
Answer: b
10. What would be the Prefix notation and Postfix notation for the given equation?
A+B+C
a) ++ABC and AB+C+
b) AB+C+ and ++ABC
c) ABC++ and AB+C+
d) ABC+ and ABC+
Answer: a
11. What would be the Prefix notation for the given equation?
a|b&c
a)a|&bc
b)&|abc
c)|a&bc
d) ab&|c
Answer: c
This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs)
focuses on “Infix to Postfix Conversion”.
a+b*c+(d*e)
a)abc*+de*+
b) abc+*de*+
c) a+bc*de+*
d) abc*+(de)*+
Answer: a
6.Parentheses are simply ignored in the conversion of infix to postfix
expression.
a) True
b) False
Answer: b
7. It is easier for a computer to process a postfix expression than an infix
expression.
a) True
b) False
Answer: a
8. What is the postfix expression for the infix expression?
a-b-c
a)-ab-c
b)ab–c–
c)–-abc
d) -ab-c
Answer: b
9. What is the postfix expression for the following infix expression?
a/b^c-d
a)abc^/d-
b)ab/cd^-
c)ab/^cd-
d) abcd^/-
Answer: a
10. Which of the following statement is incorrect with respect to
infix to postfix conversion algorithm?
a) operand is always placed in the output
b) operator is placed in the stack when the stack operator has
lower precedence
c) parenthesis are included in the output
d) higher and equal priority operators follow the same condition
Answer: c
11. In infix to postfix conversion algorithm, the operators are
associated from?
a) right to left
b) left to right
c) centre to left
d) centre to right
Answer: b
12. What is the corresponding postfix expression for the given infix expression?
a*(b+c)/d
a)ab*+cd/
b)ab+*cd/
c)abc*+/d
d) abc+*d/
Answer: d
13. What is the corresponding postfix expression for the given infix expression?
a+(b*c(d/e^f)*g)*h)
a)ab*cdef/^*g-h+
b)abcdef^/*g*h*+
c)abcd*^ed/g*-h*+
d) abc*de^fg/*-*h+
Answer: b
14. What is the correct postfix expression for the following expression?
a+b*(c^d-e)^(f+g*h)-i
a)abc^de-fg+*^*+i-
b)abcde^-fg*+*^h*+i-
c)abcd^e-fgh*+^*+i-
d) ab^-dc*+ef^gh*+i-
Answer: c
14. From the given Expression tree, identify the correct postfix
expression from the list of options.
a) ab*cd*+
b) ab*cd-+
c) abcd-*+
d) ab*+cd-
Answer: b
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Prefix to Infix
Conversion”.
1. What would be the solution to the given prefix notation?
- + 5 / 10 5 5
a)2
b)5
c)10
d) 7
Answer: a
2. What would be the solution to the given prefix notation?
/ / / / 16 4 2 1
a)1
b)4
c)2
d) 8
Answer: a
3. What would be the solution to the given prefix notation?
+ 9 * 3 / 8 4
a)14
b)15
c)18
d) 12
Answer: b
4. What would be the solution to the given prefix notation?
- + 1 2 * 3 / 6 2
a)6
b)-6
c)3
d) -3
Answer: b
5. What would be the solution to the given prefix notation?
- * 1 5 / * / 6 3 6 2
a)1
b)0
c)-1
d) -2
Answer: c
6. What would be the solution to the given prefix notation?
* / + 1 2 / 4 2 + 3 5
a)12
b)7.5
c)9
d) 13.5
Answer: a
7.Given a prefix and a postfix notation what are the difference between
them?
a) The postfix equation is solved starting from the left whereas the prefix
notation is solved from the right
b) The postfix equation is solved starting from the right whereas the prefix
notation is solved from the left
c) Both equations are solved starting from the same side(right)
d) Both equations are solved starting from the same side(left)
Answer: a
8. When converting the prefix notation into an infix notation, the first step to
be followed is ________
a) Reverse the equation
b) Push the equation to the stack
c) Push the equation onto the queue
d) Push the equation to the stack or queue
Answer: a
9. The time complexity of converting a prefix notation to infix notation is
_________
a) O(n) where n is the length of the equation
b) O(n) where n is number of operands
c) O(1)
d) O(logn) where n is length of the equation
Answer: a
10. Given two processes (conversion of postfix equation to infix notation and
conversion of prefix notation to infix notation), which of the following is
easier to implement?
a) Both are easy to implement
b) Conversion of postfix equation to infix equation is harder than
converting a prefix notation to infix notation
c) Conversion of postfix equation to infix equation is easier than
converting a prefix notation to infix notation
d) Insufficient data
Answer: c
This set of Data Structures & Algorithms Multiple Choice Questions
& Answers (MCQs) focuses on “Postfix to Infix Conversion”.
a) Insertion sort
b) Selection sort
c) Bubble sort
d) Merge sort
View Answer / Hide Answer
ANSWER: B
a) Merge sort
b) Typical in-place quick sort
c) Heap sort
d) Selection sort
View Answer / Hide Answer
ANSWER: A
3. Which of the following is not an in-place sorting algorithm?
a) Selection sort
b) Heap sort
c) Quick sort
d) Merge sort
View Answer / Hide Answer
ANSWER: D
a) O(n)
b) O(nlogn)
c) O(n2)
d) None
View Answer / Hide Answer
ANSWER: B
5. The time complexity of a quick sort algorithm which makes use of median,
found by an O(n) algorithm, as pivot element is
a) O(n2)
b) O(nlogn)
c) O(nloglogn)
d) O(n)
View Answer / Hide Answer
ANSWER: B
a) Counting sort
b) Bucket sort
c) Radix sort
d) Shell sort
View Answer / Hide Answer
ANSWER: D
7. The time complexity of heap sort in worst case is
a) O(logn)
b) O(n)
c) O(nlogn)
d) O(n2)
View Answer / Hide Answer
ANSWER: C
8. If the given input array is sorted or nearly sorted, which of the following
algorithm gives the best performance?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Merge sort
View Answer / Hide Answer
ANSWER: A
9. Which of the following algorithm pays the least attention to the ordering of the
elements in the input list?
a) Insertion sort
b) Selection sort
c) Quick sort
d) None
View Answer / Hide Answer
ANSWER: B
10. Consider the situation in which assignment operation is very costly. Which of
the following sorting algorithm should be performed so that the number of
assignment operations is minimized in general?
a) Insertion sort
b) Selection sort
c) Heap sort
d) None
View Answer / Hide Answer
ANSWER: B
11. Time complexity of bubble sort in best case is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) θ (n(logn) 2)
View Answer / Hide Answer
ANSWER: A
12. Given a number of elements in the range [0….n3]. which of the following
sorting algorithms can sort them in O(n) time?
a) Counting sort
b) Bucket sort
c) Radix sort
d) Quick sort
View Answer / Hide Answer
ANSWER: C
13. Which of the following algorithms has lowest worst case time complexity?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Heap sort
View Answer / Hide Answer
ANSWER: D
14. Which of the following sorting algorithms is/are stable
a) Counting sort
b) Bucket sort
c) Radix sort
d) All of the above
View Answer / Hide Answer
ANSWER: D
15. Counting sort performs …………. Numbers of comparisons between input
elements.
a) 0
b) n
c) nlogn
d) n2
View Answer / Hide Answer
ANSWER: A
16. The running time of radix sort on an array of n integers in the range [0……..n5 -
1] when using base 10 representation is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) none
View Answer / Hide Answer
ANSWER: B
17. The running time of radix sort on an array of n integers in the range
[0……..n5 -1] when using base n representation is
a) θ (n)
b) θ (nlogn)
c) θ (n2)
d) None
View Answer / Hide Answer
ANSWER: A
18. Which of the following sorting algorithm is in-place
a) Counting sort
b) Radix sort
c) Bucket sort
d) None
View Answer / Hide Answer
ANSWER: B
19. The radix sort does not work correctly if each individual digit is sorted using
a) Insertion sort
b) Counting sort
c) Selection sort
d) Bubble sort
View Answer / Hide Answer
ANSWER: C
20. Which of the following sorting algorithm has the running time that is least
dependant on the initial ordering of the input?
a) Insertion sort
b) Quick sort
c) Merge sort
d) Selection sort
View Answer / Hide Answer
ANSWER: D
21. Time complexity to sort elements of binary search tree is
a) O(n)
b) O(nlogn)
c) O(n2)
d) O(n2logn)
View Answer / Hide Answer
ANSWER: A
22. The lower bound on the number of comparisons performed by comparison-
based sorting algorithm is
a) Ω (1)
b) Ω (n)
c) Ω (nlogn)
d) Ω (n2)
View Answer / Hide Answer
ANSWER: C
23. Which of the following algorithm(s) can be used to sort n integers in range
[1…..n3] in O(n) time?
a) Heap sort
b) Quick sort
c) Merge sort
d) Radix sort
View Answer / Hide Answer
ANSWER: D
24. Which of the following algorithm design technique is used in the quick sort
algorithm?
a) Dynamic programming
b) Backtracking
c) Divide-and-conquer
d) Greedy method
View Answer / Hide Answer
ANSWER: C
25. Merge sort uses
a) Divide-and-conquer
b) Backtracking
c) Heuristic approach
d) Greedy approach
View Answer / Hide Answer
26. For merging two sorted lists of size m and n into sorted list of size m+n, we
require comparisons of
a) O(m)
b) O(n)
c) O(m+n)
d) O(logm + logn)
View Answer / Hide Answer
ANSWER: C
27. A sorting technique is called stable if it
a) θ (nlogn)
b) θ (n)
c) θ (logn)
d) θ (1)
View Answer / Hide Answer
ANSWER: A
29. What would be the worst case time complexity of the insertion sort algorithm,
if the inputs are restricted to permutation of 1…..n with at most n inversion?
a) θ (n2)
b) θ (nlogn)
c) θ (n1.5)
d) θ (n)
View Answer / Hide Answer
ANSWER: D
30. In a binary max heap containing n numbers, the smallest element can be
found in time
a) θ (n)
b) θ (logn)
c) θ (loglogn)
d) θ (1)
View Answer / Hide Answer
ANSWER: A
MCQs on Queue with answers
1. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
View Answer / Hide Answer
2. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
View Answer / Hide Answer
ANSWER: c) Queue
3. Let the following circular queue can accommodate maximum six elements with
the following data
front = 2 rear = 4
queue = _______; L, M, N, ___, ___
What will happen after ADD O operation takes place?
a) front = 2 rear = 5
queue = ______; L, M, N, O, ___
b) front = 3 rear = 5
queue = L, M, N, O, ___
c) front = 3 rear = 4
queue = ______; L, M, N, O, ___
d) front = 2 rear = 4
queue = L, M, N, O, ___
View Answer / Hide Answer
ANSWER: a)
4. A queue is a ?
5. In Breadth First Search of Graph, which of the following data structure is used?
a) Stack
b) Queue
c) Linked list
d) None
View Answer / Hide Answer
ANSWER: b) Queue
6. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one
at a time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABCD
View Answer / Hide Answer
ANSWER: a) ABCD
a) Insertion
b) Deletion
c) To empty a queue
d) None
View Answer / Hide Answer
ANSWER: d) None
9. In linked list implementation of queue, if only front pointer is maintained, which
of the following operation take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
d) Both a) and c)
View Answer / Hide Answer
10. If the MAX_SIZE is the size of the array used in the implementation of circular
queue. How is rear manipulated while inserting an element in the queue?
a) rear=(rear%1)+MAX_SIZE
b) rear=rear%(MAX_SIZE+1)
c) rear=(rear+1)%MAX_SIZE
d) rear=rear+(1%MAX_SIZE)
View Answer / Hide Answer
ANSWER: c) rear=(rear+1)%MAX_SIZE
11. If the MAX_SIZE is the size of the array used in the implementation of circular
queue, array index start with 0, front point to the first element in the queue, and
rear point to the last element in the queue. Which of the following condition
specify that circular queue is FULL?
a) Front=rear= -1
b) Front=(rear+1)%MAX_SIZE
c) Rear=front+1
d) Rear=(front+1)%MAX_SIZE
View Answer / Hide Answer
ANSWER: b) Front=(rear+1)%MAX_SIZE
12. A circular queue is implemented using an array of size 10. The array index
starts with 0, front is 6, and rear is 9. The insertion of next element takes place at
the array index.
a) 0
b) 7
c) 9
d) 10
View Answer / Hide Answer
ANSWER: a) 0
13. If the MAX_SIZE is the size of the array used in the implementation of circular
queue, array index start with 0, front point to the first element in the queue, and
rear point to the last element in the queue. Which of the following condition
specify that circular queue is EMPTY?
a) Front=rear=0
b) Front= rear=-1
c) Front=rear+1
d) Front=(rear+1)%MAX_SIZE
View Answer / Hide Answer
14. A data structure in which elements can be inserted or deleted at/from both the
ends but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
View Answer / Hide Answer
ANSWER: c) Dequeue
15. In linked list implementation of a queue, front and rear pointers are tracked.
Which of these pointers will change during an insertion into a NONEMPTY
queue?
16. A normal queue, if implemented using an array of size MAX_SIZE, gets full
when
a) Rear=MAX_SIZE-1
b) Front=(rear+1)mod MAX_SIZE
c) Front=rear+1
d) Rear=front
View Answer / Hide Answer
ANSWER: a) Rear=MAX_SIZE-1
17. In linked list implementation of a queue, front and rear pointers are tracked.
Which of these pointers will change during an insertion into EMPTY queue?
a) Zero
b) One
c) MAX_SIZE-1
d) MAX_SIZE
View Answer / Hide Answer
ANSWER: d) MAX_SIZE
ANSWER: a)
20. Consider the following operations along with ENQUEUE and DEQUEUE
operations queues, where k is a global parameter.
Multiqueue(Q)
{
m=k;
while(Q is not empty) and (m > 0)
{
DEQUEUE(Q)
m=m-1
}
}
a) θ (n)
b) θ (n + k)
c) θ (nk)
d) θ (n2)
View Answer / Hide Answer
ANSWER: a) θ (n)