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 23 of 25

Explore more Topics under Data Structures and Algorithms

Discuss
Answer: (a).A queue with insert/delete defined for both front and rear ends of the queue
Q222.
Select the function which performs insertion at the front end of the dequeue?
a)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  temp.setNext(trail);
  head.setNext(temp);
 }
 else
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 size++;
}

b)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  temp.setNext(trail);
  head.setNext(trail);
 }
 else
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 size++;
}

c)

public void function(Object item)
{
 Node temp = new Node(item,null);
 if(isEmpty())
 {
  Node cur = head.getNext();
  temp.setNext(cur);
  head.setNext(temp);
 }
 else
 {
  temp.setNext(trail);
  head.setNext(temp);
 }
 size++;
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q223.
What is the functionality of the following piece of code?
public void function(Object item)
{
	Node temp=new Node(item,trail);
	if(isEmpty())
	{
		head.setNext(temp);
		temp.setNext(trail);
	}
	else
	{
		Node cur=head.getNext();
		while(cur.getNext()!=trail)
		{
			cur=cur.getNext();
		}
		cur.setNext(temp);
	}
	size++;
}
Discuss
Answer: (b).Insert at the rear end of the dequeue
Discuss
Answer: (d).All of the mentioned
Q225.
Which of the following can be used to delete an element from the front end of the queue?
a)

public Object deleteFront() throws emptyDEQException
{
 if(isEmpty())
  throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = temp;
  Object e = temp.getEle();
  head.setNext(cur);
  size--;
  return e;
 }
}

b)

public Object deleteFront() throws emptyDEQException
{
 if(isEmpty())
  throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = temp.getNext();
  Object e = temp.getEle();
  head.setNext(cur);
  size--;
  return e;
 }
}

c)

public Object deleteFront() throws emptyDEQException
{
 if(isEmpty())
  throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = temp.getNext();
  Object e = temp.getEle();
  head.setNext(temp);
  size--;
  return e;
 }
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (b).b
Q226.
Which of the following can be used to delete an element from the rear end of the queue?
a)

public Object deleteRear() throws emptyDEQException
{
 if(isEmpty())
  throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = temp;
  while(temp.getNext() != trail)
  {
   temp = temp.getNext();
   cur = cur.getNext();
  }
  Object e = temp.getEle();
  cur.setNext(trail);
  size--;
  return e;
 }
}

b)

public Object deleteRear() throws emptyDEQException
{
 if(isEmpty())
  throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = head;
  while(temp != trail)
  {
   temp = temp.getNext();
   cur = cur.getNext();
  }
  Object e = temp.getEle();
  cur.setNext(trail);
  size--;
  return e;
 }
}

c)

public Object deleteRear() throws emptyDEQException
{
 if(isEmpty())
 throw new emptyDEQException("Empty");
 else
 {
  Node temp = head.getNext();
  Node cur = head;
  while(temp.getNext()!=trail)
  {
   temp = temp.getNext();
   cur = cur.getNext();
  }
  Object e = temp.getEle();
  cur.setNext(trail);
  size--;
  return e;
 }
}

d) None of the mentioned
Discuss
Answer: (c).c
Q227.
What is the time complexity of deleting from the rear end of the dequeue implemented with a singly linked list?
Discuss
Answer: (c).O(n)
Q228.
After performing these set of operations, what does the final list look contain?

InsertFront(10);

InsertFront(20);

InsertRear(30);

DeleteFront();

InsertRear(40);

InsertRear(10);

DeleteRear();

InsertRear(15);

display();
Discuss
Answer: (d).10 30 40 15
Q229.
To implement a stack using queue(with only enqueue and dequeue operations), how many queues will you need?

a.

1

b.

2

c.

3

d.

4

Discuss
Answer: (b).2
Q230.
Making the push operation costly, select the code snippet which implements the pop operation.
a)

public void pop()
{
        if(q1.size()>0)
        {
            q2.poll();
        }
        else if(q2.size()>0)
        {
            q1.poll();
        }
}

b)

public void pop()
{
        if(q1.size()>0)
        {
            q1.poll();
        }
        else if(q2.size()>0)
        {
            q2.poll();
        }
}

c)

public void pop()
{
        q1.poll();
 q2.poll();
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (b).b

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!