edited by
858 views
0 votes
0 votes
What is loop invariant in general term ?

 

 

PS: Insertion Sort has loop invariant . We have three things in loop invariant :

a. Initialization

b.Maintenance

c.Termination
edited by

1 Answer

Best answer
2 votes
2 votes

Loop invariant is a condition which is true for every iteration of loop.

loop invariant must be true

  1. before the loop starts
  2. before each iteration of the loop
  3. after the loop terminates
selected by

Related questions

0 votes
0 votes
1 answer
1
Ray Tomlinson asked Aug 9, 2023
461 views
How many times is the comparison $i >= n$ performed in the following program?int i = 200 n = 80; main() { while (i >= n) { i = i - 2 n = n + 1 } }
12 votes
12 votes
2 answers
2
36 votes
36 votes
6 answers
3