100% found this document useful (1 vote)
1K views333 pages

DSA Final Mcqs

This document contains a set of multiple choice questions and answers about operations on singly linked lists. It discusses concepts like the definition of a linked list, asymptotic time complexities of various linked list operations like insertion, deletion, searching, etc. It also contains questions about memory allocation, advantages of linked lists over arrays, and sorting linked lists. The questions cover basic to advanced level concepts related to linked lists.

Uploaded by

Sjawal Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views333 pages

DSA Final Mcqs

This document contains a set of multiple choice questions and answers about operations on singly linked lists. It discusses concepts like the definition of a linked list, asymptotic time complexities of various linked list operations like insertion, deletion, searching, etc. It also contains questions about memory allocation, advantages of linked lists over arrays, and sorting linked lists. The questions cover basic to advanced level concepts related to linked lists.

Uploaded by

Sjawal Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 333

This set of Data Structure Interview Questions & Answers focuses on “Singly Linked List Operations – 1”.

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the last node of the linked list

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?

a) Singly linked list

b) Doubly linked list

c) Circular doubly linked list

d) Array implementation of list

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.

9. Consider the following definition in c programming language.

struct node

int data;

struct node * next;

typedef struct node NODE;

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?”

a) Singly linked list

b) Doubly linked list

c) Circular linked list

d) Array implementation of linked list

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.

2. Linked lists are not suitable for the implementation of ___________

a) Insertion sort

b) Radix sort

c) Polynomial manipulation
d) Binary search

View Answer

Answer: d

Explanation: It cannot be implemented using linked lists.

3. Linked list is considered as an example of ___________ type of memory allocation.

a) Dynamic

b) Static

c) Compile time

d) Heap

View Answer

Answer: a

Explanation: As memory is allocated at the run time.

4. In Linked List implementation, a node carries information regarding ___________

a) Data

b) Link

c) Data and 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.

5. Linked list data structure offers considerable saving in _____________


a) Computational Time

b) Space Utilization

c) Space Utilization and Computational Time

d) Speed Utilization

View Answer

Answer: c

Explanation: Linked lists saves both space and time.

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

b) It is easy to insert and delete elements in Linked List

c) Random access is not allowed in a typical implementation of Linked Lists

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?

void fun1(struct node* head)

if(head == NULL)

return;

fun1(head->next);
printf("%d ", head->data);

a) Prints all nodes of linked lists

b) Prints all nodes of linked list in reverse order

c) Prints alternate nodes of Linked List

d) Prints alternate nodes in reverse order

View Answer

Answer: b

Explanation: fun1() prints the given Linked List in reverse manner.

For Linked List 1->2->3->4->5, fun1() prints 5->4->3->2->1.

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?

a) Possible if X is not last node

b) Possible if size of linked list is even

c) Possible if size of linked list is odd

d) Possible if X is not first node

View Answer

Answer: a

Explanation: Following are simple steps.

struct node *temp = X->next;

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?

a) Delete the first element

b) Insert a new element as a first element

c) Delete the last element of the list

d) Add a new element at the end of the 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”.

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

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.

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)

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

6. 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)

View Answer

Answer: a

8. 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

View Answer

Answer: d

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Doubly Linked List”.

1. Which of the following is false about a doubly linked list?

a) We can navigate in both the directions

b) It requires more space than a singly linked list

c) The insertion and deletion of a node take a bit longer

d) Implementing a doubly linked list is easier than singly 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

b) pointer to previous node xor pointer to next node

c) pointer to previous node – pointer to next node

d) pointer to next node – pointer to previous node

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

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

View Answer

Answer: d

6. 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

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.

10. Minimum number of queues to implement stack is ___________

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

d) Both Insertion and 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?

a) At the head of link list

b) At the centre position in the link list

c) At the tail of the link list

d) At any position in the linked list

View Answer

Answer: c

Explanation: Since queue follows FIFO so new element inserted at last.

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?

a) Only front pointer

b) Only rear pointer

c) Both front and rear pointer

d) No pointer will be changed

View Answer

Answer: b

Explanation: Since queue follows FIFO so new element inserted at last.

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?

a) Only front pointer

b) Only rear pointer

c) Both front and rear pointer

d) No pointer will be changed

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

Explanation: All the nodes are collected in AVAIL list.

6. In linked list implementation of a queue, from where is the item deleted?

a) At the head of link list

b) At the centre position in the link list

c) At the tail of the link list

d) Node before the tail

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

Explanation: Because front represents the deleted nodes.

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

Explanation: To check whether there is space in the queue or not.

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?

a) They will have different time complexities

b) The memory used will not be different

c) There are chances that output might be different

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.

4. Consider you have a stack whose elements in it are as follows.

5 4 3 2 << top

Where the top element is 2.

You need to get the following stack

6 5 4 3 2 << top

The operations that needed to be performed are (You can perform only push and pop):

a) Push(pop()), push(6), push(pop())

b) Push(pop()), push(6)

c) Push(pop()), 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)

a) O(m) and O(n)

b) O(1) and O(n)

c) O(n) and O(1)

d) O(n) and O(m)

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)?

a) Because of its time complexity O(n)

b) Because of its time complexity O(log(n))

c) Extra memory is not required

d) There are no problems

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

c) There exists no possible way to do this

d) Break the jar and remove the last 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”.

1. How many children does a binary tree have?


a) 2

b) any number of children

c) 0 or 1 or 2

d) 0 or 1

View Answer

Answer: c

Explanation: Can have atmost 2 nodes.

2. What is/are the disadvantages of implementing tree using normal arrays?

a) difficulty in knowing children nodes of a node

b) difficult in finding the parent of a node

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

b) 2+w and 2-w

c) w+1/2 and w/2

d) w-1/2 and w+1/2

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

Explanation: Floor of w-1/2 because we can’t miss a node.

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

b) no need of any changes continue with 2w and 2w+1, if node is at i

c) keep a seperate table telling children of a node


d) use another array parallel to the array with tree

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

b) yes because array values are indexable

c) No it is not efficient in case of sparse trees and remaning cases it is fine

d) No linked list representation of tree is only fine

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

b) No we need one more traversal to form a tree

c) No in case of sparse trees

d) Yes by using both inorder and array elements

View Answer

Answer: b

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Binary Trees using
Linked Lists”.

1. Advantages of linked list representation of binary trees over arrays?

a) dynamic size
b) ease of insertion/deletion

c) ease in randomly accessing a node

d) both dynamic size and ease in insertion/deletion

View Answer

Answer: d

Explanation: It has both dynamic size and ease in insertion and deletion as advantages.

2. Disadvantages of linked list representation of binary trees over arrays?

a) Randomly accessing is not possible

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

Explanation: Random access is not possible with linked lists.

3. Which of the following traversing algorithm is not used to traverse in a tree?

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

a) breadth first search

b) depth first search

c) dijkstra’s algorithm

d) prims algorithm

View Answer

Answer: a

Explanation: Level order is similar to bfs.

5. Identify the reason which doesn’t play a key role to use threaded binary trees?

a) The storage required by stack and queue is more

b) The pointers in most of nodes of a binary tree are NULL

c) It is Difficult to find a successor node

d) They occupy less size

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)

i) from root search for the node to be deleted

ii)

iii) delete the node at

what must be statement ii) and fill up statement iii)


a) ii)-find random node,replace with node to be deleted. iii)- delete the node

b) ii)-find node to be deleted. iii)- delete the node at found location

c) ii)-find deepest node,replace with node to be deleted. iii)- delete a node

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.

2. The following given tree is an example for?

binary-tree-operations-questions-answers-q2

a) Binary tree

b) Binary search 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.

3. A binary tree is a rooted tree but not an ordered 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.

4. How many common operations are performed in a binary tree?

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.

5. What is the traversal strategy used in the binary tree?

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.

6. How many types of insertion are performed in a binary tree?

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.

7. What operation does the following diagram depict?


binary-tree-operations-questions-answers-q7

a) inserting a leaf node

b) inserting an internal node

c) deleting a node with 0 or 1 child

d) deleting a node with 2 children

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.

8. General ordered tree can be encoded into binary trees.

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.

9. How many bits would a succinct binary tree occupy?

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.

10. The average depth of a binary tree is given as?

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.

13. Using what formula can a parent node be located in an array?

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?

a) Left subtrees are visited before right subtrees

b) Right subtrees are visited before left subtrees

c) Root node is visited before left subtree

d) Root node is visited before right subtree

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”.

1. For the tree below, write the pre-order 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

Explanation: Pre order traversal follows NLR(Node-Left-Right).

2. For the tree below, write the post-order 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: c

Explanation: Post order traversal follows LRN(Left-Right-Node).

3. Select the code snippet which performs pre-order traversal.

a)

public void preorder(Tree root)

System.out.println(root.data);

preorder(root.left);

preorder(root.right);

b)

public void preorder(Tree root)

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)

public void preorder(Tree root)

preorder(root.right);

preorder(root.left);

System.out.println(root.data);

View Answer

4. Select the code snippet which performs post-order traversal.

a)

public void postorder(Tree root)

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)

public void postorder(Tree root)

System.out.println(root.data);

postorder(root.right);

postorder(root.left);

d)

public void postorder(Tree root)

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)

public void preOrder(Tree root)

if (root == null) return;

Stack<Tree> stk = new Stack<Tree>();

st.add(root);

while (!stk.empty())

Tree node = stk.pop();

System.out.print(node.data + " ");

if (node.left != null) stk.push(node.left);

if (node.right != null) stk.push(node.right);

b)

public void preOrder(Tree root)

if (root == null) return;

Stack<Tree> stk = new Stack<Tree>();

while (!stk.empty())

Tree node = stk.pop();

System.out.print(node.data + " ");


if (node.right != null) stk.push(node.right);

if (node.left != null) stk.push(node.left);

c)

public void preOrder(Tree root)

if (root == null) return;

Stack<Tree> stk = new Stack<Tree>();

st.add(root);

while (!stk.empty())

Tree node = stk.pop();

System.out.print(node.data + " ");

if (node.right != null) stk.push(node.right);

if (node.left != null) stk.push(node.left);

d)

public void preOrder(Tree root)

if (root == null) return;

Stack<Tree> stk = new Stack<Tree>();


st.add(root);

while (!stk.empty())

Tree node = stk.pop();

System.out.print(node.data + " ");

if (node.right != null) stk.push(node.left);

if (node.left != null) stk.push(node.right);

View Answer

6. Select the code snippet that performs post-order traversal iteratively.

a)

public void postorder(Tree root)

if (root == null)

return;

Stack<Tree> stk = new Stack<Tree>();

Tree node = root;

while (!stk.isEmpty() || node != null)

while (node != null)

if (node.right != null)

stk.add(node.left);
stk.add(node);

node = node.right;

node = stk.pop();

if (node.right != null && !stk.isEmpty() && node.right == stk.peek())

Trees nodeRight = stk.pop();

stk.push(node);

node = nodeRight;

} else

System.out.print(node.data + " ");

node = null;

b)

public void postorder(Tree root)

if (root == null)

return;

Stack<Tree> stk = new Stack<Tree>();

Tree node = root;

while (!stk.isEmpty() || node != null)


{

while (node != null)

if (node.right != null)

stk.add(node.right);

stk.add(node);

node = node.left;

node = stk.pop();

if (node.right != null && !stk.isEmpty() && node.right == stk.peek())

Trees nodeRight = stk.pop();

stk.push(node);

node = nodeRight;

} else

System.out.print(node.data + " ");

node = null;

c)

public void postorder(Tree root)

{
if (root == null)

return;

Stack<Tree> stk = new Stack<Tree>();

Tree node = root;

while (!stk.isEmpty() || node != null)

while (node != null)

if (node.right != null)

stk.add(node.right);

stk.add(node);

node = node.left;

node = stk.pop();

if (node.right != null)

Trees nodeRight = stk.pop();

stk.push(node);

node = nodeRight;

} else

System.out.print(node.data + " ");

node = null;

}
}

d)

public void postorder(Tree root)

if (root == null)

return;

Stack<Tree> stk = new Stack<Tree>();

Tree node = root;

while (!stk.isEmpty() || node != null)

while (node != null)

if (node.right != null)

stk.add(node.left);

stk.add(node);

node = node.left;

node = stk.pop();

if (node.right != null)

Trees nodeRight = stk.pop();

stk.push(node);

node = nodeLeft;

} else
{

System.out.print(node.data + " ");

node = null;

View Answer

7. What is the time complexity of pre-order traversal in the iterative fashion?

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).

9. To obtain a prefix expression, which of the tree traversals is used?

a) Level-order traversal

b) Pre-order traversal

c) Post-order traversal

d) In-order traversal

View Answer

Answer: b

Explanation: As the name itself suggests, pre-order traversal can be used.

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

Explanation: The inorder sequence is B, E, A, D, C and Preorder sequence is A, B, E, C, D. The tree


constructed with the inorder and preorder sequence is

data-structure-questions-answers-preorder-traversal-q10

The levelorder traversal (BFS traversal) is A, B, C, E, D.

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

a) S1 is preorder, S2 is inorder and S3 is postorder

b) S1 is inorder, S2 is preorder and S3 is postorder

c) S1 is inorder, S2 is postorder and S3 is preorder

d) S1 is postorder, S2 is inorder and S3 is preorder

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

Explanation: 5 binary trees are possible and they are,

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?

a) 7, 8, 26, 13, 75, 40, 70, 35

b) 26, 13, 7, 8, 70, 75, 40, 35

c) 7, 8, 13, 26, 35, 40, 70, 75

d) 8, 7, 26, 13, 40, 75, 70, 35

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?

a) post-order and pre-order

b) post-order and in-order

c) post-order and level order

d) level order and preorder

View Answer

Answer: b

Explanation: A binary tree can uniquely be created by post-order and in-order traversals.

6. A full binary tree can be generated using ______

a) post-order and pre-order traversal

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

Explanation: Consider a binary tree,

postorder-traversal-questions-answers-q10

Its in-order traversal – 13 14 16 19

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”.

1. For the tree below, write the in-order 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

Explanation: In-order traversal follows LNR(Left-Node-Right).

2. For the tree below, write the level-order traversal.

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

Explanation: Level order traversal follows a breadth first search approach.

3. Select the code snippet which performs in-order traversal.

a)

public void inorder(Tree root)

System.out.println(root.data);

inorder(root.left);

inorder(root.right);
}

b)

public void inorder(Tree root)

inorder(root.left);

System.out.println(root.data);

inorder(root.right);

c)

public void inorder(Tree root)

System.out.println(root.data);

inorder(root.right);

inorder(root.left);

d)

public void inorder(Tree root)

inorder(root.right);

inorder(root.left);

System.out.println(root.data);

}
View Answer

4. Select the code snippet which performs level-order traversal.

a)

public static void levelOrder(Tree root)

Queue<Node> queue=new LinkedList<Node>();

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)

public static void levelOrder(Tree root)

Queue<Node> queue=new LinkedList<Node>();

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)

public static void levelOrder(Tree root)

Queue<Node> queue=new LinkedList<Node>();

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)

public static void levelOrder(Tree root)

Queue<Node> queue=new LinkedList<Node>();

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).

6. What is the time complexity of level order traversal?

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?

a) Depth First Search

b) Breadth First Search

c) Depth & Breadth First Search

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?

a) Each node has exactly zero or two children

b) Each node has exactly two children

c) All the leaves are at the same level

d) Each node has exactly one or two children

View Answer

Answer: a

Explanation: A full binary tree is a tree in which each node has exactly 0 or 2 children.

4. What is a complete binary tree?

a) Each node has exactly zero or two 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

d) A tree In which all nodes have degree 2

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).

6. Which of the following is not an advantage of trees?

a) Hierarchical structure

b) Faster search

c) Router algorithms

d) Undo/Redo operations in a notepad

View Answer

Answer: d

Explanation: Undo/Redo operations in a notepad is an application of stack. Hierarchical structure, Faster


search, Router algorithms are advantages of trees.

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

Explanation: Relation between number of internal nodes(I) and nodes(N) is N = 2*I+1.

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

Explanation: The relation between number of nodes(N) and leaves(L) is N=2*L-1.

10. Which of the following is incorrect with respect to binary trees?

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’.

The partial tree constructed is:

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

Explanation: Postorder sequence is 2, 4, 3, 7, 9, 8, 5.

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

Level Order Traversal: 1, 4, 5, 9, 8, 2, 3

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”.

1. Which of the following is false about a binary search tree?

a) The left child is always lesser than its parent

b) The right child is always greater than its parent

c) The left and right sub-trees should also be binary search trees

d) In order sequence gives decreasing order of elements


View Answer

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.

2. How to search for a key in a binary search tree?

a)

public Tree search(Tree root, int key)

if( root == null || root.key == key )

return root;

if( root.key < key )

return search(root.right,key);

else

return search(root.left,key);

b)

public Tree search(Tree root, int key)

if( root == null || root.key == key )


{

return root;

if( root.key < key )

return search(root.left,key);

else

return search(root.right,key);

c)

public Tree search(Tree root, int key)

if( root == null)

return root;

if( root.key < key )

return search(root.right,key);

else

return search(root.left,key);

}
d)

public Tree search(Tree root, int key)

if( root == null)

return root;

if( root.key < key )

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?

a) It traverses in a non increasing order

b) It traverses in an increasing order

c) It traverses in a random fashion

d) It traverses based on priority of the node

View Answer

4. What does the following piece of code do?


public void func(Tree root)

func(root.left());

func(root.right());

System.out.println(root.data());

a) Preorder traversal

b) Inorder traversal

c) Postorder traversal

d) Level order traversal

View Answer

5. What does the following piece of code do?

public void func(Tree root)

System.out.println(root.data());

func(root.left());

func(root.right());

a) Preorder traversal

b) Inorder traversal

c) Postorder traversal

d) Level order traversal


View Answer

6. How will you find the minimum element in a binary search tree?

a)

public void min(Tree root)

while(root.left() != null)

root = root.left();

System.out.println(root.data());

b)

public void min(Tree root)

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)

public void min(Tree root)

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)

public void max(Tree root)

{
while(root.left() != null)

root = root.left();

System.out.println(root.data());

b)

public void max(Tree root)

while(root != null)

root = root.left();

System.out.println(root.data());

c)

public void max(Tree root)

while(root.right() != null)

root = root.right();

System.out.println(root.data());
}

d)

public void max(Tree root)

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)

while (root != NULL)

if (root.data() > n1 && root.data() > n2)

root = root.right();

else if (root.data() < n1 && root.data() < n2)

root = root.left();

else break;

System.out.println(root.data());

b)

public void lca(Tree root,int n1, int n2)

while (root != NULL)

if (root.data() > n1 && root.data() < n2)

root = root.left();

else if (root.data() < n1 && root.data() > n2)

root = root.right();

else break;

}
System.out.println(root.data());

c)

public void lca(Tree root,int n1, int n2)

while (root != NULL)

if (root.data() > n1 && root.data() > n2)

root = root.left();

else if (root.data() < n1 && root.data() < n2)

root = root.right();

else break;

System.out.println(root.data());

d)

public void lca(Tree root,int n1, int n2)

while (root != NULL)

if (root.data() > n1 && root.data() > n2)

root = root.left.left();

else if (root.data() < n1 && root.data() < n2)


root = root.right.right();

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.

11. Construct a binary search tree with the below information.

The preorder traversal of a binary search tree 10, 4, 3, 5, 11, 12.

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.

2. The balance factor of a node in a binary tree is defined as _____

a) addition of heights of left and right subtrees

b) height of right subtree minus height of left subtree

c) height of left subtree minus height of right subtree

d) height of right subtree minus one

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.

6. Which of following figures is a balanced binary tree?

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

d) both sets and priority queue

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?

a) insertion takes less time

b) deletion takes less time

c) searching takes less time

d) construction of the tree takes less time than 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).

11. AVL trees are more balanced than Red-black trees.

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

c) Red – Black 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.

4. Associative arrays can be implemented using __________

a) B-tree

b) A doubly linked list

c) A single linked list

d) A self balancing binary search 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.

6. Which of the following is a self – balancing binary search tree?

a) 2-3 tree

b) Threaded binary 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.

7. A self – balancing binary search tree can be used to implement ________

a) Priority queue

b) Hash table

c) Heap sort

d) Priority queue and 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

d) Red – Black 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”.

1. Which of the following is not a random tree?

a) Treap

b) Random Binary Tree

c) Uniform Spanning Tree

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.

2. Which process forms the randomized 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.

4. What is the expected depth of a node in a randomized binary search tree?

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).

7. What is the expected number of leaves in a randomized binary search tree?

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.

8. Is Treap a randomized tree.

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.

9. What is the probability of selecting a tree uniformly at random?

a) Equal to Catalan Number

b) Less Than Catalan Number

c) Greater than Catalan Number

d) Reciprocal of Catalan Number

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.

10. Is mathematical randomized tree can be generated using beta distribution.

a) True

b) False

View Answer

Answer: a

This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “AA
Tree”.

1. AA Trees are implemented using?

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.

2. Which of the following is the correct definition for a horizontal link?

a) connection between node and a child of equal levels

b) connection between two nodes

c) connection between two child nodes

d) connection between root node and leaf node


View Answer

Answer: a

Explanation: A horizontal link is a connection between a node and a child of equal levels.

3. How will you remove a left horizontal link in an AA-tree?

a) by performing right rotation

b) by performing left rotation

c) by deleting both the elements

d) by inserting a new element

View Answer

Answer: a

Explanation: A left horizontal link is removed by right rotation. A right horizontal link is removed by left
rotation.

4. What are the two different operations done in an AA-Tree?

a) shift and color

b) skew and split

c) zig and zag

d) enqueue and dequeue

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.

5. In an AA-tree, we process split first, followed by a skew.

a) True
b) False

View Answer

Answer: b

Explanation: In an AA-tree, skew is processed first followed by a split.

6. How many different shapes does maintenance of AA-Tree need to consider?

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?

a) Only right children can be red

b) Only left children can be red

c) Right children should strictly be black

d) There should be no left children

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.

8. Which of the following trees is similar to that of an AA-Tree?


a) Splay Tree

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.

9. What is the worst case analysis of an AA-Tree?

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).

10. AA-Trees makes more rotations than a red-black tree.

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

d) Jon Louis Bentley

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?

a) It should be less than or equal to that of its parent

b) It should be greater than that of its parent

c) It should be strictly less than that of its parent

d) The level should be equal to one

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?

1- Only right children can be red

2- Procedures are coded recursively

3- Instead of storing colors, the level of a node is stored

4- There should not be any left children

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

In the given figure, find ‘?’.

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

c) Both have an equal search time

d) It depends

View Answer
Answer: a
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “AVL Tree”.

1. What is an AVL tree?

a) a tree which is balanced and is a height balanced tree

b) a tree which is unbalanced and is a height balanced tree

c) a tree with three children

d) a tree with atmost 3 children

View Answer

Answer: a

Explanation: It is a self balancing tree with height difference atmost 1.

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

a) to avoid formation of skew trees

b) to save memory

c) to attain faster memory access

d) to simplify storing

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.

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

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

d) i is not a binary search tree

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.

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

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?

a) just build the tree with the given input

b) find the median of the set of elements given, make it as root and construct the tree

c) use trial and error

d) use dynamic programming to build the tree

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?

a) log(n) where n is the number of nodes

b) n where n is the number of nodes

c) 0 or 1

d) atmost 1

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).

8. Consider the pseudo code:

int avl(binarysearchtree root):


if(not root)

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.

avltree leftrotation(avltreenode z):

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.

10. Why to prefer red-black trees over AVL trees?

