Top 150+ Solved Data Structure (DS) MCQ Questions Answer
Q. A circular linked list can be used for
a. stack
b. queue
c. both stack & queue
d. neither stack or queue
Q. In doubly linked lists
a. a pointer is maintained to store both next and previous nodes.
b. two pointers are maintained to store next and previous nodes.
c. a pointer to self is maintained for each node.
d. none of the above
Q. The disadvantage in using a circular linked list is …………………….
a. it is possible to get into infinite loop
b. last node points to first node.
c. time consuming
d. requires more memory space
Q. A linear list in which each node has pointers to point to the predecessor and successors nodes is called as
a. singly linked list
b. circular linked list
c. doubly linked list
d. linear linked list
Q. The situation when in a linked list START=NULL is
a. underflow
b. overflow
c. housefull
d. saturated
Q. In doubly linked lists, traversal can be performed?
a. only in forward direction
b. only in reverse direction
c. in both directions
d. none of the above
Q. What differentiates a circular linked list from a normal linked list?
a. you cannot have the ‘next’ pointer point to null in a circular linked list
b. it is faster to traverse the circular linked list
c. you may or may not have the ‘next’ pointer point to null in a circular linked list
d. head node is known in circular linked list
Q. How do you count the number of elements in the circular linked list?
a. public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != head){temp = temp.getnext();length++;}return length;}
b. public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != null){temp = temp.getnext();length++;}return length;}
c. public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != head && temp != null){temp = head.getnext();length++;}return length;}
d. public int length(node head){int length = 0;if( head == null)return 0;node temp = heagetnext();while(temp != head && temp == null){temp = heagetnext();length++;}return length;}
Q. public int function(){ if(head == null) return Integer.MIN_VALUE; int var; Node temp = head; while(temp.getNext() != head) temp = temp.getNext(); if(temp == head) { var = head.getItem(); head = null; return var; } temp.setNext(head.getNext()); var = head.getItem(); head = head.getNext(); return var;} What is the functionality of the following code? Choose the most appropriate answer.
a. return data from the end of the list
b. returns the data and deletes the node at the end of the list
c. returns the data from the beginning of the list
d. returns the data and deletes the node from the beginning of the list
Q. What is the functionality of the following code? Choose the most appropriate answer. public int function(){if(head == null)return Integer.MIN_VALUE;int var;Node temp = head;Node cur;while(temp.getNext() != head){cur = temp;temp = temp.getNext();}if(temp == head){var = head.getItem();head = null;return var;}var = temp.getItem();cur.setNext(head);return var;}
a. return data from the end of the list
b. returns the data and deletes the node at the end of the list
c. returns the data from the beginning of the list
d. returns the data and deletes the node from the beginning of the list
Q. How do you insert a node at the beginning of the list?
a. public class insertfront(int data){node node = new node(data, head, head.getnext());node.getnext().setprev(node);head.setnext(node);size++;}
b. public class insertfront(int data){node node = new node(data, head, head);node.getnext().setprev(node);head.setnext(node);size++;}
c. public class insertfront(int data){node node = new node(data, head, head.getnext());node.getnext().setprev(head);head.setnext(node);size++;}
d. public class insertfront(int data){node node = new node(data, head, heagetnext());node.getnext().setprev(node);heasetnext(node.getnext());size++;}
Q. 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
Q. Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue 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
Q. Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?
a. a queue cannot be implemented using this stack.
b. a queue can be implemented where enqueue takes a single instruction and dequeue takes a sequence of two instructions.
c. a queue can be implemented where enqueue takes a sequence of three instructions and dequeue takes a single instruction.
d. a queue can be implemented where both enqueue and dequeue take a single instruction each.
Q. Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:i. isEmpty (Q) — returns true if the queue is empty, false otherwise.ii. delete (Q) — deletes the element at the front of the queue and returns its value.iii. insert (Q, i) — inserts the integer i at the rear of the queue.Consider the following function:void f (queue Q) {int i ;if (!isEmpty(Q)) { i = delete(Q); f(Q); insert(Q, i); }}What operation is performed by the above function f ?
a. leaves the queue q unchanged
b. reverses the order of the elements in the queue q
c. deletes the element at the front of the queue q and inserts it at the rear keeping the other elements in the same order
d. empties the queue q