Data Structure MCQ1) How can we describe an array in the best possible way?
Answer: c Explanation: The answer is c because array stores the elements in a contiguous block of memory of similar types. Therefore, we can say that array is a container that stores the elements of similar types. 2) Which of the following is the correct way of declaring an array?
Answer: a Explanation: The answer is a because int specifies the type of the array, javatpoint is the name of the array, and 10 is the size of the array enclosed within the square brackets. 3) How can we initialize an array in C language?
Answer: c Explanation: The answer is c because the values assigned to the array must be enclosed within a curly bracket. 4) Which of the following is the advantage of the array data structure?
Answer: b Explanation: The answer is b because the elements in an array are stored in a contiguous block of memory, so it is easier to access the elements of an array through indexing. 5) Which of the following highly uses the concept of an array?
Answer: c Explanation: The answer is c, i.e., Spatial locality. Here, spatial locality means that the instruction accessed recently, then the nearby memory location would be accessed in the next iteration. As we know that in an array, all the elements are stored in a contiguous block of memory, so spatial locality is accessed quickly. 6) Which of the following is the disadvantage of the array?
Answer: c Explanation: The answer is c. For example, if we have an array of size 10 elements and we have inserted only 5 elements in an array then there is a wastage of 5 memory blocks which cannot be utilized by another variable. 7) What is the output of the below code?
Answer: a Explanation: The answer is a because the indexing in an array starts from 0, so it starts from arr[0] to arr[4]. If we try to access arr[5] then the garbage value will be printed. 8) Which one of the following is the size of int arr[9] assuming that int is of 4 bytes?
Answer: b Explanation: The answer is b because the size of int type data is 4 bytes. The array stores 9 elements, so the size of the array is 9*4=36 bytes. 9) Which one of the following is the process of inserting an element in the stack?
Answer: c Explanation: The answer is c. In stack, the process of inserting an element is known as a push operation. 10) When the user tries to delete the element from the empty stack then the condition is said to be a ____
Answer: a Explanation: The answer is a. Underflow is a condition that occurs when user tries to implement the pop operation in the empty stack. 11) If the size of the stack is 10 and we try to add the 11th element in the stack then the condition is known as___
Answer: c Explanation: The answer is c because the stack is full with its 10 elements, and inserting one more element in a stack will lead to the stack overflow. 12) Which one of the following is not the application of the stack data structure
Answer: d Explanation: The answer is d. The first three options are the stack applications, but option d is not a stack application. The queue data structure is used for synchronization between the processes. 13) Which data structure is mainly used for implementing the recursive algorithm?
Answer: b Explanation: The answer is b. Recursion means calling the function itself again. Stack is used to maintain the previous records of the function. 14) Which data structure is required to convert the infix to prefix notation?
Answer: a Explanation: The answer is a, i.e., stack. Stack is a data structure used to reverse the order of the operators in the expression. It is also used as a storage structure that stores all the operators and print all the operators when all the operands have appeared. 15) Which of the following is the infix expression?
Answer: a Explanation: The answer is a, i.e., A+B*C because, in infix notation, all the operators appear between the operands. 16) Which of the following is the prefix form of A+B*C?
Answer: d Explanation: The answer is d. The prefix notation means all the operators that appear before operand. To convert the infix expression into a prefix expression, we will move the operator to the left of the parenthesis as shown in the below figure. 17) Which of the following is not the correct statement for a stack data structure?
Answer: b Explanation: The answer is b because Stack does not follow FIFO. It follows LIFO. 18) If the elements '1', '2', '3' and '4' are added in a stack, so what would be the order for the removal?
Answer: c Explanation: The answer is c because stack follows LIFO, which means that the element inserted at the last will be removed first. 19) What is the outcome of the prefix expression +, , *, 3, 2, /, 8, 4, 1?
Answer: c Explanation: Reverse of the prefix expression: 1, 4, 8, /, 2, 3, *, , +
The infix expression of the above prefix expression is: (2*3)  (8/4) +1 6 2 +1 = 5 20) The minimum number of stacks required to implement a stack is __
Answer: c Explanation: The answer is 2. In Queue, one stack is required for the enqueue operation, and another stack will be used for the dequeue operation. The first stack is considered as the input stack whereas the second stack is considered as the output stack. 21) Which one of the following node is considered the top of the stack if the stack is implemented using the linked list?
Answer: a Explanation: The answer is a, i.e., First node. As we know, that last inserted element in the stack is considered as the top of the stack. Whenever the element is added to the linked list, it is always added at the beginning of the list. Therefore, we can say that the first node in the linked list is considered as the top of the stack. 22) Consider the following stack implemented using stack. What would be the maximum value of the top that does not cause the overflow of the stack?
Answer: d Explanation: The answer is 10. The maximum size of the array is 11; therefore, we can insert 11 elements in the stack. The top value is initialized by 1, and on every insertion, the top value gets incremented. 23) What is another name for the circular queue among the following options?
Answer: c Explanation: The circular queue is also known as a ring buffer. In a circular queue, the last element is connected back to the first element of the queue that forms a circle. Therefore, the structure of a circular queue is also known as a ring structure. 24) If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the removal?
Answer: a Explanation: The answer is a, i.e., 1234. The queue follows the FIFO principle in which the element inserted first will be removed first. 25) A list of elements in which enqueue operation takes place from one end, and dequeue operation takes place from one end is__
Answer: c Explanation: The answer is Queue. Queue is a data structure in which insertion takes place from one end, and deletion takes place from one end. 26) Which of the following principle does Queue use?
Answer: b Explanation: The answer is FIFO principle. Here, FIFO stands for FirstInFirstOut. It means that the element which is inserted first will also be removed first. 27) Which one of the following is not the type of the Queue?
Answer: d Explanation: The answer is d. i.e., single ended queue. Queue has two ends in which one end is used for the insertion and another end is used for the deletion. Therefore, it is not possible for the Queue to have a single ended queue. 28) Which one of the following is the overflow condition if linear queue is implemented using an array with a size MAX_SIZE?
Answer: c Explanation: The answer is c, i.e., rear=MAX_SIZE1. As the size of the array is MAX_SIZE, so we can insert the elements till MAX_SIZE1. If we try to insert the elements of size MAX_SIZE or more than MAX_SIZE in a queue, then it leads to the overflow condition. 29) Which one of the following is the overflow condition if a circular queue is implemented using array having size MAX?
Answer: c Explanation: The answer is c, i.e., front=(rear+1) mod max. The overflow condition for the linear queue is rear =MAX1 as there is no space left in the Queue if rear = MAX1. On the other hand, in a circular queue, the overflow condition is front=(rear+1) mod max because the last element is connected to the first element in a circular queue. 30) The time complexity of enqueue operation in Queue is __
Answer: a Explanation: The answer is a, i.e., O(1). In Queue, the insertion is performed at the rear end, which is directly accessible; therefore, it takes O(1) time to insert an element in a Queue. 31) Which of the following that determines the need for the Circular Queue?
Answer: a Explanation: The answer is a, i.e., Avoid wastage of memory. In a linear queue, there are chances of wastage of memory because if the rear is pointing to the last element whereas the front is pointing to the element other than the first element; it means that spaces allocated before the front are free, but it cannot be reused as rear cannot be incremented. In contrast, the last element is connected to the first element in a circular queue; if initial spaces are vacant, then rear can be incremented by using the statement (rear+1) mod max where max is the size of the array. Therefore, we conclude that the circular queue avoids wastage of memory. 32) Which one of the following is the correct way to increment the rear end in a circular queue?
Answer: b Explanation: The answer is b. It ensures that the rear will have the value from 0 to max1; if the rear end points to the last position, and we increment the rear end using (rear+1) % max, then rear will point to the first position in the queue. 33) Consider the following code. Which operation does the above code perform?
Answer: d Explanation: The answer is d because two operations are performed in the above code. The first one is returning the value of the front with the help of the statement n=q[front], and the second operation is dequeue (deleting an element) by using the statement front++. 34) In the linked list implementation of queue, where will the new element be inserted?
Answer: c Explanation: The answer is c. If the queue is implemented using linked list, then the new element will be inserted at the tail position of the linked list as Queue follows FIFO principle in which new element will always be added at the end of the Queue. 35) How many Queues are required to implement a Stack?
Answer: b Explanation: The answer is b because one queue is required to perform the push operation while the other queue is used to perform the pop operation. 36) Which one of the following is not the application of the Queue data structure?
Answer: d Explanation: The answer is d. The options a, b, and c are the applications of the Queue data structure while option d, i.e., balancing of symbols is not the application of the Queue data structure. The option a, i.e., resource shared between various system is the application of the Queue data structure as it allows to align all the requests for the resource in a queue. The option b, i.e., data is transferred asynchronously is a application of the Queue data structure. Here asynchronously means that the data received at the different rate as sent. The option c, i.e., load balancing is also an application of the Queue data structure because all the requests from the client are stored in the Queue, and it distributes the requests to the client one by one. The option d, i.e., balancing of symbols is an application of the stack data structure. 37) Which of the following option is true if implementation of Queue is from the linked list?
Answer: d Explanation: The answer is d. As we know that Queue has two ends, i.e., one for the insertion and another one for the deletion. If Queue is implemented using Linked list then it can be done in either of the ways. 38) The necessary condition to be checked before deletion from the Queue is__
Answer: b Explanation: The answer is b, i.e., Underflow. Before deleting an element from the Queue, we first need to check whether the Queue is empty or not. 39) Which data structure is the best for implementing a priority queue?
Answer: d Explanation: The answer is d, i.e., Heap. All the data structures that are given in the above options can be used to implement a priority queue but the most efficient way of implementing a priority queue is heap data structure. 40) Which of the following principle is used if two elements in the priority queue have the same priority?
Answer: b Explanation: The answer is b, i.e., FIFO. In a priority queue, if two or more elements have the same priority then they are arranged based on the FIFO principle. 41) Which of the following statement is not true regarding the priority queue?
Answer: c Explanation: The answer is c. i.e., deletion is easier. In worst case, the deletion is not easier as we have to traverse to the n elements until the element to be removed is not found. 42) A linear data structure in which insertion and deletion operations can be performed from both the ends is___
Answer: b Explanation: The answer is b, i.e., Deque. The deque is a data structure in which both insertion and deletion can be performed from both the ends whereas, in Queue, insertion can be done from one end and deletion can be performed from another end. 43) In the Deque implementation using singly linked list, what would be the time complexity of deleting an element from the rear end?
Answer: O(n) Explanation: The answer is O(n) because we need to traverse till the n element to delete the element from the rear end. 44) Which of the following data structure allows you to insert the elements from both the ends while deletion from only one end?
Answer: b Explanation: The answer is b. The outputrestricted queue is one of the types of the Deque data structure in which insertion is allowed from both the ends but the deletion is allowed from only one end. 45) What would be the output after performing the following operations in a Deque?
Answer: b Explanation: The answer is b. Let's dry run the above code. When insertfront(10) is called, deque would be: 10 When insertfront(20) is called, the deque would be: 20 10 When insertrear(30) is called, the deque would be: 20 10 30 When insertrear(40) is called, the deque would be: 20 10 30 40 When deletefront() is called, the deque would be: 10 30 40 When insertfront(50) is called, the deque would be: 50 10 30 40 When deleterear() is called, the deque would be: 50 10 30 46) In a circular queue implementation using array of size 5, the array index starts with 0 where front and rear values are 3 and 4 respectively. Determine the array index at which the insertion of the next element will take place.
Answer: b Explanation: The answer is b, i.e., 0. As it is mentioned in the question that the size of the array is 5; therefore, the range would be from 0 to 4. In a circular queue, the last element is connected to the first element; the value of rear is 4 so when we increment the value then it will point to the 0^{th} position of the array. 47) If circular queue is implemented using array having size MAX_SIZE in which array index starts with 0, front points to the first element in the queue, and rear points to the last element in the queue. Which one of the following conditions used to specify that the circular queue is empty?
Answer: a Explanation: The answer is a, i.e., front=rear= 1. When the circular queue is empty means that no element is available in the queue then the front and rear are initialized with a 1 value. 48) Consider the implementation of the singly linked list having the head pointer only in the representation. Which of the following operations can be performed in O(1) time? i) Deletion of the last node in the linked list
Answer: b Explanation: The answer is b. As it is mentioned in the above question that there is only head pointer pointing to the front node in the list so it will take O(1) time to insert at the front as well as to delete the first node from the list. If we try to insert the node at the end or delete the last node then it will take O(n) time as we need to traverse till the n elements. 49) What would be the time complexity if user tries to insert the element at the end of the linked list (head pointer is known)?
Answer: b Explanation: The answer is b, i.e., O(n). As it is mentioned in the above question that head pointer is known, so to insert the node at the end of the linked list; we have to traverse till the nth node. Therefore, the time complexity would be O(n). 50) Which of the following is the time complexity to search an element in the linked list?
Answer: O(n) Explanation: The answer is O(n). The worstcase time complexity to search an element in the linked list is O(n) because if we have to find the last element then we need to traverse till the nth node. 51) Consider the following code Which one of the following is the correct option to create a new node?
Answer: c Explanation: The answer is c, i.e., ptr=(node*)malloc(sizeof(node)). In this statement, we have used a malloc() function for allocating the memory to the node and ptr is a pointer variable that will point to the newly created node. 52) Which of the following statement is not true about the doubly linked list?
Answer: c Explanation: The answer is c. The implementation of doubly linked list is complex as compared to singly linked list as it needs to store the addresses of the two nodes, i.e., the previous and the next node. If we insert or delete the node from the doubly linked list then it needs to adjust two pointers, previous and the next pointer. 53) What is the maximum number of children that a node can have in a binary tree?
Answer: d Explanation: The answer is d. The binary tree can contain utmost two children. 54) Which one of the following techniques is not used in the Binary tree?
Answer: a Explanation: The answer is a. The binary tree contains three traversal techniques, preorder, postorder and inorder traversal. 55) Which of the following options is not true about the Binary Search tree?
Answer: d Explanation: The answer is d. All the three options, i.e., a, b and c are true for the binary search tree. In binary search tree, the left child should be less than the root node and the right child should be greater than the value of the root node. 56) How can we define a AVL tree?
Answer: a Explanation: The answer is a. An AVL tree is a binary search tree and height balanced tree. 57) Why do we prefer Red Black tree over AVL tree?
Answer: d Explanation: The answer is d. Red Black tree requires fewer rotations for inserting or deleting the node whereas AVL tree requires multiple rotations to balance the tree. AVL tree stores balance factor per node that requires space whereas Red Black tree stores 1bit information. 58) Which of the following satisfies the property of the Red Black tree?
Answer: d Explanation: The answer is d. Red black tree is a binary search tree but it is not a strictly balanced tree like AVL tree. In Red Black tree, a node must be either in Black or Red in color and root node must be in Black color. 59) What would be the color of newly created node while inserting a new element in a Red black tree?
Answer: d Explanation: The answer is d. The property of Red Black tree is that if the newly created node is a root node then the color of the node would be Black otherwise the color of the node would be Red. 60) Identify the AVL tree among the following options?
Answer: c Explanation: The answer is c. Both A and C are the AVL trees but B is not a AVL tree. As we know that balance factor of every node in AVL tree should be either 1, 0 or 1. But in case of B, the balance factor of node 80 is 2, so it is not a AVL tree.
Next TopicDS Tutorial