a) Because red-black is more rigidly balanced

b) AVL tree store balance factor in every node which costs space

c) AVL tree fails at scale

d) Red black is more efficient

View Answer

Answer: b

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Threaded Binary
Tree”.

1. What is a threaded binary tree traversal?

a) a binary tree traversal using stacks


b) a binary tree traversal using queues

c) a binary tree traversal using stacks and queues

d) a binary tree traversal without using stacks and queues

View Answer

Answer: d

Explanation: This type of tree traversal will not use stack or queue.

2. What are the disadvantages of normal binary tree traversals?

a) there are many pointers which are null and thus useless

b) there is no traversal which is efficient

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.

3. In general, the node content in a threaded binary tree is ________

a) leftchild_pointer, left_tag, data, right_tag, rightchild_pointer

b) leftchild_pointer, left_tag

c) leftchild_pointer, left_tag, right_tag, rightchild_pointer

d) leftchild_pointer, left_tag, data

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

c) they remain null

d) some other values randomly

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?

a) inorder, postorder, preorder traversals

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.

6. What are double and single threaded trees?

a) when both left, right nodes are having null pointers and only right node is null pointer respectively

b) having 2 and 1 node

c) using single and double linked lists

d) using heaps and priority queues


View Answer

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

a) inordersuccessor instead of inorderpredecessor must be done

b) code is correct

c) it is code for post order

d) it is code for pre order

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.

8. What is inefficient with the below threaded binary tree picture?

data-structure-questions-answers-threaded-binary-tree-q8

a) it has dangling pointers

b) nothing inefficient

c) incorrect threaded tree

d) space is being used more


View Answer

Answer: a

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Weight Balanced
Tree”.

1. What is a weight balanced tree?

a) A binary tree that stores the sizes of subtrees in nodes

b) A binary tree with an additional attribute of weight

c) A height balanced binary tree

d) A normal binary 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.

2. What are the applications of weight balanced tree?

a) dynamic sets, dictionaries, sequences, maps

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

a) key, left and right pointers, size

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.

4. The size value of various nodes in a weight balanced tree are

leaf – zero

internal node – size of it’s two children

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?

a) weight[n.left] >= a*weight[n] and weight[n.right] >= a*weight[n].

b) weight[n.left] >= a*weight[n.right] and weight[n.right] >= a*weight[n].

c) weight[n.left] >= a*weight[n.left] and weight[n.right] >= a*weight[n].

d) weight[n] is a non zero


View Answer

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

b) all basic operations

c) set intersection, set union and subset test

d) only insertion and deletion

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?

WeightBalanceTreeNode insert(int x, int wt, WeightBalanceTreeNode k) :

if (k == null)

k = new WeightBalanceTreeNode(x, wt, null, null)

else if (x < t.element) :

k.left = insert (x, wt, k.left)

if (k.left.weight < k.weight)

k = rotateWithRightChild (k)

else if (x > t.element) :

k.right = insert (x, wt, k.right)

if (k.right.weight < k.weight)

k = rotateWithLeftChild (k)

a) when x>t. element Rotate-with-left-child should take place and vice versa

b) the logic is incorrect

c) the condition for rotating children is wrong

d) insertion cannot be performed in weight balanced trees

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.

a) weight balanced and height balanced tree definations

b) height balanced and weight balanced tree definations

c) definations of weight balanced tree

d) definations of height balanced tree

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”.

1. What are splay trees?

a) self adjusting binary search trees

b) self adjusting binary trees

c) a tree with strings

d) a tree with probability distributions


View Answer

Answer: a

Explanation: Splay trees are height balanced, self adjusting BST’s.

2. Which of the following property of splay tree is correct?

a) it holds probability usage of the respective sub trees

b) any sequence of j operations starting from an empty tree with h nodes atmost, takes O(jlogh) time
complexity

c) sequence of operations with h nodes can take O(logh) time complexity

d) splay trees are unstable trees

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.

3. Why to prefer splay trees?

a) easier to program

b) space efficiency

c) easier to program and faster access to recently accessed items

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.

4. Is it true that splay trees have O(logn) amortized complexity ?

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.

5. What is a splay operation?

a) moving parent node to down of child

b) moving a node to root

c) moving root to leaf

d) removing leaf node

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.

6. Which of the following options is an application of splay trees?

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?

a) no there is no special usage

b) In real time it is estimated that 80% access is only to 20% data, hence most used ones must be easily
available

c) redblack and avl are not upto mark

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.

8. After the insertion operation, is the resultant tree a splay tee?

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.

9. What output does the below pseudo code produces?

Tree_node function(Tree_node x)

Tree_node y = x.left;

x.left = y.right;
y.right = x;

return y;

a) right rotation of subtree

b) left rotation of subtree

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.

10. What is the disadvantage of using splay trees?

a) height of a splay tree can be linear when accessing elements in non decreasing order.

b) splay operations are difficult

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”.

1. Which algorithm is used in the top tree data structure?

a) Divide and Conquer

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.

3. How many edges are present in path cluster?

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.

5. How many edges are present in Edge 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.

9. What is the time complexity for the initialization of top tree?

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.

11. Which property makes top tree a binary tree?

a) Nodes as Cluster

b) Leaves as Edges

c) Root is Tree Itself

d) All of the mentioned

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

d) All of the mentioned

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”.

1. Which of the following statements for a simple graph is correct?

a) Every path is a trail

b) Every trail is a path

c) Every trail is a path as well as every path is a trail

d) Path and trail have no relation

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.

2. In the given graph identify the cut vertices.

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

Explanation: After removing either B or C, the graph becomes disconnected.

3. For the given graph(G), which of the following statements is true?

data-structure-questions-answers-graph-q3

a) G is a complete graph
b) G is not a connected graph

c) The vertex connectivity of the graph is 2

d) The edge connectivity of the graph is 1

View Answer

Answer: c

Explanation: After removing vertices B and C, the graph becomes disconnected.

4. 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

d) Information given is insufficient

View Answer

Answer: b

Explanation: Number of ways in which every vertex can be connected to each other is nC2.

5. The given Graph is regular.

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.

7. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.

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

c) Must have no loops or multiple edges

d) Must have no multiple edges

View Answer

Answer: a

Explanation: A simple graph maybe connected or disconnected.

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.

11. Which of the following is true?

a) A graph may contain no edges and many vertices

b) A graph may contain many edges and no vertices

c) A graph may contain no edges and no vertices

d) A graph may contain no vertices and many edges

View Answer
Answer: b

Explanation: A graph must contain at least one vertex.

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

Explanation: The given statement is the definition of regular graphs.

15. Which of the following ways can be used to represent a graph?

a) Adjacency List and Adjacency Matrix

b) Incidence Matrix

c) Adjacency List, Adjacency Matrix as well as 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”.

1. Dijkstra’s Algorithm is used to solve _____________ problems.

a) All pair shortest path

b) Single source shortest path

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?

a) Max priority queue

b) Stack

c) Circular queue

d) Min priority queue

View Answer

3. What is the time complexity of Dijikstra’s algorithm?

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.

4. Dijkstra’s Algorithm cannot be applied on ______________

a) Directed and weighted graphs

b) Graphs having negative weight function

c) Unweighted graphs

d) Undirected and 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)

if(T[v].Dist + C(v,w) < T[w].Dist) {

Decrease(T[w].Dist to T[v].Dist +C(v,w));

T[w].path=v; }

b)

if(T[w].Known)

if(T[v].Dist + C(v,w) < T[w].Dist) {

Increase (T[w].Dist to T[v].Dist +C(v,w));

T[w].path=v; }

c)

if(!T[w].Known)

if(T[v].Dist + C(v,w) > T[w].Dist) {

Decrease(T[w].Dist to T[v].Dist +C(v,w);

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

6. How many priority queue operations are involved in Dijkstra’s Algorithm?

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 ___________

a) Total number of vertices

b) Total number of edges

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.

12. Given pseudo code of Dijkstra’s Algorithm.

1. //Initialise single source(G,s)

2. S=0

3. Q=V[G]

4. While Q != 0

5. Do u=extract-min(Q)

6. S=S union {u}

7. For each vertex v in adj[u]

8. Do relax(u,v,w)

What happens when while loop in line 4 is changed to while Q>1?

a) While loop gets executed for v times

b) While loop gets executed for v-1 times

c) While loop gets executed only once

d) While loop does not get executed

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.

13. Consider the following graph.

dijkstras-algorithm-questions-answers-q13

If b is the source vertex, what is the minimum cost to reach f vertex?

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

hence total cost 1+4+1=6.

14. In the given graph:

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

Hence the total cost is 5.

15. Dijkstra’s Algorithm is the prime example for ___________

a) Greedy algorithm

b) Branch and bound

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

c) brute force algorithm

d) divide and conquer 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.

3. Which bit is reserved as a parity bit in an ASCII set?

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.

6. In Huffman coding, data in a tree always occur?

a) roots

b) leaves

c) left sub trees

d) right sub trees

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.

10. An optimal code will always be present in a full tree.

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.

12. What is the running time of the Huffman encoding algorithm?

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”.

1. The most common hamming codes are a generalized version of?

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.

3. Why do we require hamming codes?

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.

6. What is the total block length ‘n’ of a Hamming code?

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.

7. What is the message length ‘k’ of a Hamming(7,4) code?

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.

8. What is the rate of hamming codes?

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.

9. A two-out-of-five code consists of _________

a) Two 0s and three 1s

b) Three 0s and two 1s

c) Four 0s and one 1s

d) One 0s and four 1s

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.

12. An Extended hamming code is also called as __________

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

Explanation: Total bits are computed as, 2m-1 = 28-1 =255.

Data bits are computed as 2m-m-1= 28-8-1= 247.

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

1. In a circular linked list

a) Components are all linked together in some sequential manner.

b) There is no beginning and no end.

c) Components are arranged hierarchically.

d) Forward and backward traversal within the list is permitted.

View Answer / Hide Answer

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

View Answer / Hide Answer

ANSWER: A
3. Which of the following operations is performed more efficiently by doubly linked list than by singly
linked list?

a) Deleting a node whose location in given

b) Searching of an unsorted list for a given item

c) Inverting a node after the node with given location

d) Traversing a list to process each node

View Answer / Hide Answer

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the last node of the linked list

a) I and II
b) I and III

c) I,II and III

d) I,II and IV

View Answer / Hide Answer

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the last node of the linked list

a) I and II

b) I and III

c) I,II and III

d) I,II and IV

View Answer / Hide Answer

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the end node of the linked list

a) I and II

b) I and III

c) I,II and III

d) I,II,III and IV

View Answer / Hide Answer

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

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the end node of the linked list

a) I and II

b) I and III

c) I,II and III

d) I,II,III and IV

View Answer / Hide Answer

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the end node of the linked list


a) I and II

b) I and III

c) I, II, III and IV

d) None

View Answer / Hide Answer

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?

i) Insertion at the front of the linked list

ii) insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the end node of the linked list

a) I and II

b) I and III

c) I, II and III

d) I,II,III and IV

View Answer / Hide Answer


ANSWER: D

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

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

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?

a) Singly linked list


b) Doubly linked list

c) Circular doubly linked list

d) Array implementation of list

View Answer / Hide Answer

ANSWER: C

16. Consider the following definition in c programming language

struct node

int data;

struct node * next;

typedef struct node NODE;

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 / Hide Answer

ANSWER: A

17. A variant of linked list in which last node of the list points to the first node of the list is?

a) Singly linked list

b) Doubly linked list

c) Circular linked list

d) Multiply linked list

View Answer / Hide Answer

ANSWER: C

18. In doubly linked lists, traversal can be performed?

a) Only in forward direction

b) Only in reverse direction


c) In both directions

d) None

View Answer / Hide Answer

ANSWER: C

19. What kind of linked list is best to answer question 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

View Answer / Hide Answer

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.

b) It is not possible to add a node at the end of the list.

c) It is difficult to traverse the list as the pointer of the last node is now not NULL

