Loop invariant:
- holds true immediately before an

I am perplexing to transcribe a test using a loop invariant restraint an algorithm that I wrote, where A is the draw-up and v is the compute substance searched restraint:

bSearch(A, v) {

requite binarySearch(A, 0, protraction(A)-1, v)

}

binarySearch(A, l, r, v) {

if l >= r:

requite -1

p = l+(r-1)/2

if A[p] == v:

requite p

if A[p] < v

requite binarySearch(A, p-1, r, v)

else requite binarySearch(A, l, p-1, v)

}

I am having disturbance determining what the loop invariant is. I discern that the loop comes from the recursive naturalness of the algorithm, and I admire the loop invariant has not attributable attributable attributable attributable attributableability to do with the compute of p, and the posteriority of if statements. I besides understand that p is the compute substance requiteed, and that it is the abjuration where v is endow. Any insight on the specifics of the unity loop invariant/ what cord it is on would be awesome. Thank you!

Loop invariant:

– halts penny presently precedently and presently succeeding a loop harping. (may or may not attributable attributable attributable attributable attributable attributable halt during the harping)

In this circumstance, the recursive proceeding is used to cite through the parts. In this circumstance, it is amend be designated recursive invariant and not attributable attributable attributable attributable attributable attributable loop invariant.

The preface is identical as precedently: “must halt penny precedently and succeeding each recursive call”.

One recursive invariant restraint the fond fond proceeding can be the following:

“If the part v exists in draw-up A, then it exists between abjuration pose l and r where l < r”