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

    sdj

    User Avatar

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

    http://csnx.groups.allonline.in/pool/Introduction%20to%20Algorithms-Cormen%20Solution.pdf

    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

    Mark44

    Staff: Mentor

    See the wiki article - http://en.wikipedia.org/wiki/Loop_invariant
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Loop Invariant in Analysis of Algorithm
  1. VEGAS algorithm (Replies: 2)

  2. Ask an algorithm (Replies: 3)

  3. Knuth Algorithm (Replies: 3)

Loading...