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

Explore more Topics under Data Structures and Algorithms

Q241.
Which data structure can be used suitably to solve the Tower of Hanoi problem?
Discuss
Answer: (d).Stack
Q242.
Select the appropriate code for the recursive Tower of Hanoi problem.(n is the number of disks)
a)

public void solve(int n, String start, String auxiliary, String end)
{
       if (n == 1) 
       {
           System.out.println(start + " -> " + end);
       } 
       else
       {
           solve(n - 1, start, end, auxiliary);
           System.out.println(start + " -> " + end);
           solve(n - 1, auxiliary, start, end);
       }
}

b)

public void solve(int n, String start, String auxiliary, String end) 
{
       if (n == 1) 
       {
           System.out.println(start + " -> " + end);
       } 
       else 
       {
           solve(n - 1, auxiliary, start, end);
           System.out.println(start + " -> " + end);
       }
}

c)

public void solve(int n, String start, String auxiliary, String end) 
{
       if (n == 1) 
       {
           System.out.println(start + " -> " + end);
       } 
       else 
       {
           System.out.println(start + " -> " + end);
    solve(n - 1, auxiliary, start, end);
       }
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q243.
Which among the following is not a palindrome?
Discuss
Answer: (d).Maadam
Q244.
Which data structure can be used to test a palindrome?
Discuss
Answer: (c).Stack
Q245.
Select the appropriate code which tests for a palindrome.
a)

public static void main(String[] args) 
{
 System.out.print("Enter any string:");
        Scanner in=new Scanner(System.in);
        String input = in.nextLine();
        Stack<Character> stk = new Stack<Character>();
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String reverse = "";
 while (!stk.isEmpty())
 {
            reverse = reverse + stk.pop();
        }
 if (input.equals(reverse))
        System.out.println("palindrome");
        else
        System.out.println("not a palindrome");
}

b)

public static void main(String[] args) 
{
 System.out.print("Enter any string:");
        Scanner in=new Scanner(System.in);
        String input = in.nextLine();
        Stack<Character> stk = new Stack<Character>();
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String reverse = "";
 while (!stk.isEmpty())
 {
            reverse = reverse + stk.peek();
        }
 if (input.equals(reverse))
        System.out.println("palindrome");
        else
            System.out.println("not a palindrome");
}

c)

public static void main(String[] args) 
{
 System.out.print("Enter any string:");
        Scanner in=new Scanner(System.in);
        String input = in.nextLine();
        Stack<Character> stk = new Stack<Character>();
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String reverse = "";
 while (!stk.isEmpty())
 {
            reverse = reverse + stk.pop();
   stk.pop();
        }
 if (input.equals(reverse))
        System.out.println("palindrome");
        else
            System.out.println("not a palindrome");
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q246.
What is the number of moves required in the Tower of Hanoi problem for k disks?
Discuss
Answer: (d).2^k – 1
Q247.
Select the appropriate code which reverses a word.
a)

public String reverse(String input)
{
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String rev = "";
 while (!stk.isEmpty())
 {
            rev = rev + stk.peek();
        }
 return rev;
}

b)

public String reverse(String input)
{
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String rev = "";
 while (!stk.isEmpty())
 {
            rev = rev + stk.pop();
        }
 return rev;
}

c)

public String reverse(String input)
{
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String rev = "";
 while (!stk.isEmpty())
 {
            rev = rev + stk.pop();
        }
}

d)

public String reverse(String input)
{
 for (int i = 0; i < input.length(); i++) 
 {
            stk.push(input.charAt(i));
        }
 String rev = "";
 while (!stk.isEmpty())
 {
            rev = rev + stk.pop();
     stk.pop();
        }
 return rev;
}

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!