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 -
0 Comments