tags:
- algorithms
- notes
- article
- computer-science
source: https://www.geeksforgeeks.org/loop-invariant-condition-examples-sorting-algorithms/#
created: 2024-09-16
published: 2024-03-29
What is a loop invariant?
A loop invariant is a condition among program variables that is necessarily true immediately before and after each iteration of a loop.
What are the three moments when a loop invariant be true?
The three moments when a loop invariant must be true are:
Can a loop invariant be false during the body of a loop?
Yes, a loop invariant can be false during the body of a loop.
What should you write if the loop invariant is not obvious?
If the loop invariant is not obvious, you should write a comment.
What are the three things you need to show with a loop invariant?
The three things you need to show with a loop invariant are:
...