edited by
2,289 views
0 votes
0 votes
What is the time complexity to insert a new Node in a singly circular linked list at Starting ? (Number of nodes in list = N)

A. O(1)

B. O(N)
edited by

2 Answers

2 votes
2 votes
O(N) is the answer because it is single circular linked list so adding a node at star will take constant time but last node point to new node which is inserted so for this linked we should go to last node which take N time
0 votes
0 votes

If you have pointer to the first node

Insertion at beginning: O(n)

Insertion at the end: O(n) // As you have to traverse till the end. 

If you have pointer to the last node

Insertion at beginning: O(1)

Insertion at end: O(1)

Check this: https://gateoverflow.in/1033/gate2004-36

edited by

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
0 answers
2