Episode 7 — DSA with JavaScript / 7.9 — Sorting Algorithms

7.9.a — Selection Sort & Insertion Sort

<< 7.9 Overview


Selection Sort

Find the minimum element and swap it to the front, repeatedly.

Array: [64, 25, 12, 22, 11]

Pass 1: Find min (11) → swap with index 0
  [11, 25, 12, 22, 64]

Pass 2: Find min in [25,12,22,64] (12) → swap with index 1
  [11, 12, 25, 22, 64]

Pass 3: Find min in [25,22,64] (22) → swap with index 2
  [11, 12, 22, 25, 64]

Pass 4: Find min in [25,64] (25) → already in place
  [11, 12, 22, 25, 64] ✓

JavaScript

function selectionSort(arr) {
    const n = arr.length;
    for (let i = 0; i < n - 1; i++) {
        let minIdx = i;
        for (let j = i + 1; j < n; j++) {
            if (arr[j] < arr[minIdx]) minIdx = j;
        }
        if (minIdx !== i) {
            [arr[i], arr[minIdx]] = [arr[minIdx], arr[i]];
        }
    }
    return arr;
}

C++

void selectionSort(vector<int>& arr) {
    int n = arr.size();
    for (int i = 0; i < n - 1; i++) {
        int minIdx = i;
        for (int j = i + 1; j < n; j++)
            if (arr[j] < arr[minIdx]) minIdx = j;
        if (minIdx != i) swap(arr[i], arr[minIdx]);
    }
}

Time: O(n²) always | Space: O(1) | Stable: No | Swaps: O(n)


Insertion Sort

Build sorted array one element at a time by inserting each element into its correct position.

Array: [5, 2, 4, 6, 1, 3]

Step 1: [5] | 2 → insert 2 → [2, 5]
Step 2: [2, 5] | 4 → insert 4 → [2, 4, 5]
Step 3: [2, 4, 5] | 6 → insert 6 → [2, 4, 5, 6]
Step 4: [2, 4, 5, 6] | 1 → insert 1 → [1, 2, 4, 5, 6]
Step 5: [1, 2, 4, 5, 6] | 3 → insert 3 → [1, 2, 3, 4, 5, 6] ✓

JavaScript

function insertionSort(arr) {
    for (let i = 1; i < arr.length; i++) {
        const key = arr[i];
        let j = i - 1;
        while (j >= 0 && arr[j] > key) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = key;
    }
    return arr;
}

C++

void insertionSort(vector<int>& arr) {
    for (int i = 1; i < arr.size(); i++) {
        int key = arr[i], j = i - 1;
        while (j >= 0 && arr[j] > key) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = key;
    }
}

Time: O(n²) worst, O(n) best (already sorted) | Space: O(1) | Stable: Yes

When insertion sort wins

  • Small arrays (n < 20)
  • Nearly sorted data (few inversions)
  • Online algorithm (can sort as data arrives)

Comparison

PropertySelection SortInsertion Sort
Best caseO(n²)O(n)
Worst caseO(n²)O(n²)
SwapsO(n)O(n²) worst
StableNoYes
AdaptiveNoYes
Use caseMinimize swapsNearly sorted data

Scenario bank (selection & insertion sort)

7.9a-001 — Trace selection sort on a given array (v1)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-002 — Trace insertion sort on a given array (v2)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-003 — Compare swap counts between sorts (v3)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-004 — Identify when insertion sort beats selection sort (v4)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-005 — Sort an array of strings using insertion sort (v5)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-006 — Implement selection sort for linked list (v6)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-007 — Count inversions using insertion sort (v7)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-008 — Sort nearly sorted array (k-sorted) (v8)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-009 — Implement binary insertion sort (v9)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-010 — Stability analysis with equal elements (v10)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-011 — Selection sort on 2D array by column (v11)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-012 — Insertion sort with custom comparator (v12)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-013 — Analyze best/worst cases with specific inputs (v13)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-014 — Sort by multiple keys (v14)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-015 — Implement in-place stable selection sort (v15)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-016 — Shell sort as insertion sort extension (v16)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-017 — Gnome sort comparison (v17)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-018 — Cocktail sort variation (v18)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-019 — Comb sort variation (v19)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-020 — Tim sort introduction (v20)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-021 — Trace selection sort on a given array (v21)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-022 — Trace insertion sort on a given array (v22)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-023 — Compare swap counts between sorts (v23)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-024 — Identify when insertion sort beats selection sort (v24)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-025 — Sort an array of strings using insertion sort (v25)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-026 — Implement selection sort for linked list (v26)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-027 — Count inversions using insertion sort (v27)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-028 — Sort nearly sorted array (k-sorted) (v28)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-029 — Implement binary insertion sort (v29)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-030 — Stability analysis with equal elements (v30)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-031 — Selection sort on 2D array by column (v31)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-032 — Insertion sort with custom comparator (v32)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-033 — Analyze best/worst cases with specific inputs (v33)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-034 — Sort by multiple keys (v34)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-035 — Implement in-place stable selection sort (v35)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-036 — Shell sort as insertion sort extension (v36)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-037 — Gnome sort comparison (v37)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-038 — Cocktail sort variation (v38)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-039 — Comb sort variation (v39)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-040 — Tim sort introduction (v40)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-041 — Trace selection sort on a given array (v41)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-042 — Trace insertion sort on a given array (v42)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-043 — Compare swap counts between sorts (v43)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-044 — Identify when insertion sort beats selection sort (v44)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-045 — Sort an array of strings using insertion sort (v45)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-046 — Implement selection sort for linked list (v46)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-047 — Count inversions using insertion sort (v47)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-048 — Sort nearly sorted array (k-sorted) (v48)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-049 — Implement binary insertion sort (v49)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-050 — Stability analysis with equal elements (v50)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-051 — Selection sort on 2D array by column (v51)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-052 — Insertion sort with custom comparator (v52)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-053 — Analyze best/worst cases with specific inputs (v53)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-054 — Sort by multiple keys (v54)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-055 — Implement in-place stable selection sort (v55)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-056 — Shell sort as insertion sort extension (v56)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-057 — Gnome sort comparison (v57)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-058 — Cocktail sort variation (v58)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-059 — Comb sort variation (v59)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-060 — Tim sort introduction (v60)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-061 — Trace selection sort on a given array (v61)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-062 — Trace insertion sort on a given array (v62)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-063 — Compare swap counts between sorts (v63)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-064 — Identify when insertion sort beats selection sort (v64)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-065 — Sort an array of strings using insertion sort (v65)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-066 — Implement selection sort for linked list (v66)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-067 — Count inversions using insertion sort (v67)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-068 — Sort nearly sorted array (k-sorted) (v68)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-069 — Implement binary insertion sort (v69)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-070 — Stability analysis with equal elements (v70)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-071 — Selection sort on 2D array by column (v71)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-072 — Insertion sort with custom comparator (v72)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-073 — Analyze best/worst cases with specific inputs (v73)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-074 — Sort by multiple keys (v74)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-075 — Implement in-place stable selection sort (v75)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-076 — Shell sort as insertion sort extension (v76)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-077 — Gnome sort comparison (v77)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-078 — Cocktail sort variation (v78)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-079 — Comb sort variation (v79)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-080 — Tim sort introduction (v80)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-081 — Trace selection sort on a given array (v81)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-082 — Trace insertion sort on a given array (v82)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-083 — Compare swap counts between sorts (v83)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-084 — Identify when insertion sort beats selection sort (v84)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-085 — Sort an array of strings using insertion sort (v85)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-086 — Implement selection sort for linked list (v86)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-087 — Count inversions using insertion sort (v87)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-088 — Sort nearly sorted array (k-sorted) (v88)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-089 — Implement binary insertion sort (v89)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-090 — Stability analysis with equal elements (v90)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-091 — Selection sort on 2D array by column (v91)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-092 — Insertion sort with custom comparator (v92)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-093 — Analyze best/worst cases with specific inputs (v93)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-094 — Sort by multiple keys (v94)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-095 — Implement in-place stable selection sort (v95)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-096 — Shell sort as insertion sort extension (v96)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-097 — Gnome sort comparison (v97)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-098 — Cocktail sort variation (v98)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-099 — Comb sort variation (v99)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-100 — Tim sort introduction (v100)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-101 — Trace selection sort on a given array (v101)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-102 — Trace insertion sort on a given array (v102)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-103 — Compare swap counts between sorts (v103)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-104 — Identify when insertion sort beats selection sort (v104)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-105 — Sort an array of strings using insertion sort (v105)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-106 — Implement selection sort for linked list (v106)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-107 — Count inversions using insertion sort (v107)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-108 — Sort nearly sorted array (k-sorted) (v108)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-109 — Implement binary insertion sort (v109)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-110 — Stability analysis with equal elements (v110)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-111 — Selection sort on 2D array by column (v111)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-112 — Insertion sort with custom comparator (v112)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-113 — Analyze best/worst cases with specific inputs (v113)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-114 — Sort by multiple keys (v114)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-115 — Implement in-place stable selection sort (v115)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-116 — Shell sort as insertion sort extension (v116)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-117 — Gnome sort comparison (v117)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-118 — Cocktail sort variation (v118)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-119 — Comb sort variation (v119)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-120 — Tim sort introduction (v120)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-121 — Trace selection sort on a given array (v121)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-122 — Trace insertion sort on a given array (v122)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-123 — Compare swap counts between sorts (v123)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-124 — Identify when insertion sort beats selection sort (v124)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-125 — Sort an array of strings using insertion sort (v125)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-126 — Implement selection sort for linked list (v126)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-127 — Count inversions using insertion sort (v127)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-128 — Sort nearly sorted array (k-sorted) (v128)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-129 — Implement binary insertion sort (v129)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-130 — Stability analysis with equal elements (v130)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-131 — Selection sort on 2D array by column (v131)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-132 — Insertion sort with custom comparator (v132)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-133 — Analyze best/worst cases with specific inputs (v133)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-134 — Sort by multiple keys (v134)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-135 — Implement in-place stable selection sort (v135)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-136 — Shell sort as insertion sort extension (v136)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-137 — Gnome sort comparison (v137)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-138 — Cocktail sort variation (v138)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-139 — Comb sort variation (v139)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-140 — Tim sort introduction (v140)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-141 — Trace selection sort on a given array (v141)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-142 — Trace insertion sort on a given array (v142)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-143 — Compare swap counts between sorts (v143)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-144 — Identify when insertion sort beats selection sort (v144)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-145 — Sort an array of strings using insertion sort (v145)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-146 — Implement selection sort for linked list (v146)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-147 — Count inversions using insertion sort (v147)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-148 — Sort nearly sorted array (k-sorted) (v148)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-149 — Implement binary insertion sort (v149)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-150 — Stability analysis with equal elements (v150)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-151 — Selection sort on 2D array by column (v151)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-152 — Insertion sort with custom comparator (v152)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-153 — Analyze best/worst cases with specific inputs (v153)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-154 — Sort by multiple keys (v154)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-155 — Implement in-place stable selection sort (v155)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-156 — Shell sort as insertion sort extension (v156)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-157 — Gnome sort comparison (v157)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-158 — Cocktail sort variation (v158)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-159 — Comb sort variation (v159)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-160 — Tim sort introduction (v160)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-161 — Trace selection sort on a given array (v161)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-162 — Trace insertion sort on a given array (v162)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-163 — Compare swap counts between sorts (v163)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-164 — Identify when insertion sort beats selection sort (v164)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-165 — Sort an array of strings using insertion sort (v165)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-166 — Implement selection sort for linked list (v166)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-167 — Count inversions using insertion sort (v167)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-168 — Sort nearly sorted array (k-sorted) (v168)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-169 — Implement binary insertion sort (v169)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.9a-170 — Stability analysis with equal elements (v170)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.