Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
405 views
in Iteration and Recursion by (49.1k points)
closed by

Explain Loop invariant with a near diagram.

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

In a loop, if L is an invariant of the loop body B, then L is known as a loop invariant, while C

– – L

B

– – L

The loop invariant is true before the loop body and after the loop body, each time. Since L is true at the start of the first iteration, L is true at the start of the loop also (just before the loop). Since L is true at the end of the last iteration, L is true when the loop ends also (just after the loop). Thus, if L is a loop variant, then it is true at four important points in the algorithm, as annotated in the algorithm.

1. At the start of the loop (just before the loop)

2. at the start of each iteration (before loop body)

3. at the end of each iteration (after loop body)

4. at the end of the loop (just after the loop)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...