2,225 views
1 votes
1 votes
1) Time complexity to insert a node in the end of circular linked list, if pointer to first node is given and the number of nodes in the list is N, is

1) O(1)

2)O(log N)

3)O(N)

4)O(N log N)

2 Answers

5 votes
5 votes

1) Add a node after first node, call it NewNode. 

2) Swap the firstNode's and NewNode's data.

3) Now change head pointer to point to head->next.

.

The head node is still 1 and we have just inserted the last node without travelling the entire node... So the time comoplexity is O(1)..

                                                                                 Authors- Vivek14 and Hirak

No related questions found