Gambler s Ruin Lesson Plan

Size: px
Start display at page:

Download "Gambler s Ruin Lesson Plan"

Transcription

1 Gambler s Ruin Lesson Plan Ron Bannon August 11, 05 1

2 Gambler s Ruin Lesson Plan 1 Printed August 11, 05 Prof. Kim s assigned lesson plan based on the Gambler s Ruin Problem. Preamble: This lesson plan is being developed for pre-college computer science students who are familiar with a procedural language. The material here will be presented using standard command line C++ on a Mac OS X platform, 2 but can easily be modified to run under other operating systems. I believe this material can be covered in five typical (50 minute session) class meetings, and will require at least one hour of homework per class session. Teacher s can visit gamblers-ruin.blogspot.com to get help, or to download this lesson plan and example ASCII code. I can also be contacted via at ron.bannon@gmail.com, and I welcome productive exchange of ideas, especially from students who actually worked through the material. Disclaimer: This lesson plan analyzes a gambling problem and playing an actual incidence of this game may be a violation of law. Please do not encourage your students to gamble, and emphasize that it is illegal to do so. Before using this lesson plan you may want to clear its content with your supervisor. 1 Session I: Playing a game-of-chance. The main goal is to simulate an actual game-of-chance to see what the outcome is. At first the simulation will involve your students, but then we ll speed-up the process by using a computer s random number generator. This example should help motivate students (and teachers) to use similar methods to explore, develop and implement probability models using a procedural language that has a robust random number generator. The problem is usually expressed in a very abstract manner as follows: The Gambler s Ruin 3 Two gamblers, A and B, bet on the outcomes of successive flips of a coin. On each flip, if the coin comes up heads, A collects 1 unit from B, whereas if it comes up tails, A pays 1 unit to B. They continue to do this until one of them runs out of money. If it is assumed that the successive flips of the coin are independent and each flip results in a head with probability p, what is the probability that A ends up with all the money if he starts with i units and B starts with N i units? However, I think it is best to avoid this description and instead take a specific case and divide the class into pairs in order to simulate an actually event. Give each pair of students twenty pennies and one dime. Then tell each pair to start playing the game as follows. 1 This document was prepared by Ron Bannon using L A TEX 2ε. Source and pdf are available by ing a request to ron.bannon@gmail.com. 2 BSD UNIX based OS. 3 From Sheldon Ross s textbook: A First Course in Probability, Seventh Edition, Prentice Hall, 02, ISBN: , pp

