Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Loop Invariant in Analysis of Algorithm

  1. Nov 2, 2012 #1


    User Avatar

    I can't generally map Loop Invariant method for proving the correctness of an Algorithm. Take the case of an Insertion Sort


    in the above link, at the page 2-3, they have proved the correctness of insertion sort using loop invariant. As of I understood, a loop invariant is a condition that will exist in an Algorithm(not necessarily), which always holds true, irrespective of the state of the Algorithm. And how is this used in proving the correctness? Besides in the same book it has been mentioned:

    "Note the similarity to mathematical induction where to prove the property holds, you prove a base case and inductive step. Here, showing that the invariant holds before the first iteration corresponds to the base case and showing that the invariant holds from iteration to iteration corresponds to the inductive step."

    Here, I can understand the lines above, but still not convinced with the explanation. Can anyone help me out...??
  2. jcsd
  3. Nov 3, 2012 #2


    Staff: Mentor

    See the wiki article - http://en.wikipedia.org/wiki/Loop_invariant
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook