![]() We’ll also ask ourselves three questions when trying to come up with recursive solutions: What is the base case? What argument is passed to the recursive function call? And how do the arguments passed to the recursive function calls become closer to the base case? As you gain more experience, answering these questions should come more naturally. In the process, you’ll learn about the head-tail technique for splitting up the data in the recursive function arguments. Then we explore an algorithm for solving the Tower of Hanoi puzzle, implement the flood fill drawing algorithm, and tackle the absurdly recursive Ackermann function. We begin with three simple algorithms: summing the numbers in an array, reversing a text string, and detecting whether a string is a palindrome. This chapter covers six classic problems in recursion, along with their solutions. Coding interviews (which, for lack of suitable ways to evaluate candidates, often crib notes from freshman computer science curricula) can touch upon them too. If you take a computer science course, the unit on recursion is sure to cover some of the classic algorithms presented in this chapter. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |