adplus-dvertising

Welcome to the Stacks and Queues MCQs Page

Dive deep into the fascinating world of Stacks and Queues with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Stacks and Queues, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Stacks and Queues, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Stacks and Queues. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Stacks and Queues. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Stacks and Queues MCQs | Page 21 of 25

Q201.
Which of the following best describes the growth of a linear queue at runtime? (Q is the original queue, size() returns the number of elements in the queue)
a)

private void expand()
{
 int length = size();
 int[] newQ = new int[length<<1];
 for(int i=front; i<=rear; i++)
 {
  newQ[i-front] = Q[i%CAPACITY];
 }
 Q = newQ;
 front = 0;
 rear = size()-1;
}

b)

private void expand()
{
 int length = size();
 int[] newQ = new int[length<<1];
 for(int i=front; i<=rear; i++)
 {
  newQ[i-front] = Q[i%CAPACITY];
 }
 Q = newQ;
}

c)

private void expand()
{
 int length = size();
 int[] newQ = new int[length<<1];
 for(int i=front; i<=rear; i++)
 {
  newQ[i-front] = Q[i];
 }
 Q = newQ;
 front = 0;
 rear = size()-1;
}

d)

private void expand()
{
 int length = size();
 int[] newQ = new int[length*2];
 for(int i=front; i<=rear; i++)
 {
  newQ[i-front] = Q[i%CAPACITY];
 }
 Q = newQ;
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q202.
What is the space complexity of a linear queue having n elements?
Discuss
Answer: (a).O(n)
Q203.
What is the output of the following piece of code?
public class CircularQueue
{
 protected static final int CAPACITY = 100;
 protected int size,front,rear;
 protected Object q[];
 int count = 0;
 
 public CircularQueue()
 {
  this(CAPACITY);
 }
 public CircularQueue (int n)
 {
  size = n;
  front = 0;
  rear = 0;
  q = new Object[size];
 }
 
 
 public void enqueue(Object item)
 {
  if(count == size)
  {
   System.out.println("Queue overflow");
    return;
  }
  else
  {
   q[rear] = item;
   rear = (rear+1)%size;
   count++;
  }
 }
 public Object dequeue()
 {
  if(count == 0)
  {
   System.out.println("Queue underflow");
   return 0;
  }
  else
  {
   Object ele = q[front];
   q[front] = null;
   front = (front+1)%size;
   count--;
   return ele;
  }
 }
 public Object frontElement()
 {
  if(count == 0)
  return -999;
  else
  {
   Object high;
   high = q[front];
   return high;
  }
 }
 public Object rearElement()
 {
  if(count == 0)
  return -999;
  else
  {
   Object low;
   rear = (rear-1)%size;
   low = q[rear];
   rear = (rear+1)%size;
   return low;
  }
 }
}
public class CircularQueueDemo
{
 public static void main(String args[])
 {
  Object var;
  CircularQueue myQ = new CircularQueue();
  myQ.enqueue(10);
  myQ.enqueue(3);
  var = myQ.rearElement();
  myQ.dequeue();
  myQ.enqueue(6);
  var = mQ.frontElement();
  System.out.println(var+" "+var);
 }
}
Discuss
Answer: (a).3 3
Q204.
In linked list implementation of queue, if only front pointer is maintained, which of the following operation take worst case linear time?
Discuss
Answer: (d).Both Insertion and To empty a queue
Q205.
In linked list implementation of a queue, where does a new element be inserted?
Discuss
Answer: (c).At the tail of the link list
Q206.
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?
Discuss
Answer: (b).Only rear pointer
Q207.
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?
Discuss
Answer: (c).Both front and rear pointer
Q208.
In case of insertion into a linked queue, a node borrowed from the __________ list is inserted in the queue.
Discuss
Answer: (a).AVAIL
Q209.
In linked list implementation of a queue, from where is the item deleted?
Discuss
Answer: (a).At the head of link list
Q210.
In linked list implementation of a queue, the important condition for a queue to be empty is?
Discuss
Answer: (a).FRONT is null

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!