1,460 views
0 votes
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 votes
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

Related questions

3 votes
3 votes
1 answer
1
hacker16 asked Nov 14, 2017
21,423 views
In circular singly linked list, insertion of node requires modification of how many pointers?1 pointers2 pointers3 pointers 4 pointers
0 votes
0 votes
2 answers
3
0 votes
0 votes
2 answers
4
Parshu gate asked Nov 19, 2017
516 views
Please explain how to approach this problem?