Skip to content

Instantly share code, notes, and snippets.

@lizlongnc
Created October 9, 2014 04:10
Show Gist options
  • Save lizlongnc/fb94219bfb8bffbf7810 to your computer and use it in GitHub Desktop.
Save lizlongnc/fb94219bfb8bffbf7810 to your computer and use it in GitHub Desktop.
JS Recursion
Recursion - when a function calls itself.
Discovered with LISP around 1958.
A great example of recursion is the quicksort
algorithm:
1. use quicksort to divide the array into two groups, low and high
if alpha, put all items that begin with a-m into 1st group and the remaining in 2nd group
if numbers, determine the mid-point and put lower nums in 1st group and the remaining in 2nd group unless this type of dividing would result in one group being much larger than the other, if so, adj mid-point
2. call quicksort again on each group containing more than one element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment