Team Prob. Team Prob

Size: px
Start display at page:

Download "Team Prob. Team Prob"

Transcription

1 1 Introduction In this module, we will be simulating the draft lottery used by the National Basketball Association (NBA). Each year, the worst 14 teams are entered into a drawing to determine who will get the first three picks in the upcoming draft. The lottery is designed so that the worse a team s record is, the better their chances of getting the first pick. You can find more information on how the lottery works here. For clarity we label the 14 teams in the lottery 1, 2,..., 14, with 1 corresponding to the team with the best chance of landing the first pick in the draft. Table?? shows the probability that each team wins the lottery and gets the first pick in the draft. Team Prob. Team Prob Table 1: Probability of getting the first pick in the draft At this point, it is important to formalize what we mean when we say that team 1 wins the lottery with probability We will adopt the frequency definition. 1 Briefly, suppose we repeatedly perform a random experiment, which can result in one of many outcomes, several times and record the number of times each outcome occurred. With these counts, we can compute the proportion of times each outcome occurred of each outcome by dividing the count by the number of trials. Now imagine that we were able to repeat the experiment for infinitely many trials. The probability of any particular outcome would be the proportion of trials which resulted in that outcome. So when we saw the probability that team 1 will win the lottery is 25%, we really mean that if we were to run the lottery infinitely many times, team 1 would win in a quarter of these trials. Unfortunately, we cannot actually perform any experiment infinitely often and we are limited to only finitely many trials. Luckily, if we perform a random experiment for a sufficiently large number of trials, the resulting empirical proportion of an outcome will be very close to the true probability. In the context of the NBA draft lottery, this means that if we were to simulate the lottery, say, 1,000,000 times, the number of times team 1 won the lottery will be very close to , 000, 000 = 250, Interpretting probabilities is a fundamental philosophical problem. For more information, check out the entry on interpreting probability in the Stanford Encyclopedia of Philosophy 2 This is essentially what the Law of Large Numbers guarantees 1

2 2 Generating Random Numbers in R One extremely useful feature of R is its ability to draw random numbers from a wide variety of probability distributions. For instance, let s say that we wish to pick a random number from the set {1, 2, 3, 4} uniformly (i.e. each number is equally likely to be picked). We can do this using the sample() function. [ 1 ] 1 [ 1 ] 1 [ 1 ] 4 [ 1 ] 1 Looking at these examples, however, it is not immediately obvious that each number was equally likely to be picked (in fact, there is barely a 10% chance that 2 was not picked in 8 repeated uniform drawings from {1, 2, 3, 4}). One way to see whether sample() is actually picking the numbers uniformly at random, we can ask it to simulate this random drawing 1,000,000 times and make a histogram to measure the relatively frequency that each number is picked. The following code does just that and produces the image in Figure 1 > x < sample ( 1 : 4, s i z e = , r e p l a c e = TRUE) > h i s t ( x, breaks = seq ( 0, 4, by = 1), f r e q = FALSE, ylim = c (0, 0. 3 ) ) > a b l i n e ( h = , c o l = ' red ' ) 2

3 Figure 1: Histogram showing results of repeatedly sampling uniformly from {1, 2, 3, 4}. There are a few things to observe in this code above. First, when we call the sample() function, we must specify replace=true. If we had left replace=false (which is the default setting), we would have gotten an error: > sample ( 1 : 4, s i z e = , r e p l a c e = FALSE) Error in sample. i n t ( l ength ( x ), s i z e, r e p l a c e, prob ) : cannot take a sample l a r g e r than the population when ' r e p l a c e = FALSE ' After defining the vector x, we create a histogram. We have manually set the breaks argument so that the bins in our histogram go from 0 to 1, 1 to 2, etc. We have also set the freq argument to FALSE, yielding a density histogram. Finally, we have added a red line at height It is quite reassuring to see that each number was picked approximately 25% of the time! Up to this point, we have only seen how sample() can be used to generating from a set uniformly at random. In order to properly simulate the draft lottery process, we need to draw numbers from a non-uniform distribution. This is where the prob argument in sample() comes in handy. Exercise 1. Just like we did in Figure 1, verify that when we set the argument prob = c(0.5, 0.25, 0.15, 0.1) in sample(1:4, replace = TRUE), the number 1 is picked about 50% of the time, 2 is 3

