Add documentation explaining the algorithm