The Question: Consider the problem of sorting n items, where the comparison oracle, in the execution of an algorithm, is allowed to lie at most once. Complexity is measured in terms of the number of comparisons (oracle consultations) used. Show how to sort n items in this model using only nlgn +O(n) comparisons, giving your algorithm and proof of correctness.
What I've got:
My best solution so far is pretty rudimentary. I'm basically implementing a form of merge sort, where the only difference is, when comparing to merge, I compare twice (since the oracle can only lie once if there is an inconsistency I will compare a third time but this can only happen once).
I know that there are lg(n) levels of merges, and that since I have n elements, the maximum amount of comparisons I will make is 2nlg(n)+1. However this is a rather crude upper bound as I know that a merge of two arrays of length m and p takes m+p-1 comparisons (and not m+p).
For simplicity, if I assume array lengths are powers of 2, I have that m=p, and I get a total of n-1 merges. So I can subtract 2(n-1) from 2nlg(n)+1 which gives me 2nlg(n) - 2n - 1 comparisons.
Not quite the answer I am looking for. I think I am going about it the wrong way (I don't think it is necessary for me to compare twice every time I merge..) and I would be very grateful if anyone could push me in the right direction!
Cheers,
Sacha