d) All of above

View Answer / Hide Answer

ANSWER: C

21. A variant of the linked list in which none of the node contains NULL pointer is?

a) Singly linked list

b) Doubly linked list

c) Circular linked list

d) None

View Answer / Hide Answer

ANSWER: C

22. In circular linked list, insertion of node requires modification of?


a) One pointer

b) Two pointer

c) Three pointer

d) None

View Answer / Hide Answer

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

c) Linked list pointers always maintain the list in ascending order

d) The linked list data structure provides an efficient way to find kth element in the list

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

ANSWER: D

MCQs on Tree with answers


1. The height of a BST is given as h. Consider the height of the tree as the no. of edges in the longest
path from root to the leaf. The maximum no. of nodes possible in the tree is?

a) 2h-1 -1

b) 2h+1 -1

c) 2h +1

d) 2h-1 +1

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

ANSWER: B
5. Which of the following statement about binary tree is CORRECT?

a) Every binary tree is either complete or full

b) Every complete binary tree is also a full binary tree

c) Every full binary tree is also a complete binary tree

d) A binary tree cannot be both complete and full

View Answer / Hide Answer

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?

a) 2, 252, 401, 398, 330, 344, 397, 363

b) 924, 220, 911, 244, 898, 258, 362, 363

c) 925, 202, 911, 240, 912, 245, 258, 363

d) 2, 399, 387, 219, 266, 382, 381, 278, 363

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer


ANSWER: B

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 / Hide Answer

ANSWER: C

10. A 2-3 is a tree such that

a) All internal nodes have either 2 or 3 children

b) All path from root to leaves have the same length

The number of internal nodes of a 2-3 tree having 9 leaves could be


a) 4

b) 5

c) 6

d) 7

View Answer / Hide Answer

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

View Answer / Hide Answer

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

View Answer / Hide Answer

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

c) n-1 leaf nodes

d) n-1 internal nodes

View Answer / Hide Answer

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))

View Answer / Hide Answer

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

View Answer / Hide Answer

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

b) Binary search tree

c) Max-heap

d) Min-heap

View Answer / Hide Answer

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)

View Answer / Hide Answer

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)

View Answer / Hide Answer

ANSWER: B

19. The minimum number of elements in a heap of height h is

a) 2h+1

b) 2h

c) 2h -1

d) 2h-1

View Answer / Hide Answer


ANSWER: B

20. The maximum number of elements in a heap of height h is

a) 2h+1 -1

b) 2h

c) 2h -1

d) 2h -1

View Answer / Hide Answer

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

View Answer / Hide Answer


ANSWER: B

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?

a) Binary search tree

b) Threaded binary tree

c) Complete binary tree

d) Max-heap

View Answer / Hide Answer

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:

50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24

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)

View Answer / Hide Answer

ANSWER: B

1. An alphabet consist of the letters A, B, C and D. The probability of occurrence is


P(A) = 0.4, P(B) = 0.1, P(C) = 0.2 and P(D) = 0.3. The Huffman code is

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

2. The basic idea behind Huffman coding is to

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

3. Huffman coding is an encoding algorithm used for

A. ? lossless data compression

B. X files greater than 1 Mbit

C. X lossy data compression

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

A. :-) 1.9 bit

B. X 2.0 bit

C. X 2.1 bit

D. ? 8.0 bit

6. The idea with wavelets is to represent a complicated function by

A. :-) simple basic functions

B. ? square functions

C. ? sinus functions

D. ? lines

7. Down sampling is to make a digital image file smaller by

A. :-) removing pixels

B. ? adding pixels

C. ? removing noise

D. ? adding noise

8. In a typical picture, most pixels will be

A. X bright

B. :-) very similar to their neighbours

C. ? equal

D. ? very different to their neighbours


9. Without losing quality, JPEG-2000 can achieve compression ratios of

A. ? 2000:1

B. X 2:1

C. :-) 200:1

D. ? 20:1

10. The best visual compression quality is achieved using

A. ? Wavelets

B. X Dolby

C. X Fourier transform

D. X

Basic Computer Knowledge Test Questions and Answers

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

B.) inorder, postorder, preorder traversals

C.) inorder

D.) postorder

Answer: Option 'B'

inorder, postorder, preorder traversals


2.

What may be the content of a node in threaded binary tree?

A.) leftchild_pointer, left_tag, data

B.) leftchild_pointer, left_tag, data, right_tag, rightchild_pointer

C.) leftchild_pointer, left_tag

D.) leftchild_pointer, left_tag, right_tag, rightchild_pointer

Answer: Option 'B'

leftchild_pointer, left_tag, right_tag, rightchild_pointer

It contains additional 2 pointers over normal binary tree node structure.

3.

What are double and single threaded trees?

A.) when both left, right nodes are having null pointers and only right node is null pointer respectively

B.) having 2 and 1 node

C.) using single and double linked lists

D.) using heaps and priority queues

Answer: Option 'A'

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?

A.) a binary tree traversal without using stacks and queues

B.) a binary tree traversal using stacks

C.) a binary tree traversal using queues

D.) a binary tree traversal using stacks and queues

Answer: Option 'A'

a binary tree traversal without using stacks and queues

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

A.) it is code for pre order

B.) inordersuccessor instead of inorderpredecessor must be done

C.) code is correct

D.) it is code for post order

Answer: Option 'B'

inordersuccessor instead of inorderpredecessor must be done


Free RRB NTPC Free Online Mock Test Series in Telugu

Free RRB NTPC Free Online Mock Test Series in Telugu

6.

What are the disadvantages of normal binary tree traversals?

A.) there are many pointers which are null and thus useless

B.) there is no traversal which is efficient

C.) improper traversals

D.) complexity in implementing

Answer: Option 'A'

there are many pointers which are null and thus useless

7.

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

C.) they remain null

D.) some other values randomly

Answer: Option 'A'

1. Which of the following statements for a simple graph is correct?

A. Every path is a trail


B. Every trail is a path

C. Every trail is a path as well as every path is a trail

D. None of the mentioned

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?

A. In adjacency list representation, space is saved for sparse graphs.


B. DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take
O(V^2) time in adjacency matrix representation. Here is V and E are number of vertices and edges
respectively.

C. Adding a vertex in adjacency list representation is easier than adjacency matrix representation.

D. All of the above

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

B. Depends on the number of vertices

C. Is independent of both the number of edges and vertices

D. It depends on both the number of edges and vertices

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

D. Information given is insufficient

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

C. Must have no loops or multiple edges

D. All of the mentioned

View Answer

Ans : A

Explanation: A simple graph maybe connected or disconnected.

15. Which of the following is true?

A. A graph may contain no edges and many vertices


B. A graph may contain many edges and no vertices

C. A graph may contain no edges and no vertices

D. None of the mentioned

View Answer

Ans : B

Explanation: A graph must contain at least one vertex.

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

D. None of the mentioned

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.

19. Which of the following ways can be used to represent a graph?

A. Adjacency List and Adjacency Matrix

B. Incidence Matrix

C. Adjacency List, Adjacency Matrix as well as Incidence Matrix


D. None of the mentioned

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.

2. Which of the following is a true about Binary Trees?

A. Every binary tree is either complete or full.

B. Every complete binary tree is also a full binary tree.

C. Every full binary tree is also a complete binary tree.

D. No binary tree is both complete and full.

E. None of the above

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.

3. A Binary Tree can have

A. Can have 2 children

B. Can have 1 children

C. Can have 0 children

D. All of the above

View Answer

Ans : D
Explanation: A Binary Tree can have 0, 1, 2 children

4.Which of the following is not an advantage of trees?

A. Hierarchical structure

B. Faster search

C. Router algorithms

D. Undo/Redo operations in a notepad

View Answer

Ans : D

Explanation: This is an application of stack.

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.

7.Height of Height of a binary tree is

A. MAX( Height of left Subtree, Height of right subtree)+1

B. MAX( Height of left Subtree, Height of right subtree)

C. MAX( Height of left Subtree, Height of right subtree)-1

D. None of the above

View Answer

Ans : A

Explanation: Height of Height of a binary tree is MAX( Height of left Subtree, Height of right subtree)+1.

8. Which of the following options is an application of splay trees ?


A. cache Implementation

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?

void fun1(struct node* head)

if(head == NULL)

return;

fun1(head->next);

printf("%d ", head->data);

A. Prints all nodes of linked lists

B. Prints all nodes of linked list in reverse order

C. Prints alternate nodes of Linked List

D. Prints alternate nodes in reverse order

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)

D. None of the mentioned

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

void fun(struct node* start)

if(start == NULL)

return;

printf("%d ", start->data);

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.

6. What is the functionality of the following piece of code?

public int function(int data)

Node temp = head;

int var = 0;

while(temp != null)

if(temp.getData() == data)

return var;

}
var = var+1;

temp = temp.getNext();

return Integer.MIN_VALUE;

A. Find and delete a given element in the list

B. Find and return the given element in the list

C. Find and return the position of the given element in the list

D. Find and insert a new element in the list

View Answer

Ans : C

Explanation: When temp is equal to data, the position of data is returned.

7. 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

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.

9. Which of these is an application of linked lists?

A. To implement file systems

B. For separate chaining in hash-tables

C. To implement non-binary trees

D. All of the mentioned

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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the last node of the linked list

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)

D. None of the mentioned

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?

A. Singly linked list

B. Doubly linked list

C. Circular doubly linked list

D. Array implementation of list

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;

struct node * next;

typedef struct node NODE;

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

Explanation: As it represents the right way to create a node.

16. What kind of linked list is best to answer question 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

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

Explanation: It cannot be implemented using linked lists.

18. Linked list is considered as an example of ___________ type of memory allocation.

A. Dynamic

B. Static

C. Compile time

D. None of the mentioned

View Answer

Ans : A

Explanation: As memory is allocated at the run time.

19. In Linked List implementation, a node carries information regarding

A. Data

B. Link

C. Data and Link

D. None of the mentioned


View Answer

Ans : B

Explanation: None.

20. Linked list data structure offers considerable saving in

A. Computational Time

B. Space Utilization

C. Space Utilization and Computational Time

D. None of the mentioned

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.

1) The operation of processing each element in the list is known as ……

A. sorting

B. merging

C. inserting

D. traversal

2) Another name for the directed graph is ……….

A. Direct graph
B. Digraph

C. Dir-graph

D. Digraph

3) Binary trees with threads are called as …….

A. Threaded trees

B. Pointer trees

C. Special trees

D. Special pointer 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

5) In Binary trees, nodes with no successor are called ……

A. End nodes

B. Terminal nodes

C. Final nodes

D. Last nodes

6) A connected graph T without any cycles is called ……..

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

8) A connected graph T without any cycles is called a ……..

A. A tree graph

B. Free tree

C. A tree d

D. All of the above

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

10) In a graph if E=(u,v) means ……

A. u is adjacent to v but v is not adjacent to u

B. e begins at u and ends at v

C. u is processor and v is the successor

D. both b and c
Read Also: Interview Questions on Stack and Queue in Data Structure set-2

11) Sequential representation of binary tree uses ……..

A. Array with pointers

B. Single linear array

C. Two-dimensional arrays

D. Three-dimensional arrays

12) In a graph, if e=[u,v], Then u and v are called ……..

A. Endpoints of e

B. Adjacent nodes

C. Neighbors

D. All of the above

13) TREE[1]=NULL indicates the tree is ……..

A. Overflow

B. Underflow

C. Empty

D. Full

14) A binary tree whose every node has either zero or two children is called …….

A. complete binary tree

B. binary search tree

C. extended binary tree


D. data structure

15) Linked representation of binary tree needs ……… parallel arrays.

A. 4

B. 2

C. 3

D. 5

16) The depth of the complete binary tree is given by ……

A. Dn = n log2n

B. Dn= n log2n+1

C. Dn = log2n

D. Dn = log2n+1

17) In a 2-tree, nodes with 0 children are called …………