3 1. One member from each team will be asked to flip the dime, this person will be arbitrarily called A and the other B. 2. Give A fifteen pennies and B five pennies. Person A should have fifteen pennies and one dime, and person B should have five pennies. 3. Person A should flip the dime, if it is heads, A should take one penny from B, if it is tails, B should take a penny from A.. Repeat playing until one player has all twenty pennies, record which player wins. 5. Encourage students to repeat this game as many times as they like. This of course may be quite chaotic, and you may need to adapt this game for your particular class. It should also be emphasized while the students are playing that three possibilities exists: player A wins, player B wins or the game never stops. Actually, depending on time, many of your pairs may fail to finish a run. In any case, the game should prove fun, but still encourage your students to continue playing with others. Some students will complain that their particular dime is biased, or that their partner s know how to toss a dime to get a desired result, and you should not suggest otherwise. 2 Session II: Does random mean pure chance? It is hard to know if randomness is well understood, even by those of us who are supposed to know the difference. It is all about language and how it is used. Words get used imprecisely and their meaning is often not well understood just think of mathematicians saying: the rational numbers, although infinite, are countable, while the irrational numbers, also infinite, are uncountable, etc., ad nauseam. So often are words used to differentiate the subtlety between concepts that many of us are perplexed when common words are used in a very demanding and precise field such as mathematics. However, here you should emphasize that computers, although anything but random, have fairly good algorithms for generating random numbers. Present the following snippet of C++ code (Listing 1) as a fairly robust 5 way to generate a sample random number from the open interval (0, 1). Listing 1: Uniform Random Variable (0, 1) 1 double uniform ( void ) 2 { 3 long random_integer ; 5 do random_integer = rand (); 7 while ( ( random_integer == RAND_MAX ) ( random_integer == 0) ); 8 9 // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET // THE SET NOW HAS TWO LESS ELEMENTS return ( static_cast <double >( random_integer ) / ( RAND_MAX - 2)); 13 } // uniform Here it might be helpful to explain that rand() is a standard C++ function and the students will need to use cstdlib library in order to call rand(). The function rand() will return an integer, It must be emphasized that this is a game and no one is to walk away with the money! 5 See for more information about random numbers. 3

4 at random, from 0 to some machine specific maximum integer call RAND MAX. This double uniform(void) function s sole job is to return one random (equally likely) number from the open interval (0, 1). If all numbers are equally likely on the open interval (0, 1) it seems reasonable that half the numbers returned from double uniform(void) will be greater than 0.5 and the other half will be less than 0.5. This, of course, will allow us to simulate a simple fair coin toss, where heads will be equivalent to double uniform(void) function returning a number greater that 0.5, and tails will be equivalent to double uniform(void) function returning a number less than or equal to 0.5. As an assignment have your students write a simple C++ program that simulates a fair coin toss. Specify that they should generate a string or Hs and Ts that has length. Here is an example (Listing 2) of what a typical student should produce. Listing 2: Twenty flips of a fair coin // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET 1 // THE SET NOW HAS TWO LESS ELEMENTS 23 int i; // counter variable 2 25 for ( i = 1 ; i <= ; i++ ) 2 if ( uniform () > 0.5 ) 27 cout << "H "; 28 else 29 cout << "T "; 30 cout << "\n"; } // main function The output should be something like this: T T H T H T T H H H T H H T T H H T T T. 3 Session III: Simulating Class 1 s game on a computer. By now your students should have a full grasp of the game. Here it s imperative that the students know the game well enough to actually program one run, where we just want to know the outcome: A won, or B won. 7 As a reminder, here s how the game proceeds. 1. One member from each team will be asked to flip the dime, this person will be arbitrarily called A and the other B. Students who question the fairness because of the inclusion of 0.5 in the lower half should be encouraged to compute the length to see that they are actually the same. 7 In reality, this could be an infinite game where no one wins, but that s not going to happen on a machine because of the speed at which events happen, and the fact that this event has probability that is asymptotically zero.

5 2. Give A fifteen pennies and B five pennies. Person A should have fifteen pennies and one dime, and person B should have five pennies. 3. Person A should flip the dime, if it is heads, A should take one penny from B, if it is tails, B should take a penny from A.. Repeat playing until one player has all twenty pennies, record which player wins. 5. Encourage students to repeat this game as many times as they like. 8 As an assignment have your students write a simple C++ program that simulates one run of this game. Specify that they should output who wins the game, i.e. A or B. Here is an example (Listing 3) of what a typical student should produce. Listing 3: One run of the game // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET 1 // THE SET NOW HAS TWO LESS ELEMENTS 23 int A = 15; // number of pennies that A starts with 2 int B = 5; // number of pennies that B starts with 25 2 do 27 if ( uniform () > 0.5 ) 2 29 A ++; 30 B - -; 31 } 32 else 33 { 3 A - -; 35 B ++; 3 } 37 while ( A!= 0 && B!= 0); if ( B == 0 ) 0 cout << "A wins all!\n"; 1 else 2 cout << "B wins all!\n"; 3 } // main function Session IV: Increasing the number of games played. By now everyone should realize that A has an advantage and that B almost always loses. However, what if we were to repeat the game many times to see what A s real advantage is. As an assignment have your students modify their prior C++ program assignment (Listing 3) that simulates one run of this game, so that it runs 1,000,000 games and keeps tabs of how many wins both A and B receive. Emphasize that a physical simulation would take about 30 years of full time effort for two humans a colossal waste of time. However a fast personal computer will be able to simulate this fairly quickly. This, of course, is the bases for all probabilistic 8 It must be emphasized that this is a game and no one is to walk away with the money! 5

6 simulations... SPEED, SPEED, SPEED! However, an older machine may need several minutes to compute the results, so some students will need to be patient. Also, clearly specify that they should output the number of wins for both players. Here is an example (Listing ) of what a typical student should produce. Listing : One million runs of the game // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET 1 // THE SET NOW HAS TWO LESS ELEMENTS 23 int A = 15; // number of pennies that A starts with 2 int B = 5; // number of pennies that B starts with 25 int A_wins = 0; // number of wins for player A 2 int B_wins = 0; // number of wins for player B 27 int i; // counter for (i = 1 ; i <= ; i ++) 30 { 31 do 32 if ( uniform () > 0.5 ) 33 { 3 A ++; 35 B - -; 3 } 37 else 3 39 A - -; 0 B ++; 1 } 2 while ( A!= 0 && B!= 0); 3 if ( B == 0 ) 5 A_wins ++; else 7 B_wins ++; 8 A = 15; // number of pennies that A starts with 9 B = 5; // number of pennies that B starts with 50 } cout << "A wins " << A_wins << ".\n"; 53 cout << "B wins " << B_wins << ".\n"; 5 55 } // main function Outputs will vary slightly, my run produced: A wins 750,2; and B wins 29, Session V: Changing the parameters. This section will be divided into three parts, and your students should have a much better understanding of the overall problem and should be able to implement subtle changes in the code (Listing ) quickly. This is especially true if they re working independently and were capable of coding (Listing ) the last exercise. 5.1 Changing the beginning cash distribution. Again, the model (Listing ) will be easy to change, but first it might be nice to conjecture what might happen if we were to start out with different amounts. Looking at the last case we saw in

7 our simulation that the ratio of number of wins for player A to player B was roughly 3 to 1, and this was to be expected, mainly because it s the same ratio as the beginning cash distributions. So with this in mind ask the students to modify the starting cash amounts and re-run 9 their programs that simulate a million runs. Suppose for example that player A starts with 75 pennies and player B starts with 0 pennies. Before the students run the program they should be able to conjecture how many wins for each player first. The simulation should either confirm or deny this. Also have the students try starting player A with 90 pennies and player B with pennies and see what happens. Here is an example of what a typical student s simulation should produce. 1. Let A start with 75 pennies and B with 0 pennies. In a million runs of this game I d expect that B would win 0 1, 000, , 29 5 games, and A would win 75 1, 000, , games. When I change the program to reflect this change in starting values I get: A wins 28,537; and B wins 571,3. That s almost exactly what we expected to see. 2. Let A start with 90 pennies and B with pennies. In a million runs of this game I d expect that A would win 90 = 900, games, and B would win 1, 000, 000 = 0, games. When I change the program to reflect this change in starting values I get: A wins 899,950; and B wins 0,050. That s almost exactly what we expected to see. 5.2 Changing the fairness of the coin. The uniform distribution (Listing 1) that we presented earlier is the single most important distribution in probabilistic modeling, mainly because it is the basis for all simulated distibutions. It can easily be adapted to model complex distributions, but here we just need to create the occurrence of a biased coin. Let s say that we want the occurrence of heads to be twice a likely as an occurrence tail. Intuitively this means that heads will occur, on average, every two out of three; and tails will occur every one out of three. As an assignment have your students write a simple C++ program that simulates a biased coin toss, where we want the occurrence of heads to be twice a likely as an occurrence tail. Modifying (Listing 2) to reflect this biased coin s behavior, and generate a 1,000,000 samples, keeping tract of the number of heads and tails. Here s a example code (Listing 5) of what a typical student s work should look like. 9 Changing parameters can have a drastic impact on simulated run times, and your students should be reminded why by appealing to their understanding of the actual physical game. 7

8 Listing 5: 1,000,000 flips of a biased coin // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET 1 // THE SET NOW HAS TWO LESS ELEMENTS 23 int i; // counter variable 2 int H = 0; // number of heads 25 int T = 0; // number if tails for ( i = 1 ; i <= ; i++ ) 29 if ( uniform () > 1.0/3.0 ) // this will occur 2/3 rd of the time 30 H ++; 31 else 32 T ++; 33 cout << " The number is heads : " << H << "\n"; 3 cout << " The number is tails : " << T << "\n"; 35 3 } // main function The output should be something like this:,3 heads, and 333,337 tails, where, as expected we have, , 337 =, Biased coin and differing cash amounts. Again the model (Listing ) will be easy to change, but first it might be nice to conjecture what might happen if we were to start out with different amounts, and played with a biased coin. Suppose player A starts with 5 pennies, player B starts with pennies, and heads is favored 3 to 2. We already know that if the coin were fair player A would win one-third of the time, but now we re playing with a biased coin that favors player A. Have the students conjecture what s going to happen before running the simulation. I believe most students would venture a guess that A is actually favored to walk away with all twenty pennies, but I seriously doubt anyone would be able to give proper odds for this game. Here it should be emphasized that simulations can in fact be a very nice way to solve very difficult probability problems. Once again the game should be simulated a million times, where player A starts with 5 pennies, player B starts with pennies, and heads is favored 3 to 2. Here s an example (Listing ) of what a student s work should look like. Listing : 1,000,000 plays using a biased coin. 1 8

9 15 // THIS WILL EXCLUDE RAND_MAX AND 0 FROM THE SET 1 // THE SET NOW HAS TWO LESS ELEMENTS 23 int A = 5; // number of pennies that A starts with 2 int B = ; // number of pennies that B starts with 25 int A_wins = 0; // number of wins for player A 2 int B_wins = 0; // number of wins for player B 27 int i; // counter for (i = 1 ; i <= ; i ++) 30 { 31 do 32 if ( uniform () > 2.0/5.0 ) // heads is favored 3 to 2 33 { 3 A ++; 35 B - -; 3 } 37 else 3 39 A - -; 0 B ++; 1 } 2 while ( A!= 0 && B!= 0); 3 if ( B == 0 ) 5 A_wins ++; else 7 B_wins ++; 8 A = 5; // number of pennies that A starts with 9 B = ; // number of pennies that B starts with 50 } cout << "A wins " << A_wins << ".\n"; 53 cout << "B wins " << B_wins << ".\n"; 5 55 } // main function The outcome from this run indicates that player A wins 870,537 games and player B wins 129,3 games. So the odds favoring player A is almost seven to one. 11 Here it should be emphasized that games of chance that involve loss and gain are always stacked against the player! Take home message, DON T GAMBLE unless you re designing the game, but that s illegal. Only the State has a right to do this, and it s often referred to as a stupid tax 12 because it preys upon people who don t understand probability. Endnote Please refer interested and capable students to birthday-surprise.blogspot.com website to learn more about probabilistic modeling. This website will start with a rather simple and robust way to generate random samples (the basis of all probabilistic simulations) and allow for students to interact in a learning community that is not limited to the confines of a classroom. Again, I can be reached via at ron.bannon@gmail.com if questions or concerns remain about the material presented. Mathematically, we expect « «15 1, 000, , games, and once again our simulation is pretty damn close! 11 An 87% chance of winning any one game! 12 It can also be referred to as a poor tax because it preys upon people who are poor. For example, I have adult students who spend more on lottery than they do on food. 9

Basic Triangle Congruence Lesson Plan

Basic Triangle Congruence Lesson Plan Basic Triangle Congruence Lesson Plan Developed by CSSMA Staff Drafted August 2015 Prescribed Learning Outcomes: Introduce students to the concept of triangle congruence and teach them about the congruency

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material MTH Calculus II Essex County College Division of Mathematics and Physics Lecture Notes # Sakai Web Project Material Introduction - - 0 - Figure : Graph of y sin ( x y ) = x cos (x + y) with red tangent

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii

More information

1 Tangents and Secants

1 Tangents and Secants MTH 11 Web Based Material Essex County College Division of Mathematics and Physics Worksheet #, Last Update July 15, 010 1 1 Tangents and Secants The idea of a it is central to calculus and an intuitive

More information

Three Types of Probability

Three Types of Probability CHAPTER Three Types of Probability This article is not so much about particular problems or problem solving tactics as it is about labels. If you think about it, labels are a big key to the way we organize

More information

More about Loops and Decisions

More about Loops and Decisions More about Loops and Decisions 5 In this chapter, we continue to explore the topic of repetition structures. We will discuss how loops are used in conjunction with the other control structures sequence

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Error Detection and Parity Lesson Plan

Error Detection and Parity Lesson Plan Error Detection and Parity Lesson Plan Overview Error Detection and Parity Summary When data is stored on a disk or transmitted from one computer to another, we usually assume that it doesn t get changed

More information

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability)

MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability) MATHEMATICS 191, FALL 2004 MATHEMATICAL PROBABILITY Outline #1 (Countability and Uncountability) Last modified: September 16, 2004 Reference: Apostol, Calculus, Vol. 2, section 13.19 (attached). The aim

More information

Building Concepts: Visualizing Equations Using Mobiles

Building Concepts: Visualizing Equations Using Mobiles Lesson Overview In this TI-Nspire lesson, students explore interactive mobiles for modeling one or more equations. Students are given specific constraints and use solution preserving moves to reinforce

More information

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is

More information

Game Guide. Keno Game Guide

Game Guide. Keno Game Guide Game Guide Keno Game Guide Contents Introduction and ways to play Keno - Keno Classic Keno Mega-Millions Keno Kwikpik Keno Heads or Tails Keno Advanced Keno Superplay Watching the game 0 Keno Replay 0

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we

More information

Modeling RNA/DNA with Matlab - Chemistry Summer 2007

Modeling RNA/DNA with Matlab - Chemistry Summer 2007 Modeling RNA/DNA with Matlab - Chemistry 694 - Summer 2007 If you haven t already, download MatlabPrograms.zip from the course Blackboard site and extract all the files into a folder on your disk. Be careful

More information

FOR Loops. Last Modified: 01 June / 1

