Software Development Exam  >  Software Development Tests  >  DSA in C++  >  Test: Stacks and Queues - Software Development MCQ

Test: Stacks and Queues - Software Development MCQ


Test Description

15 Questions MCQ Test DSA in C++ - Test: Stacks and Queues

Test: Stacks and Queues for Software Development 2024 is part of DSA in C++ preparation. The Test: Stacks and Queues questions and answers have been prepared according to the Software Development exam syllabus.The Test: Stacks and Queues MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Stacks and Queues below.
Solutions of Test: Stacks and Queues questions in English are available as part of our DSA in C++ for Software Development & Test: Stacks and Queues solutions in Hindi for DSA in C++ course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Stacks and Queues | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study DSA in C++ for Software Development Exam | Download free PDF with solutions
Test: Stacks and Queues - Question 1

Which data structure follows the Last-In-First-Out (LIFO) principle?

Detailed Solution for Test: Stacks and Queues - Question 1

Stacks follow the Last-In-First-Out (LIFO) principle, where the last element added is the first one to be removed.

Test: Stacks and Queues - Question 2

Which data structure follows the First-In-First-Out (FIFO) principle?

Detailed Solution for Test: Stacks and Queues - Question 2

Queues follow the First-In-First-Out (FIFO) principle, where the first element added is the first one to be removed.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Stacks and Queues - Question 3

What is the time complexity for pushing an element onto a stack?

Detailed Solution for Test: Stacks and Queues - Question 3

Pushing an element onto a stack takes constant time, regardless of the stack's size.

Test: Stacks and Queues - Question 4

Which of the following operations is NOT supported by a stack?

Detailed Solution for Test: Stacks and Queues - Question 4

Enqueue is an operation supported by a queue, not a stack. Enqueue adds an element to the rear end of a queue.

Test: Stacks and Queues - Question 5

Which of the following is an example of a stack implementation?

Detailed Solution for Test: Stacks and Queues - Question 5

Depth-First Search (DFS) is an example of a graph traversal algorithm that uses a stack to keep track of vertices.

Test: Stacks and Queues - Question 6

What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;

int main() {
   stack<int> myStack;
   myStack.push(10);
   myStack.push(20);
   myStack.push(30);
   cout << myStack.top() << endl;
   myStack.pop();
   cout << myStack.top() << endl;
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 6

The code pushes the elements 10, 20, and 30 onto the stack. The top() function returns the value at the top of the stack, which is 30. After popping an element, the new top is 20.

Test: Stacks and Queues - Question 7

What will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;

int main() {
   queue<int> myQueue;
   myQueue.push(5);
   myQueue.push(10);
   myQueue.push(15);
   cout << myQueue.front() << endl;
   myQueue.pop();
   cout << myQueue.front() << endl;
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 7

The code pushes the elements 5, 10, and 15 onto the queue. The front() function returns the value at the front of the queue, which is 5. After popping an element, the new front is 10.

Test: Stacks and Queues - Question 8

What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;

int main() {
   stack<int> myStack;
   myStack.push(1);
   myStack.push(2);
   myStack.push(3);
   while (!myStack.empty()) {
       cout << myStack.top() << " ";
       myStack.pop();
   }
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 8

The code pushes the elements 1, 2, and 3 onto the stack. The while loop pops elements from the stack and prints them until the stack becomes empty.

Test: Stacks and Queues - Question 9

What will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;

int main() {
   queue<int> myQueue;
   myQueue.push(1);
   myQueue.push(2);
   myQueue.push(3);
   while (!myQueue.empty()) {
       cout << myQueue.front() << " ";
       myQueue.pop();
   }
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 9

The code pushes the elements 1, 2, and 3 onto the queue. The while loop dequeues elements from the queue and prints them until the queue becomes empty.

Test: Stacks and Queues - Question 10

What will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;

int main() {
   stack<int> myStack;
   myStack.push(10);
   myStack.push(20);
   myStack.push(30);
   myStack.pop();
   cout << myStack.size() << endl;
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 10

The code pushes the elements 10, 20, and 30 onto the stack. After popping an element, the size() function returns the number of elements remaining in the stack, which is 2.

Test: Stacks and Queues - Question 11

Given a stack st with elements [1, 2, 3, 4, 5], what will be the output of the following code?
#include <iostream>
#include <stack>
using namespace std;

void display(stack<int>& st) {
   while (!st.empty()) {
       cout << st.top() << " ";
       st.pop();
   }
}

int main() {
   stack<int> st;
   st.push(1);
   st.push(2);
   st.push(3);
   display(st);
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 11

The display() function pops elements from the stack and prints them until the stack becomes empty. The elements are printed in the reverse order of their insertion, resulting in "3 2 1".

Test: Stacks and Queues - Question 12

Given a queue q with elements [1, 2, 3, 4, 5], what will be the output of the following code?
#include <iostream>
#include <queue>
using namespace std;

void display(queue<int>& q) {
   while (!q.empty()) {
       cout << q.front() << " ";
       q.pop();
   }
}

int main() {
   queue<int> q;
   q.push(1);
   q.push(2);
   q.push(3);
   display(q);
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 12

The display() function dequeues elements from the queue and prints them until the queue becomes empty. The elements are printed in the order of their insertion, resulting in "1 2 3".

Test: Stacks and Queues - Question 13

Given an input string s = "abcde", which of the following code snippets correctly stores the characters of the string into a stack st?
(I) 
stack<char> st;
for (int i = 0; i < s.length(); i++) {
    st.push(s[i]);
}
(II) 
stack<char> st;
for (int i = s.length() - 1; i >= 0; i--) {
    st.push(s[i]);
}

(III) 
stack<char> st;
for (int i = 0; i < s.length(); i++) {
    st.push_back(s[i]);
}

Detailed Solution for Test: Stacks and Queues - Question 13

The code snippet II correctly stores the characters of the input string into a stack by iterating over the string in reverse order.

Test: Stacks and Queues - Question 14

Given an input string s = "abcde", which of the following code snippets correctly stores the characters of the string into a queue q?
(I)
queue<char> q;
for (int i = 0; i < s.length(); i++) {
    q.push(s[i]);
}
(II)
queue<char> q;
for (int i = s.length() - 1; i >= 0; i--) {
    q.push(s[i]);
}
(III)
queue<char> q;
for (int i = 0; i < s.length(); i++) {
    q.push_back(s[i]);
}

Detailed Solution for Test: Stacks and Queues - Question 14

The code snippet I correctly stores the characters of the input string into a queue by iterating over the string in the normal order.

Test: Stacks and Queues - Question 15

Given a stack st with elements [1, 2, 3, 4, 5], what will be the value of x after the following code execution?
#include <iostream>
#include <stack>
using namespace std;

int main() {
   stack<int> st;
   st.push(1);
   st.push(2);
   st.push(3);
   int x = st.top();
   st.pop();
   x += st.top();
   return 0;
}

Detailed Solution for Test: Stacks and Queues - Question 15

The code stores the value at the top of the stack (3) in variable x. Then, it pops an element from the stack and adds its value (2) to x. Therefore, x becomes 3 + 2 = 5.

153 videos|115 docs|24 tests
Information about Test: Stacks and Queues Page
In this test you can find the Exam questions for Test: Stacks and Queues solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Stacks and Queues, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

153 videos|115 docs|24 tests
Download as PDF

Top Courses for Software Development