A. Exterior node

B. Outside node

C. Outer node

D. External node

18) Which indicates pre-order traversal?

A. Left sub-tree, Right sub-tree and root

B. Right sub-tree, Left sub-tree and root

C. Root, Left sub-tree, Right sub-tree

D. Right sub-tree, root, Left sub-tree


19) In extended-binary tree nodes with 2 children are called ……..

A. Interior node

B. Domestic node

C. Internal node

D. Inner node

20) A terminal node in a binary tree is called …………

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

8) D. All of the above

9) B. Predecessor

10) D. both b and c


11) A. Array with pointers

12) D. All of the above

13) C. Empty

14) C. extended binary tree

15) C. 3

16) D. Dn = log2n+1

17) D. External node

18) C. Root, Left sub-tree, Right sub-tree

19) C. Internal node

20) B. Leaf

Question: 1

Which of the following data structure is more appropriate to represent a heap?

(A) Two-dimensional array

(B) Doubly linked list

(C) Linear Array

(D) Linked list

Ans: C

Linear Array
Question: 2

Minimum number of fields in each node of a doubly linked list is ____

(A) 2

(B) 3

(C) 4

(D) None of the above

Ans: B

Question: 3

A graph in which all vertices have equal degree is known as ____

(A) Complete graph

(B) Regular graph


(C) Multi graph

(D) Simple graph

Ans: A

Complete graph

Question: 4

A vertex of in-degree zero in a directed graph is called a/an

(A) Root vertex

(B) Isolated vertex

(C) Sink

(D) Articulation point

Ans: C

Sink

Question: 5
A graph is a tree if and only if graph is

(A) Directed graph

(B) Contains no cycles

(C) Planar

(D) Completely connected

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).e-n+1

2. Minimum number of spanning tree in a connected graph is

a. n
b. n(n - 1)

c. 1

d. 0

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).1

3. Find the odd out

a. Prim's Minimal Spanning Tree Algorithm

b. Kruskal's Minimal Spanning Tree Algorithm

c. Floyd-Warshall's All pair shortest path Algorithm

d. Dijkstra's Minimal Spanning Tree Algorithm

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Floyd-Warshall's All pair shortest path Algorithm

4. The minimum number of edges required to create a cyclid graph of n vertices is

a. n

b. n+1

c. n-1

d. 2n

View Answer Report Discuss Too Difficult! Search Google

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)

b. Ο(|V| log |V|)

c. Ο(|E|+|V| log |V|)

d. None of these

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Ο(|E|+|V| log |V|)

6. Maximum degree of any vertex in a simple graph of vertices n is

a. 2n - 1

b. n

c. n+1

d. n-1

View Answer Report Discuss Too Difficult! Search Google

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)

d. Ο(log (log n))

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).Ο(log (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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Strongly Connected

9. State True of False.

i) Network is a graph that has weights or costs associated with it.

ii) An undirected graph which contains no cycles is called a forest.

iii) A graph is said to be complete if there is no edge between every pair of vertices.

a. True, False, True

b. True, True, False

c. True, True, True

d. False, True, True

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).True, True, False

10. State True or False.

i) An undirected graph which contains no cycles is called forest.

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).

11. A graph is said to be ……………… if the vertices can be sp


there are no edges between two vertices of V1 or two verti

a. Partite

b. Bipartite

c. Rooted

d. Bisects

View Answer Report Discuss Too Difficult! Search Google

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

d. graph node, edges

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).vertices, edges

13. A ……….. is a graph that has weights of costs associated with its edges.

a. Network

b. Weighted graph

c. Both A and B

d. None of the above


View Answer Report Discuss Too Difficult! Search Google

Answer: (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

d. Direction oriented tree

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Directed tree

15. In a graph if e=[u, v], Then u and v are called

a. endpoints of e

b. adjacent nodes

c. neighbors

d. all of above

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).all of above

16. A connected graph T without any cycles is called

a. a tree graph

b. free tree

c. a tree

d. All of above
View Answer Report Discuss Too Difficult! Search Google

Answer: (d).All of above

17. In a graph if e=(u, v) means

a. u is adjacent to v but v is not adjacent to u

b. e begins at u and ends at v

c. u is processor and v is successor

d. both b and c

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).both b and c

18. If every node u in G is adjacent to every other node v in G, A graph is said to be

a. isolated

b. complete

c. finite

d. strongly connected

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).complete

19. Other name for directed graph is ..........

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).

21. A connected graph T without any cycles is called ........

a. free graph

b. no cycle graph

c. non cycle graph

d. circular graph

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).free graph

22. In a graph if E=(u,v) means ......

a. u is adjacent to v but v is not adjacent to u

b. e begins at u and ends at v

c. u is processor and v is successor

d. both b and c

View Answer Report Discuss Too Difficult! Search Google


Answer: (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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).I only

24. Let A be an adjacency matrix of a graph G. The ij th entry in the matrix Ak , gives

a. The number of paths of length K from vertex Vi to vertex Vj.

b. Shortest path of K edges from vertex Vi to vertex Vj.

c. Length of a Eulerian path from vertex Vi to vertex Vj.

d. Length of a Hamiltonian cycle from vertex Vi to vertex Vj.

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Shortest path of K edges from vertex Vi to vertex Vj.

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

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).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

c. more than (n+1)/2

d. more than n(n-1)/2

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).more than n(n-1)/2

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

d. None of the above

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

31. For an undirected graph G with n vertices and e edges, the


vertex is

a. ne

b. 2n

c. 2e
d. e^n

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).2e

32. A complete graph can have ...............

a. n^2 spanning trees

b. n^(n-2) spanning trees

c. n^(n+1) spanning trees

d. n^n spanning trees

View Answer Report Discuss Too Difficult! Search Google

Answer: (b). n^(n-2) spanning trees

33. Graph traversal is different from a tree traversal, because:

a. trees are not connected

b. graphs may have loops

c. trees have root

d. None of these

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).trees have root

34. The number of edges in a simple, n-vertex, complete graph is

a. n*(n-2)

b. n*(n-1)

c. n*(n-1)/2
d. n*(n-1)*(n-2)

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).n*(n-1)/2

35. Graphs are represented using ............

a. Adjacency tree

b. Adjacency linked list

c. Adjacency graph

d. Adjacency queue

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Adjacency linked list

36. The spanning tree of connected graph with 10 vertices contains ..............

a. 9 edges

b. 11 edges

c. 10 edges

d. 9 vertices

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).9 edges

37. If locality is a concern, you can use ................ to traverse the graph.

a. Breadth First Search

b. Depth First Search

c. Either BFS or DFS


d. None of these

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Depth First Search

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Floyd'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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).

41. The minimum number of edges in a connected cyclic graph

a. n

b. n+1

c. n-1

d. none of the above

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).n

42. The number of edges in a regular graph of degree d and n vertices is

a. nd

b. n+d

c. nd/2

d. maximum of n,d

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).nd/2

43. In the given graph identify the cut vertices.


a. B and E

b. C and D

c. A and E

d. C and B

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).C and B

44. For the given graph(G), which of the following statements is true?
a. G is a complete graph

b. G is not a connected graph

c. The vertex connectivity of the graph is 2

d. The edge connectivity of the graph is 1

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).The vertex connectivity of the graph is 2

45. The given Graph is regular.

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).3

47. Which of the following graphs are isomorphic to each other?


a. fig 1 and fig 2

b. fig 2 and fig 3

c. fig 1 and fig 3

d. fig 1, fig 2 and fig 3

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).fig 1, fig 2 and fig 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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).A-C

49. What would be the DFS traversal of the given Graph?


a. ABCED

b. AEDCB

c. EDCBA

d. ADECB

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

51. Determine the longest string which is described by the give

a. BATS

b. BOATS

c. BOT

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).BATS

52. Which of the following statements for a simple graph is correct?

a. Every path is a trail

b. Every trail is a path


c. Every trail is a path as well as every path is a trail

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Every path is a trail

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

d. Information given is insufficient

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).False

55. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.

a. 15

b. 3
c. 1

d. 11

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

c. Must have no loops or multiple edges

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Must be connected

58. What is the maximum number of edges in a bipartite graph having 10 vertices?

a. 24

b. 21
c. 25

d. 16

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).25

59. Which of the following is true?

a. A graph may contain no edges and many vertices

b. A graph may contain many edges and no vertices

c. A graph may contain no edges and no vertices

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).A graph may contain many edges and no vertices

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

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

61. For which of the following combinations of the degrees of v


be eulerian?

a. 1,2,3

b. 2,3,4

c. 2,4,5
d. 1,3,5

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Regular Graph

63. Which of the following ways can be used to represent a graph?

a. Adjacency List and Adjacency Matrix

b. Incidence Matrix

c. Adjacency List, Adjacency Matrix as well as Incidence Matrix

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Adjacency List, Adjacency Matrix as well as 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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).6

66. Adjacency matrix of all graphs are symmetric.

a. False

b. True

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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. Depends on the number of edges

b. Depends on the number of vertices

c. Is independent of both the number of edges and vertices


d. It depends on both the number of edges and vertices

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Is independent

71. In the given connected graph G, what is the value of rad(G

a. 2, 3

b. 3, 2

c. 2, 2

d. 3, 3

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).2, 3

72. Which of these adjacency matrices represents a simple graph?

a. [ [1, 0, 0], [0, 1, 0], [0, 1, 1] ]

b. [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ]

c. [ [0, 0, 1], [0, 0, 0], [0, 0, 1] ]

d. [ [0, 0, 1], [1, 0, 1], [1, 0, 0] ]

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).[ [0, 0, 1], [1, 0, 1], [1, 0, 0] ]

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).x=5, y=3

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

View Answer Report Discuss Too Difficult! Search Google

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>

using namespace std;

int cur=0;
int G[10][10];

bool visited[10];

deque <int> q;

void fun(int n);

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++)

if(G[cur][j]==1 && !visited[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

View Answer Report Discuss Too Difficult! Search Google

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>

using namespace std;

int G[10][10];

void fun(int n);

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--;
}

a. All Fully Connected Graphs

b. All Empty Graphs

c. All Bipartite Graphs

d. None of the Mentioned

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).False

80. The column sum in an incidence matrix for a simple graph is __________

a. depends on number of edges

b. always greater than 2

c. equal to 2

d. equal to the number of edges

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).

81. What are the dimensions of an incidence matrix?

a. Number of edges*number of edges

b. Number of edges*number of vertices

c. Number of vertices*number of vertices

d. None of the mentioned statements

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Number of edges*number of vertices

82. The column sum in an incidence matrix for a directed graph having no self loop is __________

a. 0
b. 1

c. 2

d. equal to the number of edges

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).True

85. If a connected Graph (G) contains n vertices what would be the rank of its incidence matrix?

a. n-1

b. values greater than n are possible

c. values less than n-1 are possible

d. insufficient Information is given

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).n-1

86. A Graph Structured Stack is a _____________

a. Undirected Graph

b. Directed Graph

c. Directed Acyclic Graph

d. Regular Graph

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Directed Acyclic 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

a. Source – 1, 8 Sink – 7,4


b. Source – 1 Sink – 8,4

c. Source – 1, 8 Sink – 4

d. None of the Mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Source – 1, 8 Sink – 4

88. Graph Structured Stack finds its application in _____________

a. Bogo Sort

b. Tomita’s Algorithm

c. Todd–Coxeter algorithm

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Tomita’s 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

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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

ii) Directed, no weight


iii) Directed, weighted

iv) Undirected, weighted

a. ii iii i iv

b. i iii ii iv

c. iv iii i ii

d. i ii iii iv

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).ii iii i 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)

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).O(E)

95. Complete the given snippet of code for the adjacency list representation of a weighted directed graph.
class neighbor

int vertex, weight;

____ next;

}
class vertex

string name;

_____ adjlist;

vertex adjlists[101];

a. vertex, vertex

b. neighbor, vertex

c. neighbor, neighbor

