|
Yes, the invariant must still hold after the last iteration. Otherwise, it doesn't do you any good.
Instead of starting with the relation of left, middle, and right, start with the relation of the thing you're looking for to left and right. This doesn't look like normal binary search---maybe it's one of the weird variants that I made up for some previous exams. Anyway, middle usually doesn't need to be mentioned in the invariant at all.
Mike O'D.
|