Recent questions tagged queue

2 2 votes
1 1 answer
125
125 views
BFS is performed from the root of a binary tree containing $n$ vertices.For which type of binary tree can BFS require $\Theta(n)$ extra space in the worst case?A complete...
2 2 votes
1 1 answer
117
117 views
Consider the standard BFS algorithm, except for one modification:A vertex is marked as visited only when it is removed from the queue, instead of when it is first inserte...
2 2 votes
1 1 answer
107
107 views
Consider two vertices $x$ and $y$ that are simultaneously on the FIFO queue at some point during the execution of breadth-first search from $s$ in an undirected graph.Whi...
9 9 votes
2 2 answers
353
353 views
Given a stack $S$ with $5$ elements from top to bottom as:$2, 4, 6, 8, 10$and an empty queue $Q$.First, remove the elements one by one from $S$ and insert them into $Q$.T...
7 7 votes
1 1 answer
396
396 views
Which of the following statements are true?$\text{S1.}$ Stack operations $\texttt{push}$, $\texttt{pop}$, and $\texttt{isEmpty}$ can be worst-case $O(1)$ for a linked-lis...
0 0 votes
1 1 answer
89
89 views
A queue follows FIFO order. Consider the following operations on an initially empty queue:q = [] q.append("A") q.append("B") q.append("C") x = q.pop(0) q.append("D") y = ...
0 0 votes
1 1 answer
113
113 views
A queue is to be implemented using two stacks and only a constant amount of extra memory. Which of the following correctly implements queue behavior with constant amortiz...
0 0 votes
1 1 answer
75
75 views
Give the running time of each operation in the following queue class, where the item most recently inserted is at $\texttt{_a[0]}$.class Queue: def __init__(self): self._...
0 0 votes
1 1 answer
67
67 views
Give the running time of each operation in the following queue class, where the item least recently inserted is at $\texttt{_a[0]}$.class Queue: def __init__(self): self....
4 4 votes
1 1 answer
173
173 views
Suppose a client performs an intermixed sequence of $\texttt{enqueue}$ and $\texttt{dequeue}$ operations on a queue. The enqueue operations put the integers $0$ through $...
7 7 votes
3 3 answers
293
293 views
A queue is implemented using two stacks $\text{S1}$ and $\text{S2}$.Use the implementation where $\texttt{dequeue()}$ is $\text{O(1)}$ by keeping the front of the queue a...
4 4 votes
2 2 answers
184
184 views
Suppose a circular queue of capacity $(n - 1)$ elements is implemented with an array of $n$ elements.Insertion and deletion operations are carried out using $\texttt{REAR...
6 6 votes
3 3 answers
187
187 views
A FIFO queue is represented using a circular linked list and only one external pointer $\text{Q}$.Design $1: \text{Q}$ points to the node containing the front item. Desig...
8 8 votes
2 2 answers
193
193 views
Consider an array implementation of a queue. Suppose we try to keep all items at the front of a partially-filled array, so that $\texttt{data[0]}$ is always the front of ...
6 6 votes
3 3 answers
178
178 views
Consider an initially empty stack $\text{S}$ and an initially empty queue $\text{Q}$.The following operations are performed:S.push(5) S.push(6) S.push(S.top()) S.push(7) ...
14 14 votes
4 4 answers
2.1k
2.1k views
Consider a stack $S$ and a queue $Q$. Both of them are initially empty and have the capacity to store ten elements each. The elements $1,2,3,4$, and $5$ arrive one by one...
0 0 votes
1 1 answer
301
301 views
You were given an array of distinct elements of size n with indices starting from 0.-Every $(2i)^{th}$ element is pushed into a stack.-Every $(2i+1)^{th}$ element is enqu...
3 3 votes
1 1 answer
615
615 views
Suppose that we use a linked list to represent a queue and that in addition to the enqueue and dequeue functions add a new operation to the queue that deletes the last el...
1 1 vote
1 1 answer
575
575 views
What shall be the average waiting time per process if we know that $10$ processes (on average) arrive every second and there are normally $20$ processes in the queue?$03$...
2 2 votes
1 1 answer
357
357 views
Match List I with List II$\begin{array}{|ll|ll|} \hline & \textbf{List I} & & \textbf{List II} \\ \hline \text{A.} & \text{Circular Queue} & \text{I.} & \text{Print Queue...
2 2 votes
1 1 answer
345
345 views
Which of the following uses only increment operations for adding and removing element at either end?QueuesStacksPriority QueuesDeques
2 2 votes
1 1 answer
187
187 views
Which of the following is the primary operation for adding an element to a queue in $\text{C}?$EnqueueDequeuePushPop