Write a program in python 3 to generate a table giving

Assignment Help Computer Engineering
Reference no: EM132211234

Question :

Write a program in Python 3 to generate a table giving information related to the birthday problem. Assume that the number of days is 366, but let it be a variable so that you could use the program on other planets, for checking resistance to birthday attacks, or if I have already won several bets so that on the next bet we could reduce the number of days. Similarly, leave the maximum number of students (in this case 70) as a variable.

I will describe each column of the table separately. You might want to write your program so that it runs for one column before adding another column. In addition to the following, attach a printout of your program.

(a) The first column should give the number of people in the room (in- cluding me) and should go from 1 to 70. Have an appropriate header for the column.

(b) The second column should give the probability of me losing the bet (that is, all k people have different birthdays). So if there is only one person, all birthdays would be different with probability one. If there were two, all would be different with probability probability 365/366. If there were three, all would be different with probability 365(364)/3662 . This should also suggest a way to recursively, compute these prob- abilities.

Let P(k) be the probability that k people have different birthdays assuming n = 1 days, all days are equally likely, and one person's birthday does not influence the birthday of others. (Later, we will call this independence.) For this program, n = 366. Check the following formula to see if the following statements are correct, but I think we know that P (0) = 1.0 and P (k) = P (k - 1) * (n - k + 1)/n for k = 1. Please do the computations in floating point.

(c) Explain the logic behind the equation P(k) = P(k-1)*(n-k+1)/n, or the corrected equation if that equation is wrong.

(d) How big should the class be before I should start making the birthday bet? and what is the probability of me winning?

(e) We computed the probability based on a model. Is the actual proba- bility of me winning bigger or smaller than what we computed from our model? Explain.

(f) If there are 65 students in class, what is the probability of me winning. (If it's really close to one, it's probably better to express it as 1- something really small.

On page 116 of our text, Professor Hajek writes "When we deal with probabilities that are close to one it is usually more convenient to represent them as one minus something, for example writing 18.5106 instead of 0.9999915. When we deal with probabilities that are close to one it is usually more convenient to represent them as one minus something, for example writing 18.5106 instead of 0.9999915." Also, if you double check your answers by comparing with results on-line, you might need to change 366 to 365.).

(g) Are you more likely to win the jackpot in the lottery with one ticket or win the birthday bet against me assuming there are 70 of us in the room?

(h) (Optional) Add another column where you also compute the proba- bility of me losing, but compute it in a different way. In the recursive equation for P(k) keep track of the numerator and the denominator separately where both the numerator and the denominator are in- tegers. Thus, you have the exact value of P(k) as a fraction.

Now convert the fraction to a floating point number, and print it. (I gather that Python 3 automatically does converts integers to floating point when doing division so 1/3 will be something like .333, but Python 2 would say 1/3 is 0.) So the only error introduced should be the con- version from the fraction to the closest floating point number. This should be extremely accurate. I am interested in two things: first, you might have trouble with integers overflowing at some point. Does that happen?

If so, how many people can there be before you this happens? (One of the things that I learned was the pleasant surprise that Python can handle large integers without overflowing. I thought Python would have trouble with 36670.)

(i) (Optional) Since we are able to compute the probability two ways, we can check to see if there is there much of a difference? Generally, multiplying and dividing floating point numbers is fairly safe, but ad- dition and subtraction can be perilous. Since we are just multiplying and dividing floating point numbers in the first method, I'm guessing that the two methods should produce answers that are really close to each other.

The error should be the approximation minus the cor- rect answer. If x is the correct answer and y is the approximation, then y - x is the error. Use the second method above as the correct answer, and the first method as the approximation. Add a column giving the errors. Are the errors small? What is the worst error? (If you look on-line about errors, be careful since some authors use the absolute value of y - x.)

(j) (Optional) When dealing with small probabilities, the relative error is more important than the error.

There's a big difference in an error of .001 when the true probability is .5 and when it's .00000005. For x > 0, the relative error of approximating x by y is (y - x)/x. Add a column giving the relative errors. Are the relative errors small?

What is the worst relative error? (Again, if you're looking on-line, be careful about slight differences in the definition of relative error. One advantage of allowing the error to be positive or negative is that you can see if the approximation is above or below the true value.)

Reference no: EM132211234

Questions Cloud

Prompt the user to enter the position of an object : Write a program that prompts the user to enter the position of an object (an integer number) and the move type, the program uses the switch statement.
What are your contractual remedies against via egnatia : The three of you ate out last night at local establishment in Anderson called "Via Egnatia,". What are your contractual remedies against Via Egnatia (if any)?
Prompt the user to enter a multi-digit hexadecimal value : Write a program that prompts the user to enter a multi-digit hexadecimal (i.e., base 16) value as string.
Target supermarket complete the matrix with ten strengths : Target Supermarket Complete the (Internal Factor Evaluation (IFE) Matrix with ten (10) strengths and ten (10) weaknesses. P
Write a program in python 3 to generate a table giving : Write a program in Python 3 to generate a table giving information related to the birthday problem.
Operations differ from less-than-truckload operation : How do truck load operations differ from less-than-truckload operation
Stadium operators for negligence and premises liability : when hit on the head by a foul ball at a minor league baseball game and sued the stadium operators for negligence and premises liability.
Write a program in python for creating a binary search tree : Write a program in PYTHON for creating a binary search tree (BST) from a given number randomly generated integer values
Stride is model-based threat modeling technique developed : STRIDE is a model-based threat modeling technique developed by Microsoft.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Design the program in vb.net

Write down the program in VB.Net (not Web based) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term. Display the mortgage payment amount. Insert comments to document the program.

  Explain computer forensic investigation procedures

Explain computer forensic investigation procedures. Evaluate sources of evidence. Analyze laws related computer forensics.

  Draw a data model for the entities and considering entities

Draw a data model for the following entities, considering the entities as representing a system for a patient billing system and including only the attributes that would be appropriate for this context.

  Write a function called countlines that takes a string

Write a function called countLines() that takes a string representing the name of a file as a parameter, & a string representing a word as the second parameter.

  Explain how costs can be reduced with such a rating system

CPIS604 Project - R Coding and Modelling. Explain briefly how costs can be reduced with such a rating system. Suggest a refined question about saving costs, and what you expect to benefit from answering this question. What would be a way to answer th..

  Explain how other firms employ this concept of intangibles

what is values-based service? how can a company create value for customers and other stakeholders?values-based service

  How many edges are there in a tree with 57 vertices

How many edges are there in a tree with 57 vertices - How many internal vertices are there in a full binary tree of height 10?

  How can one protect against virus outbreaks in organization

How can one protect against virus outbreaks in an organization? What are the common causes of this problems? How would use address this troublesome trend? Use your textbook, internet, and other publications to research this topic.

  How your estimates change as the sample size changes

Generate a sample from a multivariate normal density N(µ, S), calculate m and S. Check how your estimates change as the sample size changes.

  Discuss the second order serial correlations

Refit the constant elasticity form of the model as a dynamic model, including L. Packps as a repressor. Use the two step robust DPD estimator of xtabad2.

  Devise 7-bit even-parity hamming code for the digits 0 to 9

Devise a 7-bit even-parity Hamming code for the digits 0 to 9.

  A shows a commutator diagram to describe time division

a. shows a commutator diagram to describe time division multiplexing. sketch the multiplexed signal over the range 0 to

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd