This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

39 3939 39312010-02-19 21:06:10 / rev 5c65c3b1023a+2.2 RecursionAbstraction involves making reusable modules, ones that can be used forsolving other problems. The special case of abstraction where the otherproblem is a version of the original problem is known as recursion. Theterm is most common in computing, but recursion is broader than just acomputational method – as our first example illustrates.2.2.1 Coin-flip gameThe first example is the following game.Two people take turns flipping a (fair) coin. Whoever first turns over headswins. What is the probability that the first player wins?As a first approach to finding the probability, get a feel for the game byplaying it. Here is one iteration of the game resulting from using a realcoin:THThe first player missed the chance to win by tossing tails; but the secondplayer won by tossing heads. Playing many such games may suggest apattern to what happens or suggest how to compute the probability.However, playing many games by flipping a real coin becomes tedious. Acomputer can instead simulate the games using pseudorandom numbersas a substitute for a real coin. Here are several runs produced by acomputer program – namely, by a Python script coin-game.py. Eachline begins with 1 or 2 to indicate which player won the game; then theline gives the coin tosses that resulted in the win.2 TH2 TH1 H2 TH1 TTH2 TTTH2 TH1 H1 H1 H39 3939 39312010-02-19 21:06:10 / rev 5c65c3b1023a+2.2 RecursionAbstraction involves making reusable modules, ones that can be used forsolving other problems. The special case of abstraction where the otherproblem is a version of the original problem is known as recursion. Theterm is most common in computing, but recursion is broader than just acomputational method – as our first example illustrates.2.2.1 Coin-flip gameThe first example is the following game.Two people take turns flipping a (fair) coin. Whoever first turns over headswins. What is the probability that the first player wins?As a first approach to finding the probability, get a feel for the game byplaying it. Here is one iteration of the game resulting from using a realcoin:THThe first player missed the chance to win by tossing tails; but the secondplayer won by tossing heads. Playing many such games may suggest apattern to what happens or suggest how to compute the probability.However, playing many games by flipping a real coin becomes tedious. Acomputer can instead simulate the games using pseudorandom numbersas a substitute for a real coin. Here are several runs produced by acomputer program – namely, by a Python script coin-game.py. Eachline begins with 1 or 2 to indicate which player won the game; then theline gives the coin tosses that resulted in the win.2 TH2 TH1 H2 TH1 TTH2 TTTH2 TH1 H1 H1 HGlobal comments 1Global commentsFrom the game’s description it doesn’t seem like half the time is a plausible answer. Player1 definitely has a higer chance of winning...where did this 1.58 come from?I was a little confused at this being the school method. Took me a while to realize Ido actually calculation complex multiplication like this but vertically. Maybe it wouldbe easier to show it the vertical way. Also every multiplication we do as humans is therecursion or multiplication since build on what we know via our memorization of basicmultiplication (ie. 3*5=15 so 50*3=150).I really don’t understand how this was derived. Before I checked it, it seemed like youjust split up the numbers and adding/multiplied them around several times. Does thiswork for any complex multiplication or is the a special case? Please review in class.I guess this is similar to when you multiple vertically because we do cross multiply digitsand them sum the results up. It may just seem cooler when its explicitly written out andshown horizontally.I don’t understand the subtraction portion.I think the examples in the chapter did a good job in explaining what recursion is becauseinitially the definition just sounded like abstraction and divide and conquer.39 3939 39312010-02-19 21:06:10 / rev 5c65c3b1023a+2.2 RecursionAbstraction involves making reusable modules, ones that can be used forsolving other problems. The special case of abstraction where the otherproblem is a version of the original problem is known as recursion. Theterm is most common in computing, but recursion is broader than just acomputational method – as our first example illustrates.2.2.1 Coin-flip gameThe first example is the following game.Two people take turns flipping a (fair) coin. Whoever first turns over headswins. What is the probability that the first player wins?As a first approach to finding the probability, get a feel for the game byplaying it. Here is one iteration of the game resulting from using a realcoin:THThe first player missed the chance to win by tossing tails; but the secondplayer won by tossing heads. Playing many such games may suggest apattern to what happens or suggest how to compute the probability.However, playing many games by flipping a real coin becomes tedious. Acomputer can instead simulate the games using pseudorandom numbersas a substitute for a real coin. Here are several runs produced by acomputer program – namely, by a Python script coin-game.py. Eachline begins with 1 or 2 to indicate which player won the game; then theline gives the coin tosses that resulted in the win.2 TH2 TH1 H2 TH1 TTH2 TTTH2 TH1 H1 H1 H39 3939 39312010-02-19 21:06:10 / rev 5c65c3b1023a+2.2 RecursionAbstraction involves making reusable modules, ones that can be used forsolving other problems. The special case of abstraction where the otherproblem is a version of the original problem is known as recursion. Theterm is most common in computing, but recursion is broader than just acomputational method – as our first example illustrates.2.2.1 Coin-flip gameThe first example is the following game.Two people take turns flipping a (fair) coin. Whoever first turns over headswins. What is the probability that the first player wins?As a first approach to finding the probability, get a feel for the game byplaying it. Here is one iteration of the game resulting from using a realcoin:THThe first player missed the chance to win by tossing tails; but the secondplayer won by tossing heads. Playing many such games may suggest apattern to what happens or suggest how to compute the probability.However, playing many games by flipping a real coin becomes tedious. Acomputer can instead simulate the games using


View Full Document

MIT 6 055J - Recursion

Download Recursion
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recursion and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recursion 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?