d. vertex, neighbor

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).neighbor, neighbor

96. In which case adjacency list is preferred in front of an adjacency matrix?

a. Dense graph

b. Sparse graph

c. Adjacency list is always preferred

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Sparse graph


97. To create an adjacency list C++’s map container can be used.

a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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];

void addEdge(int i,int j,int weigh)

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)

View Answer Report Discuss Too Difficult! Search Google


99. Given a plane graph, G having 2 connected component, having 6 vertices, 7 edges and 4 regions. What will b
components?

a. 1

b. 2

c. 3

d. 4

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).

101. How many of the following statements are correct?


i) All cyclic graphs are complete graphs.

ii) All complete graphs are cyclic graphs.

iii) All paths are bipartite.

iv) All cyclic graphs are bipartite.

v) There are cyclic graphs which are complete.

a. 1

b. 2

c. 3
d. 4

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).2

102. All paths and cyclic graphs are bipartite graphs.

a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).n-2

104. All trees with n vertices consists of n-1 edges.

a. True

b. False

c. May be
d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Tightly 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

View Answer Report Discuss Too Difficult! Search Google

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)

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).O(V*V*V)

110. All Graphs have unique representation on paper.

a. True

b. False

c. May be
d. Can't say

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

111. Assuming value of every weight to be greater than 10, in w


shortest path of a directed weighted graph from 2 vertices

a. add all values by 10

b. subtract 10 from all the values

c. multiply all values by 10

d. in both the cases of multiplying and adding by 10

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).multiply all values by 10

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).56

113. What would be the value of the distance matrix, after the execution of the given code?
#include <bits/stdc++.h>

#define INF 1000000

int graph[V][V] = { {0, 7, INF, 4},


{INF, 0, 13, INF},

{INF, INF, 0, 12},

{INF, INF, INF, 0}

};

int distance[V][V], i, j, k;

for (i = 0; i < V; i++)

for (j = 0; j < V; j++)

distance[i][j] = graph[i][j];

for (k = 0; k < V; k++)

for (i = 0; i < V; i++)

for (j = 0; j < V; j++)

if (distance[i][k] + distance[k][j] < distance[i][j])

distance[i][j] = distance[i][k] + distance[k][j];

return 0;

a)
{

{0, 7, INF, 4},

{INF, 0, 13, INF},

{INF, INF, 0, 12},

{INF, INF, INF, 0}

};

b)

{0, 7, 20, 24},

{INF, 0, 13, 25},

{INF, INF, 0, 12},

{INF, INF, INF, 0}

};

c)

{0, INF, 20, 24},

{INF, INF, 13, 25},

{INF, INF, 0, 12},

{INF, INF, INF, 0}


{INF, 0, 13, 25},

{INF, INF, 0, 12},

{24, INF, INF, 0}

};

d) None of the mentioned

a. a

b. b

c. c

d. d

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

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

b. No Hamiltonian path is possible

c. Exactly 1 Hamiltonian path is possible

d. Given information is insufficient to comment anything

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).No Hamiltonian path is 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>

using namespace std;

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

View Answer Report Discuss Too Difficult! Search Google

120. Which of the given statement is true?


a. All the Cyclic Directed Graphs have topological sortings

b. All the Acyclic Directed Graphs have topological sortings

c. All Directed Graphs have topological sortings

d. None of the given statements is true

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).

121. For any two different vertices u and v of an Acyclic Directed


is also reachable from v?

a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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

b. Will always be zero

c. Will always be greater than zero

d. May be zero or greater than zero

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).Will always be zero

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

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).String Matching

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)

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).O(S1)

125. In which of the following case does a Propositional Directed Acyclic Graph is used for?

a. Representation of Boolean Functions

b. String Matching

c. Searching

d. Sorting of number

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Representation of Boolean Functions

126. Every Binary Decision Diagram is also a Propositional Directed Acyclic Graph.
a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).True

128. Given Adjacency matrices determine which of them are PseudoGraphs?

i) {{1,0} {0,1}}

ii) {{0,1}{1,0}}

iii) {{0,0,1}{0,1,0}{1,0,0}}

a. only i)

b. ii) and iii)

c. i) and iii)

d. i) ii) and iii)

View Answer Report Discuss Too Difficult! Search Google


Answer: (c).i) and iii)

129. All undirected Multigraphs contain eulerian cycles.

a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

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

d. Information given is insufficient

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

131. Which of the following statement is true.

a. There exists a Simple Graph having 10 vertices such that m


and maximum degree is 9

b. There exists a MultiGraph having 10 vertices such that min


maximum degree is 9

c. There exists a MultiGraph as well as a Simple Graph havin


degree of the graph is 0 and maximum degree is 9

d. None of the mentioned


View Answer Report Discuss Too Difficult! Search Google

Answer: (b).There exists a MultiGraph having 10 vertices such that minimum degree of the graph is 0 and maximum

132. Given Adjacency matrices determine which of them are PseudoGraphs?


i) {{1,0} {0,1}}

ii) {{0,1}{1,0}}

iii) {{0,0,1}{0,1,0}{1,0,0}}

a. only i)

b. ii) and iii)

c. i) and iii)

d. i) ii) and iii)

View Answer Report Discuss Too Difficult! Search Google

Answer: (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

View Answer Report Discuss Too Difficult! Search Google

Answer: (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?

a. V = {v1, v2, v3} E = {e1, e2} = {{v2, v3} {v1, v3}}


b. V = {v1, v2} E = {e1} = {{v1, v2}}

c. V = {v1, v2, v3} E = {e1, e2, e3} = {{v2, v3}{v3, v1}{v2, v1}}

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).All of the mentioned

135. What would be the Incidence Matrix of the given HyperGraph?


V = {x,y,z} E = {{x,y}{y}{x,z}{z,y}}

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}}

d. None of the Mentioned

View Answer Report Discuss Too Difficult! Search Google

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).3,2,2,2,1,1

137. MultiGraphs having self-loops are called PseudoGraphs?

a. True

b. False

c. May be

d. Can't say

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).True

138. Binary Decision Diagram is a type of __________

a. Multigraph

b. Cyclic Graph

c. Directed Acyclic Graph

d. Directed Acyclic Word Graph

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Directed Acyclic Graph

139. In which of the following case does a Binary Decision Diagram is used for?

a. Representation of Boolean Functions

b. String Matching

c. Searching
d. Sorting of number

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Representation of Boolean Functions

140. In a Binary Decision Diagram, how many types of terminal exists?

a. 1

b. 2

c. 3

d. 4

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

141. In a Binary Decision Diagrams 0 values by a _________ lin


represented by a _________ line.

a. dashed, bold

b. bold, dashed

c. dotted, bold

d. dotted, dashed

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).dotted, bold

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

View Answer Report Discuss Too Difficult! Search Google

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. AND, AND, average

b. AND, OR, longest

c. OR, OR, shortest

d. AND, AND, longest

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).AND, AND, longest

145. And Inverter Graph is a type of __________

a. Multigraph

b. Cyclic Graph

c. Directed Acyclic Graph


d. Directed Acyclic Word Graph

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Directed Acyclic 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

View Answer Report Discuss Too Difficult! Search Google

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

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).All of the mentioned

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Pre-order Traversal

149. Time Complexity of DFS is? (V – number of vertices, E – number of edges)

a. O(V + E)

b. O(V)

c. O(E)

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

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

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).

152. A person wants to visit some places. He starts from a verte


vertex till it finishes from one vertex, backtracks and then e
vertex. What algorithm he should use?

a. Depth First Search

b. Breadth First Search


c. Trim’s algorithm

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Depth First Search

153. What can be the applications of Depth First Search?

a. For generating topological sort of a graph

b. For generating Strongly Connected Components of a directed graph

c. Detecting cycles in the graph

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).All of the mentioned

154. When the Depth First Search of a graph is unique?

a. When the graph is a Binary Tree

b. When the graph is a Linked List

c. When the graph is a n-ary Tree

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).When the graph is a Linked List

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).Can be anything

156. In Depth First Search, how many times a node is visited?

a. Once

b. Twice

c. Equivalent to number of indegree of the node

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Equivalent to number of indegree of the node

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).Level-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)

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (a).O(V + E)

159. The Breadth First Search traversal of a graph will result into?

a. Linked List

b. Tree

c. Graph with back edges

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

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?

a. Depth First Search

b. Breadth First Search

c. Trim’s algorithm

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).

161. What can be the applications of Breadth First Search?

a. Finding shortest path between two nodes

b. Finding bipartiteness of a graph


c. GPS navigation system

d. All of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (d).All of the mentioned

162. When the Breadth First Search of a graph is unique?

a. When the graph is a Binary Tree

b. When the graph is a Linked List

c. When the graph is a n-ary Tree

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

Answer: (b).When the graph is a Linked List

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

View Answer Report Discuss Too Difficult! Search Google

Answer: (c).At most 1

164. In BFS, how many times a node is visited?

a. Once
b. Twice

c. equivalent to number of indegree of the node

d. None of the mentioned

View Answer Report Discuss Too Difficult! Search Google

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”.

1. Process of inserting an element in stack is called ____________


