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 Algorithms algorithms loop-invariants + – dragonball asked Jun 19, 2017 • edited Jun 19, 2017 by dragonball dragonball 858 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Surajit commented Jun 19, 2017 reply Follow Share A loop invariant is basically a condition which remains true in all the three scenarios you mentioned.It will be true during initialization,while loop in iterating and end of loop. 0 votes 0 votes just_bhavana commented Jun 19, 2017 reply Follow Share Refer this https://stackoverflow.com/questions/3221577/what-is-a-loop-invariant 0 votes 0 votes Please log in or register to add a comment.
Best answer 2 votes 2 votes Loop invariant is a condition which is true for every iteration of loop. loop invariant must be true before the loop starts before each iteration of the loop after the loop terminates Angkit answered Jun 19, 2017 • selected Oct 11, 2017 by dragonball Angkit comment Share Follow See all 3 Comments See all 3 3 Comments reply dragonball commented Jun 19, 2017 reply Follow Share Could u give one such example in general which will be easy to understand ? 0 votes 0 votes Angkit commented Jun 19, 2017 reply Follow Share int j = 9; for(int i=0; i<10; i++) j--; In this example it is true (for every iteration) that i + j == 9 3 votes 3 votes smsubham commented May 30, 2018 reply Follow Share A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop. (Note that this says nothing about its truth or falsity part way through an iteration. ) Source: http://www.cs.uofs.edu/~mccloske/courses/cmps144/invariants_lec.html 0 votes 0 votes Please log in or register to add a comment.