// Basic procedure insertSort(arr: byRef) do for i = 1 to arr.len - 1 do key = arr[i] j = i - 1 while (j >= 0 AND arr[j] > key) do arr[j+1] = arr[j] j++ end arr[j+1] = key end end // Number of comparisons 1/2 N * (N - 1) procedure insertSort(arr: byRef) do comparisons = 0 for i = 1 to arr.len - 1 do key = arr[i] j = i - 1 while (j >= 0 AND arr[j] > key) do arr[j+1] = arr[j] j++ comparisons++ end arr[j+1] = key end end