12 13 10 9 8 4 11 5 7 6 2 1 3 l m r index at 11 M = 7 < index, A[M] =11 > k=2, need one < 2 L = 8, R = 13 M = 10 12 13 10 9 8 4 11 5 7 6 2 1 3 l M r M = 8 < index, A[M] = 6 > k = 2, need one < 2 L = 11, R = 13, M = 12, M > index, a[M] < k -> need one > 2 L = 11, R = 11 -> good overall, needed 2 lt 2, 1 gt 2 12 13 10 9 8 4 1 5 7 6 2 1 3 there aren't 2 lt 2 -> no 1 2 3 4 5 6 7 8 9 10 11 12 13 12 13 10 9 8 4 11 5 7 6 2 1 3 1 13 2 M = 7, 1 lt (11 > 2, Left) M = 10, 2 lt (6 > 2, Right) L = 11, R = 13, M = 12, 1 gt done 7 4 3 1 5 2 7 6 4 3 4 2 2 3 5 1 5 6 1 7 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 14 1 3 15 4 5 6 16 7 8 9 10 11 12 13 2 1 16 14 L = 1, R = 16, M = 8 -> 16, go left (no cost) L = 1, R = 7, M = 4 -> 15, left (no cost) L = 1, R = 3, M = 2 -> go left (1 gt)