As seen on Introduction to Algorithms (http://mitpress.mit.edu/algorithms), the exercise states the following:
Input: Array A[1..n]
and a v
The LS algorithm that I wrote is-
LINEARSEARCH(A, v)
for i=0 to A.length-1
if(A[i] == v)
return i
return NIL
I made my own assumptions for loop invariant for checking correctness of Linear Search:
At Initialisation- at i = 0, we are searching for v at i = 0.
At successive iterations- we are looking for v till i < A.length-1
At termination- i = A.length and till A.length we kept looking for v.