4 picked about 25% of the time, 3 is picked about 15% of the time, and 4 is picked 10% of the time 2. Create a vector named lottery.probs that contains the probability listed in Table??each team in the lottery wins. Pass this vector as the prob argument to sample() to simulate the winner of the lottery 1,000,000. Make a histogram similar to Figure 1 based on these results. 4

5 3 Beyond the first pick Admittedly, the last exercise was a bit anti-climatic, in light of our frequentist interpretation of probability. Using just the values in Table 1, it is not trivial to compute the probability that a team gets the 2 nd pick in the draft. In order to simulate the full draft order we ll need to do a bit more work. The actual lottery is performed as follows: teams are assigned a set of four-number combinations from {1, 2,..., 14}, with the team with the worst record receiving 250 combinations, the team with the second-worst record receiving 199 combinations, and so on. To determine the first pick, four balls are selected uniformly and at random, with replacement, from a bin of balls labelled 1, 2,..., 14. The team who has that combination is awarded the first pick. Then, the process of drawing four balls from the bin is repeated and the team with the resulting combination is awarded the second pick. Since no team can be awarded multiple picks through the lottery, if the team with the first pick also owns the second four-number combination drawn, the process of drawing four balls is repeated until we get a combination which does not belong to the team with the first pick. A similar procedure is followed to award the third pick. After the first three picks have been awarded, the remainder of the draft order is set by team record. Rather than simulate the actual process of drawing four balls and looking up which teams own which combinations, we will simulate an equivalent process. In particular, we will use sample() to pick a number from {1, 2,..., 14} with probabilities listed in Table 1 to determine which team gets the first pick. We ll then pick another number from {1, 2,..., 14} with the same probabilities. If they are equal, we will keep drawing until we get a new number to determine who gets the second pick. In order to program the process of repeatedly drawing until we get a new number, we need to use a while() loop. A while() loop consists of two parts: a logical condition and a block of code. The loop starts by checking the condition and if it is TRUE, it will execute the block of code. It will moreover repeatedly execute the block of code until the condition is no longer true. Here s a really basic example of a while() loop > x < 0 > while ( x < 5) + p r i n t ( paste0 ( "x = ", x ) ) + x < x + 1 [ 1 ] "x = 0" [ 1 ] "x = 1" [ 1 ] "x = 2" [ 1 ] "x = 3" [ 1 ] "x = 4" > x [ 1 ] 5 In this example, the loop checks to see whether or not x is less than 5. If x < 5, then we add one to 5

6 x and check the condition again. From the printed statements, we see that the block of code within the loop (i.e. between the curled braces) is executed until x = 5. Note that a while() loop will continue executing the block of code until the condition is no longer TRUE, meaning that there is a potential for a while() loop to continue indefinitely. Such infinite loops are highly problematic and care must be taken to avoid them. If you find yourself stuck in an infinite loop, you should halt the execution with ESC key. To avoid getting stuck in an infinite loop, you need to make sure that the you haven t used a constraint that is always TRUE. Additionally, you need to make sure that there is a way to update the expression or quantities being checked by the condition in the block of code being executed. For instance, in the above example, if we had neglected to include x < x + 1, then there would be no way for the condition x < 5 to fail. To simulate awarding first and second picks of the draft, we can do > f i r s t. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) > second. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) > while ( second. pick == f i r s t. pick ) + p r i n t ( " f i r s t. pick = second. pick! need to re draw f o r 2nd pick " ) + second. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) > > > f i r s t. pick > second. pick [ 1 ] 4 In this example, we first drew the first pick and second picks and stored their values as first.pick and second.pick. We then wrote a while() loop to re-draw the second pick if necessary. Notice in the while() loop we included a print statement. This lets us know that we have started executing the block of code contained in the while() loop. The fact that nothing was printed when we executed the code in this example means that in this case, we did not have to re-draw for the second pick (we confirm this at the end of the example). Exercise 1. Execute the code in the example above several times. Keep track of the number of times that you had to re-draw the second pick. Hint: It d be helpful to write this code in a script. Then you can select all of the lines and execute them at once with Command+Enter on a Mac or Control + R on Windows 6

7 The previous exercise had you repeatedly execute a block code several times by hand. This process, however, is not scalable, especially if you wish to simulate drawing the first two picks 1,000,000 times. This brings us to for () loops. Basically, a for () loop allows us to repeatedly execute a block of code several times. Like a while() loop, a for () consists of two parts: a vector of iterators and a block of code. For each iterator in the vector, the loop will execute the block of code. > f o r ( i in 1 : 4 ) + f i r s t. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) + p r i n t ( f i r s t. pick ) [ 1 ] 2 [ 1 ] 8 In this example, we have drawn the first pick of the draft 4 separate times, each time printing the result. Typically, when we use a for () loop to simulate a random process, we d like to save the results in a matrix or data.frame. In this case, we ll use a matrix > p i c k s. matrix < matrix ( nrow = 5, ncol = 2, dimnames = l i s t ( c ( ), c ( " F i r s t Pick ", " Second Pick " ) ) ) > f o r ( i in 1 : 5 ) + f i r s t. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) + second. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) + while ( second. pick == f i r s t. pick ) + second. pick < sample ( 1 : 1 4, s i z e = 1, r e p l a c e = TRUE, prob = l o t t e r y. probs ) + + p i c k s. matrix [ i, " F i r s t Pick " ] < f i r s t. pick + p i c k s. matrix [ i, " Second Pick " ] < second. pick + In this example, we first created a matrix picks.matrix to store the results from our simulation. Then we ran the code we wrote earlier simulate the first two picks (note, we removed the print() statement from the while() loop for ease of presentation). The resulting picks were 7

8 F i r s t Pick Second Pick [ 1, ] 2 14 [ 2, ] 2 1 [ 3, ] 6 1 [ 4, ] 1 2 [ 5, ] 4 1 We are now equipped to answer the following question What is the probability that team 1 gets the second pick of the draft? Above, we see that team 1 received the second pick 3 times out 5 (i.e. 60% of the time). Unfortunately, 5 simulations is by no means close to sufficient to determine this probability accurately. We need, instead, to do something like 1,000,000 simulations and in this case, we can not rely on printed output to find the probability. Instead, we can do the following: > mean( p i c k s. matrix [, " Second Pick " ] == 1) [ 1 ] 0. 6 This line of code is doing several things: first, the expression picks. matrix[,"second Pick"] == 1 creates a logical vector. R can evaluate TRUE s to be 1 s and FALSE s to be 0 s so when we pass this vector to mean(), we are simply computing the proportion of TRUE s. This is precisely the proportion of simulations in which the second pick went to team 1. Exercises 1. Modify the code in the example above to simulate drawing the first two draft picks 1,000,000 times. 2. For each team, compute the probability that it is awarded the second pick in the draft. At this point, you may be wondering how we can modify our code to answer questions such as What is the probability that team 1 does not get either the first pick or the second pick in the draft? and What is the probability that team 5 gets either the first pick or the second pick? To answer this, we need the quantifies like AND and OR. Indeed, the first probability is the proportion of times that picks. matrix[,"first Pick"]! = 1 AND picks. matrix[,"second Pick"]!= 1, while the second probability is the proportion of times that picks. matrix[,"first Pick"] == 5 OR picks. matrix[,"second Pick"] == 5. In R, the AND quantifier is denoted & and the OR quantifier is denoted. We can use them as follows: > mean( p i c k s. matrix [, " Second Pick " ]!= 1 & p i c k s. matrix [, " F i r s t Pick " ]!= 1) > mean( p i c k s. matrix [, " Second Pick " ] == 5 p i c k s. matrix [, " F i r s t Pick " ] == 5) 8

9 4 The first 3 picks Up to this point, we ve only focused on the first two picks of the draft. In order to simulate drawing the third pick we can add to the code we ve written before. First, we can create a new variable called third.pick and initialize it like we did with second.pick. We can then go ahead and re-draw second.pick as necessary until we know that first. pick! = second.pick. We then can write another while() loop to re-draw the third pick as necessary. The condition in this loop, however, is a little bit more complex than the previous loop. In particular, we need to re-draw third.pick if third. pick == first.pick OR third.pick == second.pick. We can add the OR operator to our condition with the symbol: > while ( t h i r d. pick == f i r s t. pick t h i r d. pick == second. pick ) {... } Exercise 1. Fill in the... in the above example with the code necessary to re-draw third.pick. At this point, you should have a single block of code that will simulate drawing the first three picks of the draft. 2. Wrap this block of code into a for () loop and simulate drawing the first pick 100 times. Be sure to save the resulting picks in a matrix like the one we created above. 3. Using this matrix, answer the following questions (a) What is the probability that team 1 gets the second or third pick? (b) What is the probability that team 14 gets one of the top three picks? (c) What is the probability that team 1 does not get any of the top 3 picks? 9

Lab 3: Sampling Distributions

Lab 3: Sampling Distributions Lab 3: Sampling Distributions Sampling from Ames, Iowa In this lab, we will investigate the ways in which the estimates that we make based on a random sample of data can inform us about what the population

More information

LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT

LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT NAVAL POSTGRADUATE SCHOOL LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT Statistics (OA3102) Lab #2: Sampling, Sampling Distributions, and the Central Limit Theorem Goal: Use R to demonstrate sampling

More information

Here is a sample IDLE window illustrating the use of these two functions:

Here is a sample IDLE window illustrating the use of these two functions: 1 A SLIGHT DETOUR: RANDOM WALKS One way you can do interesting things with a program is to introduce some randomness into the mix. Python, and most programming languages, typically provide a library for

More information

Chapter 6: DESCRIPTIVE STATISTICS

Chapter 6: DESCRIPTIVE STATISTICS Chapter 6: DESCRIPTIVE STATISTICS Random Sampling Numerical Summaries Stem-n-Leaf plots Histograms, and Box plots Time Sequence Plots Normal Probability Plots Sections 6-1 to 6-5, and 6-7 Random Sampling

More information