a) Create
b) Push
c) Evaluation
d) Pop
Answer: b
2. Process of removing an element from stack is called __________
a) Create
b) Push
c) Evaluation
d) Pop
Answer: d
3. In a stack, if a user tries to remove an element from an empty stack it is called
_________
a) Underflow
b) Empty collection
c) Overflow
d) Garbage Collection
Answer: a
4. Pushing an element into stack already having five elements and stack size of 5, then
stack becomes ___________
a) Overflow
b) Crash
c) Underflow
d) User flow
Answer: a
5. Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one
Answer: d
6. Which of the following is not the application of stack?
a) A parentheses balancing program
b) Tracking of local variables at run time
c) Compiler Syntax Analyzer
d) Data Transfer between two asynchronous process
Answer: d
7. Consider the usual algorithm for determining whether a sequence of parentheses is
balanced. The maximum number of parentheses that appear on the stack AT ANY
ONE TIME when the algorithm analyzes: (()(())(()))?
a) 1
b) 2
c) 3
d) 4 or more
Answer: c
8. Consider the usual algorithm for determining whether a sequence of parentheses is
balanced. Suppose that you run the algorithm on a sequence that contains 2 left
parentheses and 3 right parentheses (in some order). The maximum number of
parentheses that appear on the stack AT ANY ONE TIME during the computation?
a) 1
b) 2
c) 3
d) 4 or more
Answer: b
9. What is the value of the postfix expression 6 3 2 4 + – *?
a) 1
b) 40
c) 74
d) -18
Answer: d
10. Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual
stack algorithm to convert the expression from infix to postfix notation. The maximum
number of symbols that will appear on the stack AT ONE TIME during the
conversion of this expression?
a) 1
b) 2
c) 3
d) 4
Answer: d
This set of Data Structure Interview Questions and Answers focuses on “Stack
Operations – 2”.
1. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
a) AB+ CD*E – FG /**
b) AB + CD* E – F **G /
c) AB + CD* E – *F *G /
d) AB + CDE * – * F *G /
Answer: c

2. The data structure required to check whether an expression contains balanced


parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree
Answer: a
3. What data structure would you mostly likely see in a non recursive
implementation of a recursive algorithm?
a) Linked List
b) Stack
c) Queue
d) Tree
Answer: b
4. The process of accessing data stored in a serial access memory is similar to
manipulating data on a ________
a) Heap
b) Binary Tree
c) Array
d) Stack
Answer: d
5. The postfix form of A*B+C/D is?
a) *AB/CD+
b) AB*CD/+
c) A*BC+/D
d) ABCD+/*
Answer: b
6. Which data structure is needed to convert infix notation to postfix notation?
a) Branch
b) Tree
c) Queue
d) Stack
Answer: d
7. The prefix form of A-B/ (C * D ^ E) is?
a) -/*^ACBDE
b) -ABCD*^DE
c) -A/B*C^DE
d) -A/BC*^DE
Answer: c

8. What is the result of the following operation?


Top (Push (S, X))
a) X
b) X+S
c) S
d) XS
Answer: a
9. The prefix form of an infix expression (p + q) – (r * t) is?
a) + pq – *rt
b) – +pqr * t
c) – +pq * rt
d) – + * pqrt
Answer: c
10. Which data structure is used for implementing recursion?
a) Queue
b) Stack
c) Array
d) List
Answer: b
This set of Data Structure Questions and Answers for Freshers focuses on
“Stack Operations – 3”.

1. The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?


a) 600
b) 350
c) 650
d) 588
Answer: b
2. Convert the following infix expressions into its equivalent postfix expressions.
(A + B ⋀D)/(E – F)+G
a) (A B D ⋀ + E F – / G +)
b) (A B D +⋀ E F – / G +)
c) (A B D ⋀ + E F/- G +)
d) (A B D E F + ⋀ / – G +)
Answer: a
3. Convert the following Infix expression to Postfix form using a stack.
x + y * z + (p * q + r) * s, Follow usual precedence rule and assume that the
expression is legal.
a) xyz*+pq*r+s*+
b) xyz*+pq*r+s+*
c) xyz+*pq*r+s*+
d) xyzp+**qr+s*+
Answer: a

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

7. 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
Answer: a
8. Queues serve major role in ______________
a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) Simulation of heap sort
Answer: c
9. Which of the following is not the type of queue?
a) Ordinary queue
b) Single ended queue
c) Circular queue
d) Priority queue
Answer: b
This set of Data Structure Interview Questions & Answers focuses on “Singly Linked
List Operations – 1”.

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

3. Linked list is considered as an example of ___________ type of memory


allocation.
a) Dynamic
b) Static
c) Compile time
d) Heap
Answer: a
4. In Linked List implementation, a node carries information regarding ___________
a) Data
b) Link
c) Data and Link
d) Node
Answer: b
5. Linked list data structure offers considerable saving in _____________
a) Computational Time
b) Space Utilization
c) Space Utilization and Computational Time
d) Speed Utilization
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
b) It is easy to insert and delete elements in Linked List
c) Random access is not allowed in a typical implementation of Linked Lists
d) Access of elements in linked list takes less time than compared to arrays
Answer: d
7. 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
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”.

1. Which of the following properties is associated with a queue?


a) First In Last Out
b) First In First Out
c) Last In First Out
d) Last In Last Out
Answer: b
2. In a circular queue, how do you increment the rear end of the queue?
a) rear++
b) (rear+1) % CAPACITY
c) (rear % CAPACITY)+1
d) rear–
Answer: b

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

2. . What are the applications of dequeue?


a) A-Steal job scheduling algorithm
b) Can be used as both stack and queue
c) To find the maximum of all sub arrays of size k
d) To avoid collision in hash tables
Answer: d
3. What is the time complexity of deleting from the rear end of the
dequeue implemented with a singly linked list?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: c

This set of Data Structures & Algorithms Multiple Choice Questions


& Answers (MCQs) focuses on “Evaluation of a Postfix Expression”.

1. What is the other name for a postfix expression?


a) Normal polish Notation
b) Reverse polish Notation
c) Warsaw notation
d) Infix notation
Answer: b
2. Which of the following is an example for a postfix expression?
a) a*b(c+d)
b) abc*+de-+
c) +ab
d) a+b-c
Answer: b
3. Reverse Polish Notation is the reverse of a Polish Notation
a) True
b) False
Answer: b
4. What is the time complexity of evaluation of postfix expression
algorithm?
a) O (N)
b) O (N log N)
c) O (N2)
d) O (M log N)
Answer: a
5. In Postfix expressions, the operators come after the operands.
a) True
b) False
Answer: b
6. Which of these operators have the highest order of precedence?
a) ‘(‘ and ‘)’
b) ‘*’ and ‘/’
c) ‘~’ and ‘^’
d) ‘+’ and ‘-‘
Answer: c
7. Which of the following is not an application of stack?
a) evaluation of postfix expression
b) conversion of infix to postfix expression
c) balancing symbols
d) line at ticket counter
Answer: d

8. While evaluating a postfix expression, when an operator is


encountered, what is the correct operation to be performed?
a) push it directly on to the stack
b) pop 2 operands, evaluate them and push the result on to the stack
c) pop the entire stack
d) ignore the operator
Answer: b
9. Which of the following statement is incorrect?
a) Postfix operators use value to their right
b) Postfix operators use value to their left
c) Prefix operators use value to their right
d) In postfix expression, operands are followed by operators
Answer: a
10. What is the result of the given postfix expression? abc*+ where a=1,
b=2, c=3.
a) 4
b) 5
c) 6
d) 7
Answer: d
11. What is the result of the following postfix expression?
ab*cd*+ where a=2,b=2,c=3,d=4.
a) 16
b) 12
c) 14
d) 10
Answer: a
12. Consider the stack
|5|
|4|
|3|
| 2 |.
At this point, ‘*’ is encountered. What has to be done?
a) 5*4=20 is pushed into the stack
b) * is pushed into the stack
c) 2*3=6 is pushed into the stack
d) * is ignored
Answer: a
13. Evaluate the postfix expression ab + cd/- where a=5, b=4, c=9, d=3.
a) 23
b) 15
c) 6
d) 10
Answer: c
14. Evaluate and write the result for the following postfix expression
abc*+de*f+g*+ where a=1, b=2, c=3, d=4, e=5, f=6, g=2.
a) 61
b) 59
c) 60
d) 55
Answer: b
15. For the given expression tree, write the correct postfix expression.

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”.

1. How many stacks are required for evaluation of prefix


expression?
a) one
b) two
c) three
d) four
Answer: b
2. While evaluating a prefix expression, the string is read from?
a) left to right
b) right to left
c) center to right
d) center to left to right
Answer: b
3. The associativity of an exponentiation operator ^ is right side.
a) True
b) False
Answer: a
4. How many types of input characters are accepted by this
algorithm?
a) one
b) two
c) three
d) four
Answer: c
5. What determines the order of evaluation of a prefix expression?
a) precedence and associativity
b) precedence only
c) associativity only
d) depends on the parser
Answer: a
6. Find the output of the following prefix expression
*+2-2 1/-4 2+-5 3 1
a) 2
b) 12
c) 10
d) 4
Answer: a
7. An error is thrown if the character ‘\n’ is pushed in to the
character stack.
a) true
b) false
Answer: b
8. Using the evaluation of prefix algorithm, evaluate +-9 2 7.
a) 10
b) 4
c) 17
d) 14
Answer: d
9. If -*+abcd = 11, find a, b, c, d using evaluation of prefix
algorithm.
a) a=2, b=3, c=5, d=4
b) a=1, b=2, c=5, d=4
c) a=5, b=4, c=7,d=5
d) a=1, b=2, c=3, d=4
Answer: b
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Infix to Prefix
Conversion”.

1. What data structure is used when converting an infix


notation to prefix notation?
a) Stack
b) Queue
c) B-Trees
d) Linked-list
Answer: a
2. What would be the Prefix notation for the given equation?

A+(B*C)

a)+A*CB
b)*B+AC
c)+A*BC
d) *A+CB

Answer: c

3. What would be the Prefix notation for the given equation?

(A*B)+(C*D)
a)+*AB*CD
b)*+AB*CD
c)**AB+CD
d) +*BA*CD

Answer: a

4. What would be the Prefix notation for the given equation?

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

9. What would be the Prefix notation for the given equation?

(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”.

1. When an operand is read, which of the following is done?


a)It is placed on to the output
b) It is placed in operator stack
c) It is ignored
d) Operator stack is emptied
Answer: a
2. What should be done when a left parenthesis ‘(‘ is encountered?
a) It is ignored
b) It is placed in the output
c) It is placed in the operator stack
d) The contents of the operator stack is emptied
Answer: c
3. Which of the following is an infix expression?
a) (a+b)*(c+d)
b) ab+c*
c) +ab
d) abc+*
Answer: a
4. What is the time complexity of an infix to postfix conversion algorithm?
a) O(N log N)
b) O(N)
c) O(N2)
d) O(M log N)
Answer: b
5.What is the postfix expression for the corresponding infix expression?

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”.

1. Which of the following data structure is used to convert postfix


expression to infix expression?
a) Stack
b) Queue
c) Linked List
Answer: a
2. The postfix expression abc+de/*- is equivalent to which of the
following infix expression?
a) abc+-de*/
b) (a+b)-d/e*c
c) a-(b+c)*(d/e)
d) abc+*-(d/e)
Answer: c
3. The equivalent infix expression and value for the postfix form 1 2 + 3 *
4 5 * – will be ___________
a) 1 + 2 * 3 – 4 * 5 and -13
b) (2 + 1) * (3 – 4) * 5 and 13
c) 1 + 2 * (3 – 4) * 5 and -11
d) (1 + 2) * 3 – (4 * 5) and -11
Answer: d
4. What is the value of the postfix expression 2 3 + 4 5 6 – – *
a) 19
b) 21
c) -4
d) 25
Answer: d
5. The prefix expression of the postfix expression AB+CD-* is
__________
a) (A+B)*(C-D)
b) +AB*-CD
c) A+*BCD-
d) *+AB-CD
Answer: d
6. Consider the postfix expression 4 5 6 a b 7 8 a c, where a, b, c are
operators. Operator a has higher precedence over operators b and c.
Operators b and c are right associative. Then, equivalent infix
expression is
a) 4 a 5 6 b 7 8 a c
b) 4 a 5 c 6 b 7 a 8
c) 4 b 5 a 6 c 7 a 8
d) 4 a 5 b 6 c 7 a 8
Answer: c
7. To convert the postfix expression into the infix expression we use
stack and scan the postfix expression from left to right.
a) True
b) False
Answer: a
8. Which of the following is valid reverse polish expression?
a) a op b
b) op a b
c) a b op
d) both op a b and a b op
Answer: c
9. The result of the postfix expression 5 3 * 9 + 6 / 8 4 / + is
_____________
a) 8
b) 6
c) 10
d) 9
Answer: b

This set of Data Structure Multiple Choice Questions & Answers


(MCQs) focuses on “Towers of Hanoi”.

1. The optimal data structure used to solve Tower of Hanoi is


_________
a) Tree
b) Heap
c) Priority queue
d) Stack
Answer: d
2. Which among the following is not a palindrome?
a) Madam
b) Dad
c) Malayalam
d) Maadam
Answer: d
3. Which data structure can be used to test a palindrome?
a) Tree
b) Heap
c) Stack
d) Priority queue
Answer: c
4. What is the number of moves required to solve Tower of Hanoi
problem for k disks?
a) 2k – 1
b) 2k + 1
c) 2k + 1
d) 2k – 1
Answer: d
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Towers of Hanoi using
Recursion”.
1. What is the objective of tower of hanoi puzzle?
a) To move all disks to some other rod by following rules
b) To divide the disks equally among the three rods by following
rules
c) To move all disks to some other rod in random order
d) To divide the disks equally among three rods in random order
Answer: a
2. Which of the following is NOT a rule of tower of hanoi puzzle?
a) No disk should be placed over a smaller disk
b) Disk can only be moved if it is the uppermost disk of the stack
c) No disk should be placed over a larger disk
d) Only one disk can be moved at a time
Answer: c
3. The time complexity of the solution tower of hanoi problem using
recursion is _________
a) O(n2)
b) O(2n)
c) O(n log n)
d) O(n)
Answer: b

4. Recurrence equation formed for the tower of hanoi problem is