FOR Loops. Last Modified: 01 June / 1 FOR Loops http://people.sc.fsu.edu/ jburkardt/isc/week04 lecture 08.pdf... ISC3313: Introduction to Scientific Computing with C++ Summer Semester 2011... John Burkardt Department of Scientific Computing

More information

Let s get started. Game guide

Let s get started. Game guide Let s get started Game guide What is Keno? Keno is a fun, easy game that is played every minutes. 0 numbers are drawn from the 0 available on the Keno game grid. Match the numbers you play to the numbers

More information

Chapter Four: Loops II

Chapter Four: Loops II Chapter Four: Loops II Slides by Evan Gallagher & Nikolay Kirov Chapter Goals To understand nested loops To implement programs that read and process data sets To use a computer for simulations Processing

More information

Integrated Math 1 Module 3 Honors Sequences and Series Ready, Set, Go! Homework

Integrated Math 1 Module 3 Honors Sequences and Series Ready, Set, Go! Homework 1 Integrated Math 1 Module 3 Honors Sequences and Series Ready, Set, Go! Homework Adapted from The Mathematics Vision Project: Scott Hendrickson, Joleigh Honey, Barbara Kuehl, Travis Lemon, Janet Sutorius

More information

Distributions of Continuous Data

Distributions of Continuous Data C H A P T ER Distributions of Continuous Data New cars and trucks sold in the United States average about 28 highway miles per gallon (mpg) in 2010, up from about 24 mpg in 2004. Some of the improvement