In the real world, light sources emit light particles, which travel in space, reflect at objects or scatter in volumetric media (potentially multiple

In the real world, light sources emit light particles, which travel in space, reflect at objects or scatter in volumetric media (potentially multiple 1 In the real world, light sources emit light particles, which travel in space, reflect at objects or scatter in volumetric media (potentially multiple times) until they are absorbed. On their way, they

More information

Notes on Turing s Theorem and Computability

Notes on Turing s Theorem and Computability Notes on Turing s Theorem and Computability Walter Neumann About 60 years ago there was a revolution in mathematics and philosophy. First Gödel and then Turing showed that there are impossible problems

More information

Chapter 16 Heuristic Search

Chapter 16 Heuristic Search Chapter 16 Heuristic Search Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction Variables

More information

III Data Structures. Dynamic sets

III Data Structures. Dynamic sets III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations

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

1 Pencil and Paper stuff

1 Pencil and Paper stuff Spring 2008 - Stat C141/ Bioeng C141 - Statistics for Bioinformatics Course Website: http://www.stat.berkeley.edu/users/hhuang/141c-2008.html Section Website: http://www.stat.berkeley.edu/users/mgoldman

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

6. Relational Algebra (Part II)

6. Relational Algebra (Part II) 6. Relational Algebra (Part II) 6.1. Introduction In the previous chapter, we introduced relational algebra as a fundamental model of relational database manipulation. In particular, we defined and discussed

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

An introduction to plotting data

An introduction to plotting data An introduction to plotting data Eric D. Black California Institute of Technology February 25, 2014 1 Introduction Plotting data is one of the essential skills every scientist must have. We use it on a

More information

Probability and Statistics for Final Year Engineering Students

Probability and Statistics for Final Year Engineering Students Probability and Statistics for Final Year Engineering Students By Yoni Nazarathy, Last Updated: April 11, 2011. Lecture 1: Introduction and Basic Terms Welcome to the course, time table, assessment, etc..

More information

RECURSION. Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist

RECURSION. Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist RECURSION Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker Pre-Laboratory Checklist vvskills: You can write any conditional expression. vvknowledge:

More information

14.1 Encoding for different models of computation

14.1 Encoding for different models of computation Lecture 14 Decidable languages In the previous lecture we discussed some examples of encoding schemes, through which various objects can be represented by strings over a given alphabet. We will begin this

More information

Regularization and model selection

Regularization and model selection CS229 Lecture notes Andrew Ng Part VI Regularization and model selection Suppose we are trying select among several different models for a learning problem. For instance, we might be using a polynomial

More information

Lecture 4: examples of topological spaces, coarser and finer topologies, bases and closed sets

Lecture 4: examples of topological spaces, coarser and finer topologies, bases and closed sets Lecture 4: examples of topological spaces, coarser and finer topologies, bases and closed sets Saul Glasman 14 September 2016 Let s give the definition of an open subset of R. Definition 1. Let U R. We

More information

n! = 1 * 2 * 3 * 4 * * (n-1) * n

n! = 1 * 2 * 3 * 4 * * (n-1) * n The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are

More information

Kuratowski Notes , Fall 2005, Prof. Peter Shor Revised Fall 2007

Kuratowski Notes , Fall 2005, Prof. Peter Shor Revised Fall 2007 Kuratowski Notes 8.30, Fall 005, Prof. Peter Shor Revised Fall 007 Unfortunately, the OCW notes on Kuratowski s theorem seem to have several things substantially wrong with the proof, and the notes from

More information

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list?

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list? 1 Practice problems Here is a collection of some relatively straightforward problems that let you practice simple nuts and bolts of programming. Each problem is intended to be a separate program. 1. Write

More information

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: September 28, 2016 Edited by Ofir Geri

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: September 28, 2016 Edited by Ofir Geri CS161, Lecture 2 MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: September 28, 2016 Edited by Ofir Geri 1 Introduction Today, we will introduce a fundamental algorithm design paradigm,

More information

2. Use elementary row operations to rewrite the augmented matrix in a simpler form (i.e., one whose solutions are easy to find).

2. Use elementary row operations to rewrite the augmented matrix in a simpler form (i.e., one whose solutions are easy to find). Section. Gaussian Elimination Our main focus in this section is on a detailed discussion of a method for solving systems of equations. In the last section, we saw that the general procedure for solving

More information

4.7 Approximate Integration

4.7 Approximate Integration 4.7 Approximate Integration Some anti-derivatives are difficult to impossible to find. For example, 1 0 e x2 dx or 1 1 1 + x3 dx We came across this situation back in calculus I when we introduced the

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

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

Welfare Navigation Using Genetic Algorithm

Welfare Navigation Using Genetic Algorithm Welfare Navigation Using Genetic Algorithm David Erukhimovich and Yoel Zeldes Hebrew University of Jerusalem AI course final project Abstract Using standard navigation algorithms and applications (such

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF Copyright Cengage Learning. All rights reserved. SECTION 4.3 Direct Proof and Counterexample III: Divisibility Copyright Cengage Learning. All rights

More information

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015 CS161, Lecture 2 MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015 1 Introduction Today, we will introduce a fundamental algorithm design paradigm, Divide-And-Conquer,

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

User Defined Functions

User Defined Functions User Defined Functions 120 90 1 0.8 60 Chapter 6 150 0.6 0.4 30 0.2 180 0 210 330 240 270 300 Objectives Create and use MATLAB functions with both single and multiple inputs and outputs Learn how to store

More information

Programming for Experimental Research. Flow Control

Programming for Experimental Research. Flow Control Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated

More information

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF Copyright Cengage Learning. All rights reserved. SECTION 4.3 Direct Proof and Counterexample III: Divisibility Copyright Cengage Learning. All rights

More information

Fall 2004 CS414 Prelim 1

Fall 2004 CS414 Prelim 1 Fall 2004 CS414 Prelim 1 1. The Sim City Smoking Ban problem: In the Sim-City community Woobish most people smoke, but the laws of Sim City require that non-smokers be protected from passive smoke. So

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

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present

More information

9. MATHEMATICIANS ARE FOND OF COLLECTIONS

9. MATHEMATICIANS ARE FOND OF COLLECTIONS get the complete book: http://wwwonemathematicalcatorg/getfulltextfullbookhtm 9 MATHEMATICIANS ARE FOND OF COLLECTIONS collections Collections are extremely important in life: when we group together objects

More information

Electrical Circuits and Random Walks

Electrical Circuits and Random Walks Electrical Circuits and Random Walks LA Math Circle, High School II December 2, 2018 This worksheet is largely about graphs. Whenever there is a graph G, V (G) will denote the set of vertices of G, and

More information

16 Greedy Algorithms

16 Greedy Algorithms 16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices

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

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018 Contents 1 Imperative Programming 1 1.1 Sky High Grades......................................

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

Cantor s Diagonal Argument for Different Levels of Infinity

Cantor s Diagonal Argument for Different Levels of Infinity JANUARY 2015 1 Cantor s Diagonal Argument for Different Levels of Infinity Michael J. Neely University of Southern California http://www-bcf.usc.edu/ mjneely Abstract These notes develop the classic Cantor

More information

Bulgarian Math Olympiads with a Challenge Twist

Bulgarian Math Olympiads with a Challenge Twist Bulgarian Math Olympiads with a Challenge Twist by Zvezdelina Stankova Berkeley Math Circle Beginners Group September 0, 03 Tasks throughout this session. Harder versions of problems from last time appear

More information

1 Matrices and Vectors and Lists

1 Matrices and Vectors and Lists University of Wollongong School of Mathematics and Applied Statistics STAT231 Probability and Random Variables 2014 Second Lab - Week 4 If you can t finish the log-book questions in lab, proceed at home.

More information

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) What is the Metacircular Evaluator? It is the best part

More information

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist In Handout 28, the Guide to Inductive Proofs, we outlined a number of specifc issues and concepts to be mindful about when

More information

Project 1 Balanced binary

Project 1 Balanced binary CMSC262 DS/Alg Applied Blaheta Project 1 Balanced binary Due: 7 September 2017 You saw basic binary search trees in 162, and may remember that their weakness is that in the worst case they behave like

More information

Hashing and sketching

Hashing and sketching Hashing and sketching 1 The age of big data An age of big data is upon us, brought on by a combination of: Pervasive sensing: so much of what goes on in our lives and in the world at large is now digitally

More information

Due Thursday, July 18 at 11:00AM

Due Thursday, July 18 at 11:00AM CS106B Summer 2013 Handout #10 July 10, 2013 Assignment 3: Recursion! Parts of this handout were written by Julie Zelenski, Jerry Cain, and Eric Roberts. This assignment consists of four recursive functions

More information

Chapel Hill Math Circle: Symmetry and Fractals

Chapel Hill Math Circle: Symmetry and Fractals Chapel Hill Math Circle: Symmetry and Fractals 10/7/17 1 Introduction This worksheet will explore symmetry. To mathematicians, a symmetry of an object is, roughly speaking, a transformation that does not

More information

Assignment 3: Block Ciphers

Assignment 3: Block Ciphers Assignment 3: Block Ciphers CSCI3381-Cryptography Due October 3, 2014 1 Solutions to the Written Problems 1. Block Cipher Modes of Operation 6 points per part, 30 total. Parts (a)-(d) refer to the cipherblock

More information

Monte Carlo Integration

Monte Carlo Integration Lab 18 Monte Carlo Integration Lab Objective: Implement Monte Carlo integration to estimate integrals. Use Monte Carlo Integration to calculate the integral of the joint normal distribution. Some multivariable

More information

Worst-case running time for RANDOMIZED-SELECT

Worst-case running time for RANDOMIZED-SELECT Worst-case running time for RANDOMIZED-SELECT is ), even to nd the minimum The algorithm has a linear expected running time, though, and because it is randomized, no particular input elicits the worst-case

More information

Let denote the number of partitions of with at most parts each less than or equal to. By comparing the definitions of and it is clear that ( ) ( )

Let denote the number of partitions of with at most parts each less than or equal to. By comparing the definitions of and it is clear that ( ) ( ) Calculating exact values of without using recurrence relations This note describes an algorithm for calculating exact values of, the number of partitions of into distinct positive integers each less than

More information

Lecture 10. Finding strongly connected components

Lecture 10. Finding strongly connected components Lecture 10 Finding strongly connected components Announcements HW4 due Friday Nothing assigned Friday because MIDTERM in class, Monday 10/30. Please show up. During class, 1:30-2:50 If your last name is

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

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Excerpt from Art of Problem Solving Volume 1: the Basics 2014 AoPS Inc. Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

Import Statements, Instance Members, and the Default Constructor

Import Statements, Instance Members, and the Default Constructor Import Statements, Instance Members, and the Default Constructor Introduction In this article from my free Java 8 course, I will be discussing import statements, instance members, and the default constructor.

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

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation

More information

Chapter 15 Introduction to Linear Programming

Chapter 15 Introduction to Linear Programming Chapter 15 Introduction to Linear Programming An Introduction to Optimization Spring, 2015 Wei-Ta Chu 1 Brief History of Linear Programming The goal of linear programming is to determine the values of

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

height VUD x = x 1 + x x N N 2 + (x 2 x) 2 + (x N x) 2. N

height VUD x = x 1 + x x N N 2 + (x 2 x) 2 + (x N x) 2. N Math 3: CSM Tutorial: Probability, Statistics, and Navels Fall 2 In this worksheet, we look at navel ratios, means, standard deviations, relative frequency density histograms, and probability density functions.

More information

Computational Geometry: Lecture 5

Computational Geometry: Lecture 5 Computational Geometry: Lecture 5 Don Sheehy January 29, 2010 1 Degeneracy In many of the algorithms that we have discussed so far, we have run into problems when that input is somehow troublesome. For

More information

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions): CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 7 This lecture returns to the topic of propositional logic. Whereas in Lecture 1 we studied this topic as a way of understanding proper reasoning

