arXiv.itsnick.co

an independent field guide to 23 million papers from arXiv & OpenAlex — not affiliated with arXiv.org

Computer Science · Artificial Intelligence

Presumably just as good as the older book.

Eric S, Thinking Recursively, John Wiley, An Excellent, Intuitive Book

See on the map

Abstract

Warning: beware of forward references This set of slides discusses recursion, a way of programming (and thinking) that can be used in many areas of computing. In older versions of CSC 148H/A48H, these slides were used late in the course, when suitable examples could be drawn from many areas. Currently, we’re using it near the beginning, and some of those examples aren’t appropriate yet. They will be. For now, ignore references to “tree”, “BSTnodes”, and “iterators”. We’ll get to them. 2 The Idea Recursion isn’t hard. You’ve been doing it your whole life. For example, how do you look up a word in a dictionary? / / Look up w in d. look up word(Dictionary d, Word w) { find w in d read the definition of w for each word v in the definition if you don’t understand v, then look up word(d, v) put your understanding of the words together to understand the definition 3 Thinking Recursively Imagine you have to solve one of the problems below, but you are very lazy. You can ask one or more equally lazy friends for help (so you can’t ask someone to solve the whole problem — you have to do some work!) Problem: Calculate the value of 13! Problem: You have a two-pan balance and a pile of 32 quarters. One is counterfeit and weighs slightly less than the others. Find it. How many weighings will it take? Problem: Given a set of characters, determine all possible permutations of that set. 4 To calculate the value of 13! • You can ask a friend what the value of 12! is, (and then later multiply that by 13). • Your friend can ask another friend what 11! is (and then multiply that by 12). • Eventually, someone has to figure out the factorial of 1. This is so simple that they can just answer “it’s 1”. • This answer is passed on to the person who needs to figure out 2!. They calculate 2 ∗ 1 = 2 and pass that answer on to the person who needs to figure out 3!. • They calculate 3 ∗ 2 = 6, and pass it on to the person who needs to figure out 4!. • Eventually the first person has the value of 13!.

More like this