Data Structure and Algorithms (DSA) MCQs with answers Page - 43

Here, you will find a collection of MCQ questions on Data Structure and Algorithms (DSA). Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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 = head.getnext(); while(temp != head && temp == null) { temp = head.getnext(); length++; } return length; }

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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, head.getnext()); node.getnext().setprev(node); head.setnext(node.getnext()); size++; }

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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.

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

Q. Consider the following statements:i. First-in-first out types of computations are efficiently supported by STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing LISTS on
an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than implementing QUEUES
on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by QUEUES.Which of the following is correct?

  • (A) (ii) and (iii) are true
  • (B) (i) and (ii) are true
  • (C) (iii) and (iv) are true
  • (D) (ii) and (iv) are true

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