Added the pseudo code from the wiki page