1.

Why is merge sort a better option than quicksort for linked lists?

Answer»
  • When it comes to linked lists, there are a few things to keep in mind. The issue is unique due to the memory allocation differences between arrays and linked lists. Unlike arrays, linked list nodes in memory may not be adjacent.
  • We can insert items in the MIDDLE of a linked list in O(1) extra space and O(1) time if we are GIVEN a reference/pointer to the previous node, unlike an array. As a result, the merge SORT operation can be accomplished WITHOUT the need for additional linked list space.
  • We can do random access in arrays since the elements are continuous in memory. In contrast to arrays, we can't access a linked list at random.
  • Quick Sort necessitates a great deal of this type of access. Because we don't have a continuous block of memory, we have to travel from the head to the i'th node to get to the i'th index in a linked list. Merge sort accesses data in a sequential manner, with less requirement for random access.


Discussion

No Comment Found