More information

Starting Boolean Algebra

Starting Boolean Algebra Boolean Algebra March 2, 27 Diagram for FunChip2 Here is a picture of FunChip2 that we created more or less randomly in class on /25 (used in various Activities): Starting Boolean Algebra Boolean algebra

More information

Short-Cut MCMC: An Alternative to Adaptation

Short-Cut MCMC: An Alternative to Adaptation Short-Cut MCMC: An Alternative to Adaptation Radford M. Neal Dept. of Statistics and Dept. of Computer Science University of Toronto http://www.cs.utoronto.ca/ radford/ Third Workshop on Monte Carlo Methods,

More information

Chapter 2: Modeling Distributions of Data

Chapter 2: Modeling Distributions of Data Chapter 2: Modeling Distributions of Data Section 2.2 The Practice of Statistics, 4 th edition - For AP* STARNES, YATES, MOORE Chapter 2 Modeling Distributions of Data 2.1 Describing Location in a Distribution

More information

Multi-step transformations

Multi-step transformations October 6, 2016 Transformations (section 1.6) Day 4 page 1 Multi-step transformations Objective: Apply transformations involving multiple steps or multiple substitutions. Upcoming: We will have a test

More information

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 13 Merging using Queue ADT and Queue types In the

More information

GOV 2001/ 1002/ E-2001 Section 1 1 Monte Carlo Simulation