More information

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2

Discrete Mathematics and Probability Theory Fall 2013 Midterm #2 CS 70 Discrete Mathematics and Probability Theory Fall 013 Midterm # 1. (30 points) Short Answer. No justification necessary. Please write only the answer in the space provided after each question. Please

More information

8. DEALING WITH RANDOMNESS

8. DEALING WITH RANDOMNESS TABLE OF CONTENTS 8.1 GENERATING RANDOM NUMBERS... 3 ACTIVITY 1... 4 ACTIVITY 2... 4 8.2 TRANSFORMING RANDOM NUMBERS... 6 ACTIVITY 3... 6 ACTIVITY 4... 7 ACTIVITY 5... 8 8.3 DISPLAYING RANDOMNESS... 10

More information

1 Leaffix Scan, Rootfix Scan, Tree Size, and Depth

1 Leaffix Scan, Rootfix Scan, Tree Size, and Depth Lecture 17 Graph Contraction I: Tree Contraction Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Kanat Tangwongsan March 20, 2012 In this lecture, we will explore

More information

Student Outcomes. Lesson Notes. Classwork. Discussion (4 minutes)

Student Outcomes. Lesson Notes. Classwork. Discussion (4 minutes) Student Outcomes Students write mathematical statements using symbols to represent numbers. Students know that written statements can be written as more than one correct mathematical sentence. Lesson Notes

More information

CSC 1351: Quiz 6: Sort and Search

CSC 1351: Quiz 6: Sort and Search CSC 1351: Quiz 6: Sort and Search Name: 0.1 You want to implement combat within a role playing game on a computer. Specifically, the game rules for damage inflicted by a hit are: In order to figure out

More information

Heads Up! (Continued)

Heads Up! (Continued) . Name Date A c t i v i t y 6 Heads Up! (Continued) In this activity, you will do more experiments with simulations and use a calculator program that will quickly simulate multiple coin tosses. The Problem

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming (Spring 2012) Lecture #5: Conditionals and Loops Zhong Shao Department of Computer Science Yale University Office: 314 Watson http://flint.cs.yale.edu/cs112 Acknowledgements:

More information

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Variables You have to instruct your computer every little thing it needs to do even

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Chapter Fourteen Bonus Lessons: Algorithms and Efficiency

Chapter Fourteen Bonus Lessons: Algorithms and Efficiency : Algorithms and Efficiency The following lessons take a deeper look at Chapter 14 topics regarding algorithms, efficiency, and Big O measurements. They can be completed by AP students after Chapter 14.

More information

The Probabilistic Method

