Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Recursion 12-28-2011Opening DiscussionMinute essays responses:When to use recursion over a loop.Difference between recursion and loops.Do I ever use KDE?http://www.youtube.com/watch?v=3ARKn9C7-NYRecursionYou should have learned about recursive functions in PAD1. A recursive function is simply a function that calls itself.You can use recursion to imitate loops, but we won't do that very often in C/Java/Scala. Where recursion comes in really handy is when a function needs to test more than one alternative at a time.This works nicely because the call stack remembers where you are in a given function so when you return back, you can take off from that point again.Maze SolvingOne of my favorite recursive algorithms is maze solving. This is a special case of graph traversals which are common problems in CS.We'll use a 2D array of Ints as our maze and we can even put this into our drawing program.I want to write code to find the shortest path through a maze or count all paths through a maze.We can try to make this nice and graphical as well so it fits properly into our drawing program.Formula ParsingAnother one of my favorite recursive algorithms is formula parsing. This allows us to have the user type in a function and our code can evaluate it.We do this through “divide and conquer”. We split the formula in two across the lowest precedence operator then recursively evaluate the two halves.We can use this to put function plotting into our program if we give it the ability to handle a variable.Minute EssayQuestions?IcP #5 on
View Full Document