• edited by
1,563 views
0 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

1 Answer

Best answer
2 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
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
1.1k
1.1k views
aashish1406 asked Aug 9, 2023
1,062 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 } }
2 2 votes
1 1 answer
826
826 views
shivamSK asked Jun 15, 2024
826 views
#include <stdio.h int main () { int i, k; int a [8] = {33,34,35,36,37,40,50,38}; for(i = 0; i < 3; i++) { a[i] = a[i] + 1; i=i+1; } i=i-1; for (k = 7; k 4; k ) { int i =...
13 13 votes
2 answers 2 answers
6.4k
6.4k views
Arjun asked Dec 18, 2018
6,400 views
Consider the following program fragment:var x, y: integer; x := 1; y := 0; while y < x do begin x := 2*x; y := y+1 end;For the above fragment , which of the following is ...