Skip to content

Sorting Algorithms

vinayak edited this page Jan 24, 2020 · 3 revisions

index


  1. Selection Sort
  2. Bubble Sort
  3. Recursive Bubble Sort
  4. Insertion Sort
  5. Recursive Insertion Sort
  6. Merge Sort
  7. Iterative Merge Sort
  8. Quick Sort
  9. Iterative Quick Sort
  10. Heap Sort
  11. Counting Sort
  12. Radix Sort
  13. Bucket Sort
  14. ShellSort
  15. TimSort
  16. Comb Sort
  17. Pigeonhole Sort
  18. Cycle Sort
  19. Cocktail Sort
  20. Strand Sort
  21. Bitonic Sort
  22. Pancake sorting
  23. Binary Insertion Sort
  24. BogoSort or Permutation Sort
  25. Gnome Sort
  26. Sleep Sort – The King of Laziness / Sorting while Sleeping
  27. Structure Sorting (By Multiple Rules)
  28. Stooge Sort
  29. Tag Sort (To get both sorted and original)
  30. Tree Sort
  31. Cartesian Tree Sorting
  32. Odd-Even Sort / Brick Sort
  33. QuickSort on Singly Linked List
  34. QuickSort on Doubly Linked List
  35. 3-Way QuickSort (Dutch National Flag)
  36. Merge Sort for Linked Lists
  37. Merge Sort for Doubly Linked List
  38. 3-way Merge Sort

Selection sort

**selection sort**, algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
  1. The subarray which is already sorted.
  2. Remaining subarray which is unsorted.
  3. In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.

    Properties:

    • Worst-case performance O(n^2)
    • Best-case performance O(n)
    • Average case performance O(n^2)

    read more at: Wikipedia
    code: Bubble sort


    Bubble sort

    Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. It can be practical if the input is usually in sorted order but may occasionally have some out-of-order elements nearly in position.

    Properties:

    • Worst-case performance O(n^2)
    • Best-case performance O(n)
    • Average case performance O(n^2)

    read more at: Wikipedia
    code: Bubble sort


    Insertion sort

    Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

    Properties:

    • Worst-case performance O(n^2)
    • Best-case performance O(n)
    • Average case performance O(n^2)

    read more at: Wikipedia
    code: Insertion sort

Clone this wiki locally