given by _________
a) T(n) = 2T(n-1)+n
b) T(n) = 2T(n/2)+c
c) T(n) = 2T(n-1)+c
d) T(n) = 2T(n/2)+n
Answer: c
5. Minimum number of moves required to solve a tower of hanoi
problem with n disks is __________
a) 2n
b) 2n-1
c) n2
d) n2-1
Answer: b
6. Space complexity of recursive solution of tower of hanoi puzzle is
________
a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
Answer: b
7. Recursive solution of tower of hanoi problem is an example of
which of the following algorithm?
a) Dynamic programming
b) Backtracking
c) Greedy algorithm
d) Divide and conquer
Answer: d
8. Tower of hanoi problem can be solved iteratively.
a) True
b) False
Answer: a
9. Minimum time required to solve tower of hanoi puzzle with 4 disks
assuming one move takes 2 seconds, will be __________
a) 15 seconds
b) 30 seconds
c) 16 seconds
d) 32 seconds
Answer: b
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Quicksort – 1”.
1. Which of the following sorting algorithms is the fastest?
a) Merge sort
b) Quick sort
c) Insertion sort
d) Shell sort
Answer: b
2. Quick sort follows Divide-and-Conquer strategy.
a) True
b) False
Answer: a
3. What is the worst case time complexity of a quick sort algorithm?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(log N)
Answer: c
4. Which of the following methods is the most effective for picking the pivot element?
a) first element
b) last element
c) median-of-three partitioning
d) random element
Answer: c
5. Find the pivot element from the given input using median-of-three partitioning
method.
8, 1, 4, 9, 6, 3, 5, 2, 7, 0.
a) 8
b) 7
c) 9
d) 6
Answer: d
6. Which is the safest method to choose a pivot element?
a) choosing a random element as pivot
b) choosing the first element as pivot
c) choosing the last element as pivot
d) median-of-three partitioning method
Answer: a
7. What is the average running time of a quick sort algorithm?
a) O(N2)
b) O(N)
c) O(N log N)
d) O(log N)
Answer: c
8. Which of the following sorting algorithms is used along with quick sort to sort the sub
arrays?
a) Merge sort
b) Shell sort
c) Insertion sort
d) Bubble sort
Answer: c
9. Quick sort uses join operation rather than merge operation.
a) true
b) false
Answer: a
10. How many sub arrays does the quick sort algorithm divide the entire array into?
a) one
b) two
c) three
d) four
Answer: b
11. Which is the worst method of choosing a pivot element?
a) first element as pivot
b) last element as pivot
c) median-of-three partitioning
d) random element as pivot
Answer: a
12. Which among the following is the best cut-off range to perform insertion sort within a
quick sort?
a) N=0-5
b) N=5-20
c) N=20-30
d) N>30
Answer: b
This set of Data Structures & Algorithms Multiple Choice Questions & Answers
(MCQs) focuses on “Merge Sort”.
1. Merge sort uses which of the following technique to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming
Answer: c
2. What is the average case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Answer: a
3. What is the auxiliary space complexity of merge sort?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: c
4. Merge sort can be implemented using O(1) auxiliary space.
a) true
b) false
Answer: a
5. What is the worst case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Answer: a
6. Which of the following method is used for sorting in merge sort?
a) merging
b) partitioning
c) selection
d) exchanging
Answer: a
7. What will be the best case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Answer: a
8. Which of the following is not a variant of merge sort?
a) in-place merge sort
b) bottom up merge sort
c) top down merge sort
d) linear merge sort
Answer: d
9. Choose the incorrect statement about merge sort from the following?
a) it is a comparison based sort
b) it is an adaptive algorithm
c) it is not an in place algorithm
d) it is stable algorithm
Answer: b
10. Which of the following is not in place sorting algorithm?
a) merge sort
b) quick sort
c) heap sort
d) insertion sort
Answer: a
11. Which of the following is not a stable sorting algorithm?
a) Quick sort
b) Cocktail sort
c) Bubble sort
d) Merge sort
Answer: a
12. Which of the following stable sorting algorithm takes the least time when applied
to an almost sorted array?
a) Quick sort
b) Insertion sort
c) Selection sort
d) Merge sort
Answer: d
13. Merge sort is preferred for arrays over linked lists.
a) true
b) false
Answer: b
14. Which of the following sorting algorithm makes use of merge sort?
a) tim sort
b) intro sort
c) bogo sort
d) quick sort
Answer: a
15. Which of the following sorting algorithm does not use recursion?
a) quick sort
b) merge sort
c) heap sort
d) bottom up merge sort
Answer: d
This set of Data Structure Multiple Choice Questions & Answers (MCQs)
focuses on “Bubble Sort”.
1. What is an external sorting algorithm?
a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
Answer: a
2. What is an internal sorting algorithm?
a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
Answer: b
3. What is the worst case complexity of bubble sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
4. What is the average case complexity of bubble sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
5. Which of the following is not an advantage of optimised bubble sort over other
sorting techniques in case of sorted elements?
a) It is faster
b) Consumes less memory
c) Detects whether the input is already sorted
d) Consumes less time
Answer: c
6. The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array
elements. How many iterations will be done to sort the array?
a) 4
b) 2
c) 1
d) 0
Answer: a
7. What is the best case efficiency of bubble sort in the improvised version?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: c
8. The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array
elements. How many iterations will be done to sort the array . with improvised
version?
a) 4
b) 2
c) 1
d) 0
Answer: b
This set of Data Structure Multiple Choice Questions &
Answers (MCQs) focuses on “Selection Sort”.
1. What is an in-place sorting algorithm?
a) It needs O(1) or O(logn) memory to create auxiliary locations
b) The input is already sorted and in-place
c) It requires additional storage
d) It requires additional space
Answer: a
2. In the following scenarios, when will you use selection sort?
a) The input is already sorted
b) A large file has to be sorted
c) Large values need to be sorted with small keys
d) Small values need to be sorted with large keys
Answer: c
3. What is the worst case complexity of selection sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
4. What is the advantage of selection sort over other sorting
techniques?
a) It requires no additional storage space
b) It is scalable
c) It works best for inputs which are already sorted
d) It is faster than any other sorting technique
Answer: a
5. What is the average case complexity of selection sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
6. What is the disadvantage of selection sort?
a) It requires auxiliary memory
b) It is not scalable
c) It can be used for small keys
d) It takes linear time to sort the elements
Answer: b
7. The given array is arr = {3,4,5,2,1}. The number of iterations in
bubble sort and selection sort respectively are,
a) 5 and 4
b) 4 and 5
c) 2 and 4
d) 2 and 5
Answer: a
8. The given array is arr = {1,2,3,4,5}. (bubble sort is implemented
with a flag variable)The number of iterations in selection sort
and bubble sort respectively are,
a) 5 and 4
b) 1 and 4
c) 0 and 4
d) 4 and 1
Answer: d
9. What is the best case complexity of selection sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: d
This set of Data Structures & Algorithms Multiple Choice
Questions & Answers (MCQs) focuses on “Insertion Sort –
1”.
1.How many passes does an insertion sort algorithm consist of?
a) N
b) N-1
c) N+1
d) N2
Answer: b
2. Which of the following algorithm implementations is similar
to that of an insertion sort?
a) Binary heap
b) Quick sort
c) Merge sort
d) Radix sort
Answer: a
3. What is the average case running time of an insertion sort
algorithm?
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Answer: d
4. Any algorithm that sorts by exchanging adjacent elements
require O(N2) on average.
a) True
b) False
Answer: a
5. What is the average number of inversions in an array of N
distinct numbers?
a) N(N-1)/4
b) N(N+1)/2
c) N(N-1)/2
d) N(N-1)/3
Answer: a
6. What is the running time of an insertion sort algorithm if the
input is pre-sorted?
a) O(N2)
b) O(N log N)
c) O(N)
d) O(M log N)
Answer: c
7. What will be the number of passes to sort the elements
using insertion sort?
14, 12,16, 6, 3, 10
a) 6
b) 5
c) 7
d) 1
Answer: b
8. For the following question, how will the array elements look
like after second pass?
34, 8, 64, 51, 32, 21
a) 8, 21, 32, 34, 51, 64
b) 8, 32, 34, 51, 64, 21
c) 8, 34, 51, 64, 32, 21
d) 8, 34, 64, 51, 32, 21
Answer: d
9. Which of the following real time examples is based on
insertion sort?
a) arranging a pack of playing cards
b) database scenarios and distributes scenarios
c) arranging books on a library shelf
d) real-time systems
Answer: a
10. In C, what are the basic loops required to perform an
insertion sort?
a) do- while
b) if else
c) for and while
d) for and if
Answer: c
11. Binary search can be used in an insertion sort algorithm to
reduce the number of comparisons.
a) True
b) False
Answer: a
12. Which of the following options contain the correct feature of
an insertion sort algorithm?
a) anti-adaptive
b) dependable
c) stable, not in-place
d) stable, adaptive
Answer: d
13. Which of the following sorting algorithms is the fastest for
sorting small arrays?
a) Quick sort
b) Insertion sort
c) Shell sort
d) Heap sort
Answer: b
14. For the best case input, the running time of an insertion sort
algorithm is?
a) Linear
b) Binary
c) Quadratic
d) Depends on the input
Answer: a
15. Which of the following examples represent the worst case
input for an insertion sort?
a) array in sorted order
b) array sorted in reverse order
c) normal unsorted array
d) large array
Answer: b

MCQs on Sorting with answers

1. Which of the following is not a stable sorting algorithm?

a) Insertion sort
b) Selection sort
c) Bubble sort
d) Merge sort
View Answer / Hide Answer

ANSWER: B

2. Which of the following is a stable sorting algorithm?

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

5. Running merge sort on an array of size n which is already


sorted is

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

6. Which of the following is not a noncomparison sort?

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) Takes O(nlogn) times


b) Maintains the relative order of occurrence of non-distinct elements
c) Uses divide-and-conquer paradigm
d) Takes O(n) space
View Answer / Hide Answer
ANSWER: B
28. In a heap with n elements with the smallest element at the root, the seventh
smallest element can be found in time

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 ?

a) FIFO (First In First Out) list


b) LIFO (Last In First Out) list.
c) Ordered array
d) Linear tree
View Answer / Hide Answer

ANSWER: a) FIFO (First In First Out) list

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

7. In linked list implementation of a queue, where does a new element be


inserted?

a) At the head of link list


b) At the tail of the link list
c) At the centre position in the link list
d) None
View Answer / Hide Answer

ANSWER: b) At the tail of the link list

8. In the array implementation of circular queue, which of the following operation


take worst case linear time?

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

ANSWER: d) Both a) and c)

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

ANSWER: b) Front= rear=-1

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?

a) Only front pointer


b) Only rear pointer
c) Both front and rear pointer
d) None of the front and rear pointer
View Answer / Hide Answer

ANSWER: b) Only rear pointer

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) Only front pointer


b) Only rear pointer
c) Both front and rear pointer
d) None
View Answer / Hide Answer

ANSWER: c) Both front and rear pointer


18. An array of size MAX_SIZE is used to implement a circular queue. Front, Rear,
and count are tracked. Suppose front is 0 and rear is MAX_SIZE -1. How many
elements are present in the queue?

a) Zero
b) One
c) MAX_SIZE-1
d) MAX_SIZE
View Answer / Hide Answer

ANSWER: d) MAX_SIZE

19. Suppose a circular queue of capacity (n-1) elements is implemented with an


array of n elements. Assume that the insertion and deletion operations are carried
out using REAR and FRONT as array index variables, respectively. Initially
REAR=FRONT=0. The conditions to detect queue full and queue is empty are?

a) Full: (REAR+1)mod n == FRONT


Empty: REAR==FRONT
b) Full: (REAR+1)mod n == FRONT
Empty: (FRONT+1) mod n == REAR
c) Full: REAR==FRONT
Empty: (REAR+1) mod n==FRONT
d) Full: (FRONT+1)mod n==REAR
Empty: REAR==FRONT
View Answer / Hide Answer

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
}
}

What is the worst case time complexity of a sequence of n queue operations on an


initially empty queue?

a) θ (n)
b) θ (n + k)
c) θ (nk)
d) θ (n2)
View Answer / Hide Answer

ANSWER: a) θ (n)

You might also like