611 views
0 votes
0 votes

My doubt is that the single list queue is the form : 1->2->3->4->5->6->7->8->9->NULL with 1 as the rear node and 9 as the front node. Also, in a queue, addition takes from the rear and the deletion from the front, so a structure like above should be there. Then deletion of front item should take O(n) time and rear item O(1) time, right? I just want to confirm whether my answer was right or the answer given.

Source : testbook.com live test on 3rd January, 2016

1 Answer

1 votes
1 votes
delete rear item from list takes O(n)

suppose list is 1-2-3-4

u delete 4

sow now u need to make pointer of node 3 null

so u will have to traverse list from starting to reach 3 and make pointer null

Related questions

1 votes
1 votes
1 answer
3
5 votes
5 votes
1 answer
4
hacker16 asked Nov 14, 2017
3,459 views
What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?O(n)O(1)θ(n2)θ...