Skip to main content
deleted 57 characters in body
Source Link
Yuval Filmus
  • 279.1k
  • 27
  • 316
  • 512

I've been looking over sorting algorithms for linked list and I here's what I came up with.

As we know, for element access arrays will work better than linked list also. Also, there is the benefit of elements being stored in consecutive memory location andlocations: due to spatial locality of cache, arrays give better performance.

Thus for sorting linked list: 1)Extract all elements from linked list to a array : O(n)

2)Sort the array using Quick Sort : Theta(n logn)

3)Store the elements in Linked List : O(n)

  1. Extract all elements from linked list to a array: $O(n)$

  2. Sort the array using quicksort: $\Theta(n \log n)$

  3. Store the elements in linked list: $O(n)$

Is this approach better than all the other approachapproaches for sorting linked lists such as this :using merge sort directly, as described on Algorithmgeeksforgeeks.

If there's anything missing in my question or if you feel to down vote, please comment it. Thanks

I've been looking over sorting algorithms for linked list and I here's what I came up with.

As we know for element access arrays will work better than linked list also there is benefit of elements being stored in consecutive memory location and due to spatial locality of cache, arrays give better performance.

Thus for sorting linked list: 1)Extract all elements from linked list to a array : O(n)

2)Sort the array using Quick Sort : Theta(n logn)

3)Store the elements in Linked List : O(n)

Is this approach better than all the other approach for sorting linked lists such as this : Algorithm.

If there's anything missing in my question or if you feel to down vote, please comment it. Thanks

I've been looking over sorting algorithms for linked list and here's what I came up with.

As we know, for element access arrays will work better than linked list. Also, there is the benefit of elements being stored in consecutive memory locations: due to spatial locality of cache, arrays give better performance.

Thus for sorting linked list:

  1. Extract all elements from linked list to a array: $O(n)$

  2. Sort the array using quicksort: $\Theta(n \log n)$

  3. Store the elements in linked list: $O(n)$

Is this approach better than other approaches for sorting linked lists such as using merge sort directly, as described on geeksforgeeks.

Source Link
manjy
  • 41
  • 3

Sorting elements of linked list

I've been looking over sorting algorithms for linked list and I here's what I came up with.

As we know for element access arrays will work better than linked list also there is benefit of elements being stored in consecutive memory location and due to spatial locality of cache, arrays give better performance.

Thus for sorting linked list: 1)Extract all elements from linked list to a array : O(n)

2)Sort the array using Quick Sort : Theta(n logn)

3)Store the elements in Linked List : O(n)

Is this approach better than all the other approach for sorting linked lists such as this : Algorithm.

If there's anything missing in my question or if you feel to down vote, please comment it. Thanks