982 views
3 votes
3 votes

A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed in O(1)O(1) time?

(I) Next pointer of front node points to the rear node.

(II) Next pointer of rear node points to the front node.

(A) (I) only.

(B) (II) only.

(C) Both (I) and (II).

(D) Neither (I) nor (II).

I feel whatever be the order of the rear and front pointer it doesnt matter .....it will be O(1) for deletion and insertion

But the key says only B is right

would be helpful if someone explains this one

1 Answer

0 votes
0 votes
for option (i) if front ->rear then

 for insert a new node can take o(1): because new->=rear-> and rear->=new

but for delete a node from list: we find out a node which pointing the node front then from that node next=front-> then delete front which take o(n) time to find the node which next is fron.

Related questions

35 votes
35 votes
3 answers
4
go_editor asked Sep 28, 2014
16,728 views
Which one of the following correctly determines the solution of the recurrence relation with $T(1) = 1$?$$T(n)= 2T\left(\frac {n} {2}\right) + \log n$$$\Theta(n)$$\Theta(...