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

Q181.
What is the functionality of the following piece of Java code?
Assume: ‘a’ is a non empty array of integers, the Stack class creates an array of specified size and provides a top pointer indicating TOS(top of stack), push and pop have normal meaning.
public void some_function(int[] a)
{
 Stack S=new Stack(a.length);
 int[] b=new int[a.length];
 for(int i=0;i<a.length;i++)
 {
  S.push(a[i]);
 }
 for(int i=0;i<a.length;i++)
 {
  b[i]=(int)(S.pop());
 }
 System.out.println("output :");
 for(int i=0;i<b.length;i++)
 {
  System.out.println(b[i]);
 }
}
Discuss
Answer: (d).reverse the array
Q182.
‘Array implementation of Stack is not dynamic’, which of the following statements supports this argument?
Discuss
Answer: (a).space allocation for array is fixed and cannot be changed during run-time
Q183.
Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N).
Discuss
Answer: (a).S[N-1].
Q184.
What is the complexity of searching for a particular element in a Singly Linked List?
Discuss
Answer: (a).O(n)
Q185.
Which of the following statements are correct with respect to Singly Linked List(SLL) and Doubly Linked List(DLL)?
Discuss
Answer: (d).All of the mentioned
Q186.
Given below is the Node class to perform basic list operations and a Stack class with a no arg constructor.
Select from the options the appropriate pop() operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.
class Node
{
 protected Node next;
 protected Object ele;
 Node()
 {
  this(null,null);
 }
 Node(Object e,Node n)
 {
  ele=e;
  next=n;
 }
 public void setNext(Node n)
 {
  next=n;
 }
 public void setEle(Object e)
 {
  ele=e;
 }
 public Node getNext()
 {
  return next;
 }
 public Object getEle()
 {
  return ele;
 }
}
 
class Stack
{
 Node first;
 int size=0;
 Stack()
 {
  first=null;
 }
}

a)

public Object pop() 
{
 if(size == 0)
 System.out.println("underflow");
 else
 {
  Object o = first.getEle();
  first = first.getNext();
  size--;
  return o;
 }
}

b)

public Object pop() 
{
 if(size == 0)
 System.out.println("underflow");
 else
 {
  Object o = first.getEle();
  first = first.getNext().getNext();
  size--;
  return o;
 }
}

c)

public Object pop() 
{
 if(size == 0)
 System.out.println("underflow");
 else
 {
  first = first.getNext();
  Object o = first.getEle();
  size--;
  return o;
 }
}

d)

public Object pop() 
{
 if(size == 0)
 System.out.println("underflow");
 else
 {
  first = first.getNext().getNext();
  Object o = first.getEle();
  size--;
  return o;
 }
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q187.
What does the following function do?
public Object some_func()throws emptyStackException
{
 if(isEmpty())
  throw new emptyStackException("underflow");
 return first.getEle();
}
Discuss
Answer: (c).retrieve the top-of-the-stack element
Q188.
What is the functionality of the following piece of code?
public void display() 
{
	if(size == 0)
		System.out.println("underflow");
	else
	{
		Node current = first;
		while(current != null)
		{
			System.out.println(current.getEle());
			current = current.getNext();
		}
	}
}
Discuss
Answer: (b).display the list
Discuss
Answer: (b).adding items to a full stack
Q190.
Given below is the Node class to perform basic list operations and a Stack class with a no arg constructor. Select from the options the appropriate push() operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.

class Node
{
 protected Node next;
 protected Object ele;
 Node()
 {
  this(null,null);
 }
 Node(Object e,Node n)
 {
  ele=e;
  next=n;
 }
 public void setNext(Node n)
 {
  next=n;
 }
 public void setEle(Object e)
 {
  ele=e;
 }
 public Node getNext()
 {
  return next;
 }
 public Object getEle()
 {
  return ele;
 }
}
 
class Stack
{
 Node first;
 int size=0;
 Stack()
 {
  first=null;
 }
}
a)

public void push(Object item)
{
 Node temp = new Node(item,first);
 first = temp;
 size++;
}
b)

public void push(Object item)
{
 Node temp = new Node(item,first);
 first = temp.getNext();
 size++;
}
c)

public void push(Object item)
{
 Node temp = new Node();
 first = temp.getNext();
 first.setItem(item);
 size++;
}
d) none of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a

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!