The Probabilistic Method The Probabilistic Method Po-Shen Loh June 2010 1 Warm-up 1. (Russia 1996/4 In the Duma there are 1600 delegates, who have formed 16000 committees of 80 persons each. Prove that one can find two committees

More information

CS103 Spring 2018 Mathematical Vocabulary

CS103 Spring 2018 Mathematical Vocabulary CS103 Spring 2018 Mathematical Vocabulary You keep using that word. I do not think it means what you think it means. - Inigo Montoya, from The Princess Bride Consider the humble while loop in most programming

More information

1.3 Conditionals and Loops

1.3 Conditionals and Loops 1.3 Conditionals and Loops Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 15/1/2013 22:16:24 A Foundation for Programming any program

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

Algebra of Sets. Aditya Ghosh. April 6, 2018 It is recommended that while reading it, sit with a pen and a paper.

Algebra of Sets. Aditya Ghosh. April 6, 2018 It is recommended that while reading it, sit with a pen and a paper. Algebra of Sets Aditya Ghosh April 6, 2018 It is recommended that while reading it, sit with a pen and a paper. 1 The Basics This article is only about the algebra of sets, and does not deal with the foundations

More information

Introduction to Counting, Some Basic Principles

Introduction to Counting, Some Basic Principles Introduction to Counting, Some Basic Principles These are the class notes for week. Before we begin, let me just say something about the structure of the class notes. I wrote up all of these class notes

More information

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change Chapter01.fm Page 1 Monday, August 23, 2004 1:52 PM Part I The Mechanics of Change The Mechanics of Change Chapter01.fm Page 2 Monday, August 23, 2004 1:52 PM Chapter01.fm Page 3 Monday, August 23, 2004

More information

Building Concepts: Building Expressions

Building Concepts: Building Expressions Lesson Overview Algebraic Focus: What does it mean to say two expressions are equivalent? In this lesson students view expressions as objects in their own right and interpret the form and structure of

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

Algorithm Design and Recursion. Search and Sort Algorithms

Algorithm Design and Recursion. Search and Sort Algorithms Algorithm Design and Recursion Search and Sort Algorithms Objectives To understand the basic techniques for analyzing the efficiency of algorithms. To know what searching is and understand the algorithms

More information

Lecture 3: Loops. While Loops. While Loops: Powers of Two. While Loops: Newton-Raphson Method

Lecture 3: Loops. While Loops. While Loops: Powers of Two. While Loops: Newton-Raphson Method While Loops Lecture : Loops The while loop is a common repetition structure. Check loop-continuation condition. Execute a sequence of statements. Repeat. while (boolean expression) statement; while loop

More information

1.7 Limit of a Function

1.7 Limit of a Function 1.7 Limit of a Function We will discuss the following in this section: 1. Limit Notation 2. Finding a it numerically 3. Right and Left Hand Limits 4. Infinite Limits Consider the following graph Notation:

More information

Lecture 3: Loops. While Loops. While Loops: Newton-Raphson Method. While Loops: Powers of Two

Lecture 3: Loops. While Loops. While Loops: Newton-Raphson Method. While Loops: Powers of Two While Loops Lecture 3: Loops The while loop is a common repetition structure. Check loop-continuation condition. Execute a sequence of statements. Repeat. while (boolean expression) statement; while loop

More information

Greedy Algorithms CLRS Laura Toma, csci2200, Bowdoin College

Greedy Algorithms CLRS Laura Toma, csci2200, Bowdoin College Greedy Algorithms CLRS 16.1-16.2 Laura Toma, csci2200, Bowdoin College Overview. Sometimes we can solve optimization problems with a technique called greedy. A greedy algorithm picks the option that looks

More information

Statistical Computing

Statistical Computing SERIES I ARTICLE Statistical Computing 1. Understanding Randomness and Random Numbers Sudhakar Kunte Elements of statistical computing are discussed in this series. We begin with the notion of random numbers

More information

Random Simulation Simulation Modeling

Random Simulation Simulation Modeling Random Simulation 5.1 86 Simulation Modeling Goal: Use probabilistic methods to analyze deterministic and probabilistic models. Example. Determine the best elevator delivery scheme. The wait is too long,

More information

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture 32 Multiple Server Queueing Models In this lecture, we continue our discussion

More information

Chapter 3. Set Theory. 3.1 What is a Set?

Chapter 3. Set Theory. 3.1 What is a Set? Chapter 3 Set Theory 3.1 What is a Set? A set is a well-defined collection of objects called elements or members of the set. Here, well-defined means accurately and unambiguously stated or described. Any

More information

More About WHILE Loops

More About WHILE Loops More About WHILE Loops http://people.sc.fsu.edu/ jburkardt/isc/week04 lecture 07.pdf... ISC3313: Introduction to Scientific Computing with C++ Summer Semester 2011... John Burkardt Department of Scientific

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions Section 1.5 Transformation of Functions 61 Section 1.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations

More information

An Interesting Way to Combine Numbers

An Interesting Way to Combine Numbers An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly

More information

Mathematics for Computer Science Exercises from Week 4

Mathematics for Computer Science Exercises from Week 4 Mathematics for Computer Science Exercises from Week 4 Silvio Capobianco Last update: 26 September 2018 Problems from Section 4.1 Problem 4.3. Set Formulas and Propositional Formulas. (a) Verify that the

More information

DEFERRED ACCEPTANCE 2

DEFERRED ACCEPTANCE 2 DEFERRED ACCEPTANCE The point of this note is to take you through the logic behind the deferred acceptance algorithm. Please read the papers associated with the links on the web page for motivation and

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions Section.5 Transformation of Functions 6 Section.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations

More information

Lecture Notes on Contracts

Lecture Notes on Contracts Lecture Notes on Contracts 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 30, 2012 1 Introduction For an overview the course goals and the mechanics and schedule of the course,

More information

3. Simple Types, Variables, and Constants

3. Simple Types, Variables, and Constants 3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting

More information

def F a c t o r i a l ( n ) : i f n == 1 : return 1 else : return n F a c t o r i a l ( n 1) def main ( ) : print ( F a c t o r i a l ( 4 ) )

def F a c t o r i a l ( n ) : i f n == 1 : return 1 else : return n F a c t o r i a l ( n 1) def main ( ) : print ( F a c t o r i a l ( 4 ) ) 116 4.5 Recursion One of the most powerful programming techniques involves a function calling itself; this is called recursion. It is not immediately obvious that this is useful; take that on faith for

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions 6 Chapter 1 Section 1.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations in order to explain or

More information

Lesson 13: The Graph of a Linear Equation in Two Variables

Lesson 13: The Graph of a Linear Equation in Two Variables Student Outcomes Students predict the shape of a graph of a linear equation by finding and plotting solutions on a coordinate plane. Students informally explain why the graph of a linear equation is not

More information

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 CS 3512, Spring 2011 Instructor: Doug Dunham Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 Prerequisites: Calc I, CS2511 Rough course outline:

More information

Out for Shopping-Understanding Linear Data Structures English

Out for Shopping-Understanding Linear Data Structures English Out for Shopping-Understanding Linear Data Structures English [MUSIC PLAYING] [MUSIC PLAYING] TANZEELA ALI: Hi, it's Tanzeela Ali. I'm a software engineer, and also a teacher at Superior University, which

More information

A Prehistory of Arithmetic

A Prehistory of Arithmetic A Prehistory of Arithmetic History and Philosophy of Mathematics MathFest August 8, 2015 Patricia Baggett Andrzej Ehrenfeucht Dept. of Math Sci. Computer Science Dept. New Mexico State Univ. University

More information

Lecture. Simulation && Design. Richard E Sarkis CSC 161: The Art of Programming

Lecture. Simulation && Design. Richard E Sarkis CSC 161: The Art of Programming Lecture Simulation && Design Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To understand the potential applications of simulation as a way to solve real-world problems To

More information

2.3 Flow Control. Flow-Of-Control. If-Else: Leap Year. If-Else

2.3 Flow Control. Flow-Of-Control. If-Else: Leap Year. If-Else Flow-Of-Control 2.3 Flow Control Flow-of-control. Sequence of statements that are actually executed in a program. Conditionals and loops: enable us to harness power of the computer. statement 1 boolean

More information

CS2 Algorithms and Data Structures Note 1

CS2 Algorithms and Data Structures Note 1 CS2 Algorithms and Data Structures Note 1 Analysing Algorithms This thread of the course is concerned with the design and analysis of good algorithms and data structures. Intuitively speaking, an algorithm

More information

Is the result of multiplying 2 positive numbers positive or negative? Is the result of multiplying 2 negative numbers positive or negative?

Is the result of multiplying 2 positive numbers positive or negative? Is the result of multiplying 2 negative numbers positive or negative? Write down all the work necessary for the problem, this is a part of your class notes that you can use to study from. You will not be able to use notes on quizzes or tests. DO NOT simply write it and toss

More information

Lab 4: Strings/Loops Due Apr 22 at midnight

Lab 4: Strings/Loops Due Apr 22 at midnight Lab 4: Strings/Loops Due Apr 22 at midnight For this lab, you must work with a partner. All functions should be commented appropriately. If there are random numbers, the function must still be commen ted

More information

POSTER PROBLEMS LAUNCH POSE A PROBLEM WORKSHOP POST, SHARE, COMMENT STRATEGIC TEACHER-LED DISCUSSION FOCUS PROBLEM: SAME CONCEPT IN A NEW CONTEXT

POSTER PROBLEMS LAUNCH POSE A PROBLEM WORKSHOP POST, SHARE, COMMENT STRATEGIC TEACHER-LED DISCUSSION FOCUS PROBLEM: SAME CONCEPT IN A NEW CONTEXT POSTER PROLEMS Triangles To Order Seventh Grade Poster Problem Geometry In this poster problem, students try to build triangles to particular specifications (specs). The specs can include side lengths,

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

CS 161 Computer Security

CS 161 Computer Security Popa & Wagner Spring 2016 CS 161 Computer Security Midterm 2 Print your name:, (last) (first) I am aware of the Berkeley Campus Code of Student Conduct and acknowledge that academic misconduct will be

More information

Math 7 Notes Unit 2B: Rational Numbers

Math 7 Notes Unit 2B: Rational Numbers Math 7 Notes Unit B: Rational Numbers Teachers Before we move to performing operations involving rational numbers, we must be certain our students have some basic understandings and skills. The following

More information

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site.

More information

Chapters 5-6: Statistical Inference Methods

Chapters 5-6: Statistical Inference Methods Chapters 5-6: Statistical Inference Methods Chapter 5: Estimation (of population parameters) Ex. Based on GSS data, we re 95% confident that the population mean of the variable LONELY (no. of days in past

More information

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 COMPUTER SCIENCE 61AS 1. What is functional programming? Give an example of a function below: Functional Programming In functional programming, you do not

More information

CMPSCI 187 / Spring 2015 Hanoi

CMPSCI 187 / Spring 2015 Hanoi Due on Thursday, March 12, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 Contents Overview 3 Learning Goals.................................................

More information

Learn to use the vector and translation tools in GX.

Learn to use the vector and translation tools in GX. Learning Objectives Horizontal and Combined Transformations Algebra ; Pre-Calculus Time required: 00 50 min. This lesson adds horizontal translations to our previous work with vertical translations and

More information

1.3 Conditionals and Loops

1.3 Conditionals and Loops A Foundation for Programming 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data

More information

COMP 161 Lecture Notes 16 Analyzing Search and Sort

COMP 161 Lecture Notes 16 Analyzing Search and Sort COMP 161 Lecture Notes 16 Analyzing Search and Sort In these notes we analyze search and sort. Counting Operations When we analyze the complexity of procedures we re determine the order of the number of

More information

Assignment #1 Simple C++

Assignment #1 Simple C++ Eric Roberts Handout #5 CS 106B January 7, 2015 Assignment #1 Simple C++ Due: Friday, January 16 Part 1. Get Qt Creator working Parts of this handout were written by Julie Zelenski. Your first task is

More information

NUMBERS AND NUMBER RELATIONSHIPS

NUMBERS AND NUMBER RELATIONSHIPS MODULE MODULE CHAPTERS Numbers and number patterns 2 Money matters KEY SKILLS writing rational numbers as terminating or recurring decimals identifying between which two integers any irrational number

More information

#23: Sequences March 28, 2009

#23: Sequences March 28, 2009 #23: Sequences March 28, 2009 a mysterious rule easy peasy Suppose n is an integer, and consider this simple rule: if n is even, divide it by two; otherwise, multiply n by 3, and add one. Pretty simple,

More information

Discrete Mathematics Exam File Fall Exam #1

Discrete Mathematics Exam File Fall Exam #1 Discrete Mathematics Exam File Fall 2015 Exam #1 1.) Which of the following quantified predicate statements are true? Justify your answers. a.) n Z, k Z, n + k = 0 b.) n Z, k Z, n + k = 0 2.) Prove that

More information

CS1132 Fall 2009 Assignment 1. 1 The Monty Hall Dillemma. 1.1 Programming the game

CS1132 Fall 2009 Assignment 1. 1 The Monty Hall Dillemma. 1.1 Programming the game CS1132 Fall 2009 Assignment 1 Adhere to the Code of Academic Integrity. You may discuss background issues and general solution strategies with others and seek help from course staff, but the homework you

More information

CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I

CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I Welcome to your CSCI-1100 Lab! In the fine tradition of the CSCI-1100 course, we ll start off the lab with the classic bad joke

More information

Announcements. Project 1 will be posted today on webpage and cvs. Due Tuesday

Announcements. Project 1 will be posted today on webpage and cvs. Due Tuesday Announcements Project 1 will be posted today on webpage and cvs Due Tuesday More Loops A H: either 0 or 1 Printing in base 2 Printing in base 2 A H: either 0 or 1 Mask Printing in base 2 A H: either 0

More information

The Quick And Easy Affiliate Setup List

The Quick And Easy Affiliate Setup List "Affiliate Marketing With Roy Carter!" Lesson #3 The Quick And Easy Affiliate Setup List - SUPPLEMENT - By Roy Carter NOTICE: You Do NOT Have the Right to Reprint or Resell this Report! You Also MAY NOT

More information

Lesson 4.02: Operations with Radicals

Lesson 4.02: Operations with Radicals Lesson 4.02: Operations with Radicals Take a Hike! Sheldon is planning on taking a hike through a state park. He has mapped out his route carefully. He plans to hike 3 miles to the scenic overlook, and

More information

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar Order from Chaos University of Nebraska-Lincoln Discrete Mathematics Seminar Austin Mohr Department of Mathematics Nebraska Wesleyan University February 8, 20 The (, )-Puzzle Start by drawing six dots

More information

Amber Weyland: [to cameraman] Just hold it there so we can see Mollie.

Amber Weyland: [to cameraman] Just hold it there so we can see Mollie. Interview Transcript Interviewer: Amber Weyland Interviewee: Mollie Hummer Cameraman: Christopher Smith [friend to both] Date: March 22, 2010 Beginning time of interview: 2:30pm End time of interview:

More information

CFP Education GTP FAQ

CFP Education GTP FAQ CFP Education GTP FAQ Is the CFP exam fee going to be reimbursed if I fail the exam? No. Students are responsible for applying and paying for the exam on their own. Dalton Education will not reimburse

More information

Recognizing a Function

Recognizing a Function Recognizing a Function LAUNCH (7 MIN) Before Why would someone hire a dog walking service? During Do you know exactly what it would cost to hire Friendly Dog Walking? After How does each service encourage

More information

1099s: Out of the Holding Tank

1099s: Out of the Holding Tank QuickBooks support from Diane Gilson... 1099s: Out of the Holding Tank Here are the basic steps to follow: You pay YOUR taxes, I pay MY taxes, but does everyone else out there pay THEIR taxes? Well, if

More information

Outline: Search and Recursion (Ch13)

Outline: Search and Recursion (Ch13) Search and Recursion Michael Mandel Lecture 12 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture12final.ipynb

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Number systems and binary

Number systems and binary CS101 Fundamentals of Computer and Information Sciences LIU 1 of 8 Number systems and binary Here are some informal notes on number systems and binary numbers. See also sections 3.1 3.2 of the textbook.

More information

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical Choose It Maker 2 Quick Guide Created 09/06 Updated SM Overview/Introduction This is a simple to use piece of software that can be tailored for use by children as an alternative to a pencil and paper worksheet,

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

(Refer Slide Time: 00:51)

(Refer Slide Time: 00:51) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute Technology, Madras Module 10 E Lecture 24 Content Example: factorial

More information