GOV 2001/ 1002/ E-2001 Section 1 1 Monte Carlo Simulation GOV 2001/ 1002/ E-2001 Section 1 1 Monte Carlo Simulation Anton Strezhnev Harvard University January 27, 2016 1 These notes and accompanying code draw on the notes from TF s from previous years. 1 / 33

More information

Shadows in the graphics pipeline

Shadows in the graphics pipeline Shadows in the graphics pipeline Steve Marschner Cornell University CS 569 Spring 2008, 19 February There are a number of visual cues that help let the viewer know about the 3D relationships between objects

More information

Understanding Recursion

Understanding Recursion Understanding Recursion sk, rob and dbtucker (modified for CS 536 by kfisler) 2002-09-20 Writing a Recursive Function Can we write the factorial function in AFunExp? Well, we currently don t have multiplication,

More information

CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers

CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers CIS 194: Homework 6 Due Monday, February 25 Files you should submit: Fibonacci.hs This week we learned about Haskell s lazy evaluation. This homework assignment will focus on one particular consequence

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Probability, Simulations & Course Wrap-Up Raymond Yin University of Pennsylvania December 8, 2016 Raymond Yin (University of Pennsylvania) CIS 192 December 8, 2016 1 / 21 Outline

More information

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14 600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14 23.1 Introduction We spent last week proving that for certain problems,

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

Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018

Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018 Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018 Contents Overview 2 Generating random numbers 2 rnorm() to generate random numbers from

