Qualcomm Stacks and Queue Quiz-1

Question 1

Time: 00:00:00
How many queues are needed to implement a stack? Consider the situation where no other data structure like arrays, the linked list is available to you?

1

1

2

2

3

3

4

4

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 2

Time: 00:00:00
A priority queue can efficiently implement using which of the following data structures? Assume that the number of inserts and peek (operation to see the current highest priority item) and extraction (remove the highest priority item) operations are almost same.

Array

Array

Linked List

Linked List

Heap Data Structures like Binary Heap, Fibonacci Heap

Heap Data Structures like Binary Heap, Fibonacci Heap

None of the above

None of the above

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 3

Time: 00:00:00
Suppose a circular queue of capacity (n – 1) elements are implemented with an array of n elements. Assume that the insertion and deletion operation is carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 4

Time: 00:00:00
An implementation of a queue Q, using two stacks S1 and S2, is given below:
void insert(Q, x) {
push (S1, x);
}

void delete(Q){
if(stack-empty(S2)) then
if(stack-empty(S1)) then {
print(“Q is empty”);
return;
}
else while (!(stack-empty(S1))){
x=pop(S1);
push(S2,x);
}
x=pop(S2);
}



Let n insert and m (<=n) delete operations be performed in an arbitrary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following is true for all m and n?

n+m <= x < 2n and 2m <= y <= n+m

n+m <= x < 2n and 2m <= y <= n+m

n+m <= x < 2n and 2m<= y <= 2n

n+m <= x < 2n and 2m<= y <= 2n

2m <= x < 2n and 2m <= y <= n+m

2m <= x < 2n and 2m <= y <= n+m

2m <= x <2n and 2m <= y <= 2n

2m <= x <2n and 2m <= y <= 2n

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 5

Time: 00:00:00
Consider the following pseudo code. Assume that IntQueue is an integer queue. What does the function fun do?
void fun(int n)
{
IntQueue q = new IntQueue();
q.enqueue(0);
q.enqueue(1);
for (int i = 0; i < n; i++)
{
int a = q.dequeue();
int b = q.dequeue();
q.enqueue(b);
q.enqueue(a + b);
ptint(a);
}
}

Prints numbers from 0 to n-1

Prints numbers from 0 to n-1

Prints numbers from n-1 to 0

Prints numbers from n-1 to 0

Prints first n Fibonacci numbers

Prints first n Fibonacci numbers

Prints first n Fibonacci numbers in reverse order.

Prints first n Fibonacci numbers in reverse order.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 6

Time: 00:00:00
Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?

A queue cannot be implemented using this stack.

A queue cannot be implemented using this stack.

A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.

A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.

A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.

A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.

A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 7

Time: 00:00:00
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?

Both operations can be performed in O(1) time

Both operations can be performed in O(1) time

At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n)

At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n)

The worst case time complexity for both operations will be Ω(n)

The worst case time complexity for both operations will be Ω(n)

Worst case time complexity for both operations will be Ω(log n)

Worst case time complexity for both operations will be Ω(log n)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 8

Time: 00:00:00
Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.



The maximum possible number of iterations of the while loop in the algorithm is______ [This Question was originally a Fill-in-the-Blanks question]

16

16

32

32

256

256

64

64

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 9

Time: 00:00:00
Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:
i. isEmpty (Q) — returns true if the queue is empty, false otherwise.
ii. delete (Q) — deletes the element at the front of the queue and returns its value.
iii. insert (Q, i) — insert the integer i at the rear of the queue.


Consider the following function:
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
i = delete(Q);
f(Q);
insert(Q, i);
}
}
What operation is performed by the above function f ?

Leaves the queue Q unchanged

Leaves the queue Q unchanged

Reverses the order of the elements in the queue Q

Reverses the order of the elements in the queue Q

Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order

Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order

Empties the queue Q

Empties the queue Q

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

["0","40","60","80","100"]
["Need more practice! \r\n","Keep trying! \r\n","Not bad! \r\n","Good work! \r\n","Perfect! \r\n"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.

Comments