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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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