edited by
518 views
0 votes
0 votes
What will be the complexity of merging two circular single linked list? You can consider the sizes of the linked lists are n1 and n2, respectively.
edited by

4 Answers

0 votes
0 votes

I think answer should be O(1), because we just have to merge linked list and not having any constraint of maintain sorting.

For more details refer this website-

data structures - Linked List Concatenation In O(1) Time - Stack Overflow

0 votes
0 votes

@amit166

The time complexity of this method will be O(m * n) where m and n are the numbers of nodes in two lists....

You can't do it with an array implementation, because you end up having to allocate more memory and copy the new resulting list to it...

Even if the array already has memory allocated, you still have to copy all of the new items to it...

So it's either O(m+n) or O(n) (where m and n are the lengths of the individual lists, respectively)…

 

1. https://gateoverflow.in/2220/Gate-cse-1997-question-1-4 

 

2. https://gateoverflow.in/217564/Gate-cs-mock-2018

 

3. https://gateoverflow.in/13746/Does-concatenation-circular-linked-lists-takes-constant-time

 

 

0 votes
0 votes
In case of simple linked list, complexity of merging takes : O(n1+n2) {We need to find both list tail by using

The Tortoise and the Hare (Floyd’s Algorithm)}

while in case of Doubly linked list : O(1) {Change of few pointers}

Related questions

0 votes
0 votes
0 answers
1
Sankaranarayanan P.N asked Oct 27, 2016
373 views
Let P be a singly linked list. Let Q be the pointer to an intermediate node X in the list. What is the worst case time complexity of the best known algorithm to delete no...