More information

CS 4349 Lecture October 18th, 2017

CS 4349 Lecture October 18th, 2017 CS 4349 Lecture October 18th, 2017 Main topics for #lecture include #minimum_spanning_trees. Prelude Homework 6 due today. Homework 7 due Wednesday, October 25th. Homework 7 has one normal homework problem.

More information

An aside. Lecture 14: Last time

An aside. Lecture 14: Last time An aside Lecture 14: Recall from last time that aggregate() allowed us to combine data that referred to the same building; it is possible to implement this with lower-level tools in R Similarly, our dance

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

The Bizarre Truth! Automating the Automation. Complicated & Confusing taxonomy of Model Based Testing approach A CONFORMIQ WHITEPAPER

The Bizarre Truth! Automating the Automation. Complicated & Confusing taxonomy of Model Based Testing approach A CONFORMIQ WHITEPAPER The Bizarre Truth! Complicated & Confusing taxonomy of Model Based Testing approach A CONFORMIQ WHITEPAPER By Kimmo Nupponen 1 TABLE OF CONTENTS 1. The context Introduction 2. The approach Know the difference

More information

1 of 5 3/28/2010 8:01 AM Unit Testing Notes Home Class Info Links Lectures Newsgroup Assignmen [Jump to Writing Clear Tests, What about Private Functions?] Testing The typical approach to testing code

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

Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn

Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn Difference Between Dates Case Study 2002 M. J. Clancy and M. C. Linn Problem Write and test a Scheme program to compute how many days are spanned by two given days. The program will include a procedure

More information

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9 CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9 What problems are beyond our capacity to solve? Why are they so hard? And why is anything that we've discussed this quarter at all practically

More information

Logic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009

Logic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009 Logic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009 Note that I change the name of the functions slightly in these notes from what I used in class, to be consistent with

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

A Quick Introduction to R

A Quick Introduction to R Math 4501 Fall 2012 A Quick Introduction to R The point of these few pages is to give you a quick introduction to the possible uses of the free software R in statistical analysis. I will only expect you

More information

Statistics: Interpreting Data and Making Predictions. Visual Displays of Data 1/31

Statistics: Interpreting Data and Making Predictions. Visual Displays of Data 1/31 Statistics: Interpreting Data and Making Predictions Visual Displays of Data 1/31 Last Time Last time we discussed central tendency; that is, notions of the middle of data. More specifically we discussed

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Why Deprecating async() is the Worst of all Options

Why Deprecating async() is the Worst of all Options Doc No: WG21 N3780 Date: 2013-09-26 Reply to: Nicolai Josuttis (nico@josuttis.de) Subgroup: SG1 Concurrency Prev. Version: none Why Deprecating async() is the Worst of all Options The concurrency working

More information

Random Oracles - OAEP

Random Oracles - OAEP Random Oracles - OAEP Anatoliy Gliberman, Dmitry Zontov, Patrick Nordahl September 23, 2004 Reading Overview There are two papers presented this week. The first paper, Random Oracles are Practical: A Paradigm

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 21 Tuesday, April 15, 2014 1 Static program analyses For the last few weeks, we have been considering type systems.

More information