Knowledge Card - Sorting Techniques

Sorting Techniques

  1. Selection Sort: Repeatedly selects the smallest element and places it at the beginning.

    • Example: [3, 1, 4, 1, 5] becomes [1, 1, 3, 4, 5].
  2. Bubble Sort: Repeatedly swaps adjacent elements if they are in the wrong order.

    • Example: [5, 3, 1] becomes [1, 3, 5] after multiple passes.
  3. Insertion Sort: Builds the final sorted list one item at a time.

    • Example: [3, 1, 2] becomes [1, 2, 3] by inserting elements in order.
  4. Efficiency Comparison: Discuss the time complexity of each algorithm.

    • Example: Selection sort is O(n²), while more advanced algorithms like quicksort can be O(n log n).