Saturday 8 August 2015

Compute Binomial Coefficient


Crux  of the solution is recalling an important mathematical identity:
nCr = (n-1)Cr + (n-1)C(r-1)

//algo
To find nCk; define array a of size n+1;

a[0]=1;
for (int i = 1; i <= n ; i++) {
 for (int j = min(i,k); j>= 1; j--) {
    a[j] = a[j] + a[j-1];
  }
 }


return a[k];




Levenshtein's Distance

For starters, Levenshtein's distance is the number of edits you need to make to a string A to transform it to string B. The edits could be: removal of a character to A to change it to B, addition of a character to A to change it to B or  simply substituting character in A to the one in B.

Application: Spell Checker

Not many sources explain this algorithm well but I happened to find one that explains it really superbly.

Check this out:
http://oldfashionedsoftware.com/tag/levenshtein-distance/