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 Algorithms algorithms loop-invariants + – dragonball 1.6k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply Surajit commented Jun 19, 2017 reply Follow flag 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 0 replyShare just_bhavana commented Jun 19, 2017 reply Follow flag Refer this https://stackoverflow.com/questions/3221577/what-is-a-loop-invariant 0 0 replyShare Please log in or register to add a comment.
Best answer 2 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 3 3 Comments reply dragonball commented Jun 19, 2017 reply Follow flag Could u give one such example in general which will be easy to understand ? 0 0 replyShare Angkit commented Jun 19, 2017 reply Follow flag 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 3 replyShare smsubham commented May 30, 2018 reply Follow flag 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 0 replyShare Please log in or register to add a comment.