Files

15 lines
597 B
Plaintext

Hoare mistakes that look reasonable
===================================
1. last element as pivot with Hoare's (lo,p) / (p+1,hi) recursion, input [1, 2]:
StackOverflowError (the partition returns p = 1 = hi, so (lo, p) is the same range again)
2. Hoare partition, but recursing on (lo, p-1) and (p+1, hi) as Lomuto does, input [2, 3, 1]:
result [2, 1, 3] (expected [1, 2, 3])
all 6 permutations of 1..3: 1 come back unsorted
all 24 permutations of 1..4: 8 come back unsorted
all 120 permutations of 1..5: 52 come back unsorted
the real Hoare.sort on the same input: [1, 2, 3]