Advertisement

Merge Two Sorted Linked Lists | No Extra Space | O(n) time complexity

Merge Two Sorted Linked Lists | No Extra Space | O(n) time complexity A Linked List is a list of nodes where each node points to the next node.

In this problem, we have two sorted linked lists. Our goal is to merge those two lists and have the resultant list in sorted order.

There are two approaches to this problem:

1. Brute Force (Naive Approach) - Merge the lists and then sort them. This has a time complexity of O(nlogn)

2. The Sorted Order Solution (aka the better solution) - This solution uses the fact that the lists are already sorted. We compare the current node from both the lists and add the smaller node to the new list. At the end, we get a merged sorted list. This solution has time complexity of O(n)

Link to the source code -

#mergesortedlinkedlists #linkedlists #datastructures #algorithms

++++++++++++++++++++++++++++++++++++++++++++++++++++

My General Tech Blog :
My Web Dev Focused Blog :
My Github URL :

++++++++++++++++++++++++++++++++++++++++++++++++++++

Sound Courtesy -

merge two sorted lists,merge sorted lists,merge two sorted linked lists,merge two sorted linked lists javascript,

Post a Comment

0 Comments