Loop Invariants — arrayMax

Array A:
Presets:
Speed
arrayMax

                
We have to prove
  1. 𝐼 holds at (A)
  2. 𝐼 ∧ cond at (B) ⇒ 𝐼 at (C)
  3. 𝐼 ∧ ¬cond ⇒ post condition
Loop invariant
𝐼 ≡ curMax = maxk∈[0..j−1] A[k]  ∧  j ≤ n
comparisons A[j] > curMax: 0 of 0 updates of curMax: 0 total work: Θ(n)
← / → step · Home / End jump to start / end · Space plays