1,934 views
0 0 votes
Given a head pointer what is the time complexity:

1. To insert the element at front

2.To delete the element at front

3.To insert the element at end

4.To delete the element at front

5.To insert the element at the middle

To delete the element at the middle

1 Answer

0 0 votes
Given that circular single linked list

a) To insert element at front  =  O(1)   [  Just involves head pointer ]

b) To delete element at the front  =  O(1)  [ Just involves head pointer ]

c) To insert the element at the end = O(n) [ Since we are given only head pointer only ]

d) To delete element at the end  =  O(n) [ Same as in c) ]

e) To insert element at the middle  = O(n) [ As we need to go to middle hence O(n) ]

f) To delete element at the middle = O(n) [ Same as in e) ]
• edited by
Position:
Show:

Related questions

4 4 votes
1 answers 1 answer
24.4k
24.4k views
hacker16 asked Nov 14, 2017
24,433 views
In circular singly linked list, insertion of node requires modification of how many pointers?1 pointers2 pointers3 pointers 4 pointers
2 2 votes
1 1 answer
3.6k
3.6k views
radha gogia asked Jul 22, 2015
3,560 views
I am not getting that when head pointer has no information regarding the tail pointer then how is it that circular linked list will have a constant time for its concatena...
6 6 votes
3 3 answers
201
201 views
GO Classes asked Jul 8
201 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...
6 6 votes
3 3 answers
204
204 views
GO Classes asked Jul 6
204 views
A circular linked list has $n$ nodes. A function prints every node exactly once and stops when it reaches the starting node again.What is the running time of printing the...