Professional Documents
Culture Documents
Submitted By:
Hassan Abdullah 19011598-110
Syed Idrees Hashmi 19011598-133
Course:
Formal Methods in Software Engineering
SE-426
Department:
BS Software Engineering (SE-6C)
Submitted To:
Mr, Asim
Date:
June 25, 2022
University of Gujrat
Hafiz Hayat Campus
LINEAR-SEARCH (A, ν)
for i = 1 to A.length
if A[i] = = ν
return i
return NIL
Loop invariant: at the start of the ith iteration of the for loop (lines 1–4),
∀ k ∈ [1, i) A [k] ≠ ν.
Initialization:
i == 1 ⟹ [1, i) == Ø ⟹ ∀ k ∈ Ø A[k] ≠ ν,
which is true, as any statement regarding the empty set is true (vacuous truth).
Maintenance: let's suppose the loop invariant is true at the start of the ith iteration of
the for loop. If A[i] = = ν, the current iteration is the final one (see the termination section),
as line 3 is executed; otherwise, if A[i] ≠ ν, we have