VOOZH about

URL: https://www.geeksforgeeks.org/dsa/quicksort-on-singly-linked-list/

⇱ QuickSort on Singly Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

QuickSort on Singly Linked List

Last Updated : 3 May, 2026

Given a linked list, apply the Quick sort algorithm to sort the linked list. To sort the Linked list change pointers rather than swapping data.

Example:

Input:

👁 2056957888

Output :

👁 2056957889


Input:

👁 2056957890

Output: 

👁 2056957891

Quick Sort follows these steps.

  • Selecting a pivot from the linked list, typically the last node.
  • The linked list is then partitioned such that all elements smaller than the pivot are placed on the left, while those greater than the pivot are placed on the right.
  • Once the partitioning is complete, the algorithm recursively applies the same process to the left and right linked lists.
  • The sorted left list, pivot and right list are combined to get the complete sorted list.

Output
3 4 5 20 30 
  • Time Complexity: O(n * log n), It takes O(n2) time in the worst case and O(n log n) in the average or best case.
  • Auxiliary Space: O(n)
Comment