Coming up with loop invariants involving k? void min(arr[], n){
for(i = 0;i &lt; n; ++i)
{
   // Change &lt; to &gt; if you want to find the smallest element
   if(arr[i] &gt; arr[i+1])
       arr[i] = arr[i+1];
}

To avoid wording about a &quot;just check my work&quot; question. I will try to explain what I do not understand about this topic of loop invaraints. I have been having the hardest time coming up with the beginning loop variant with respect to the variables and the what they mean in relation to the arrays. So, my question about this code loop invariant is that this program finds the smallest element in the array. My loop invaraiant is At the start of the iteration when i = k, the item at index k is the smallest item in the range from zero to k. Can you tell me both if I have the correct loop invariant and also am I understanding the concept correctly. I believe that I need to relate such variables such as i, and j in loops with the varaible k in relation to what the program is doing. Thank you.
There is a very simple way to determine whether you have the correct loop invariant:

Can you prove that it holds when entering the loop?
Can you prove that the loop maintains it?
Can you deduce correctness of the algorithm using the invariant?

I trust that you can do all these checks yourself.