• retagged by
1,588 views
2 2 votes

A circular linked list is used to represents a queue. A single variable L is used to access the queue. To which node should L point such that both the operation enqueue and dequeue can be performed in constant time ?

  1.  node next to front
  2.  front node
  3.  not possible with a single node
  4.  rear node

3 Answers

1 1 vote
Answer is D) rear node because, from rear, we can go to front to delete and add a node(at rear) because we are at last node. We can't do this with any other node.
0 0 votes

Ans is C

0 0 votes

Enqueue is done at the rear.

Dequeue is done at the front.

 

So we need to point to a node such that we can access both the front and the rear easily (in $O(1)$ time).

In circular LL, if we point to the rear, we can access rear and front easily. So, Option D

// front == (rear + 1) mod n.

 


 

Why are other options incorrect?

If we point to the front, to access the rear node, we have to traverse all the way to the other end, ie, $O(n)$

So, Option B

By extension Option A

And obviously since rear node is the right answer, Option C

Answer:
Position:
Show:

Related questions

2 2 votes
1 answers 1 answer
2.2k
2.2k views
Bikram asked Nov 26, 2016
2,242 views
The initial configuration of a queue is a, b, c, d (a is in the front). To get the configuration d ,c, b, a, we need minimum number of:$2$ deletions & $3$ additions$3$ de...
1 1 vote
1 answers 1 answer
961
961 views
Bikram asked Nov 26, 2016
961 views
The concatenation of $2$ lists is to be performed in $O(1)$ time. Which of the following implementations should be used?array implementation of listdoubly linked listsing...
3 3 votes
2 answers 2 answers
2.5k
2.5k views
Bikram asked Nov 26, 2016
2,516 views
You are given a linked list, L, and another linked list, P, containing integers, sorted in ascending order. The operation print_lots(L,P) will print the elements in L tha...
2 2 votes
2 answers 2 answers
2.7k
2.7k views
Bikram asked Nov 26, 2016
2,713 views
Meena is working in an IT company as HR manager. She has a large list of potential candidates to be recruited which are all sorted by their names. But she found that due ...