CARVIEW |
stack and queue pune contest
Question 1
The data structure required for Breadth First Traversal on a graph is?
stack
queue
array
tree
Question 2
A queue follows __________
FIFO (First In First Out) principle
LIFO (Last In First Out) principle
Ordered array
Linear tree
Question 3
A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
Queue
Circular queue
Dequeue
Priority queue
Question 4
Consider the usual algorithm for determining whether a sequence of parentheses is balanced. The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
1
2
3
4 or more
Question 5
Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation?
1
2
3
4 or more
Question 6
Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?
1
2
3
4
Question 7
What will be the output of the following code?
// Include necessary header files #include <iostream> #include <stack> // Start of the main function int main() { // Create a stack of integers stack<int> stack; // Push elements onto the stack stack.push(21); stack.push(31); stack.push(41); stack.push(51); // Pop elements from the stack stack.pop(); stack.pop(); // Print elements remaining in the stack while (!stack.empty()) { // Print the top element of the stack print stack.top() // Pop the top element from the stack stack.pop(); } // End of the main function }
21 31
31 41
31 21
41 51
Question 8
What will be the output of the following program?
#include <iostream> #include <queue> using namespace std; int main() { queue<int> myqueue; myqueue.push(80); myqueue.push(70); myqueue.push(60); myqueue.push(50); if (myqueue.front() > myqueue.back()) { cout << myqueue.front() - myqueue.back(); } else if (myqueue.front() < myqueue.back()) { cout << myqueue.back() - myqueue.front(); } else cout << "0"; }
50
70
30
130
Question 9
What is the complexity of the swap() member function of the queue STL in C++?
O(1)
O(n)
O(log n)
O(n log n)
Question 10
Consider a standard Circular Queue 'q' implementation (which has the same condition for Queue Full and Queue Empty) whose size is 11 and the elements of the queue are q[0], q[1], q[2].....,q[10]. The front and rear pointers are initialized to point at q[2] . In which position will the ninth element be added?
q[0]
q[1]
q[9]
q[10]
There are 10 questions to complete.