Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Subject:parallel programing PROBLEM 2 (25 pts) A famous Google interview question has been: Assume that you flip a fair coin until one of the following

Subject:parallel programingimage text in transcribed

PROBLEM 2 (25 pts) A famous Google interview question has been: "Assume that you flip a fair coin until one of the following patterns of consecutive outcomes appears: HHT (head head tail) or HTH (head tail head). Find the probability that HHT pattern appears first and the probability that the HTT pattern appears first. This question may be solved using advanced probability theory and the precise answers will be 2/3 and 1/3 Inspired by the above question, in this problem you are required to design a multi-threaded program named ProbabilityEstimation to estimate the probabilities that each among two given patterns (of H-s and T-s) appears first. The program will estimate the probabilities by repeating the random experiment many times and counting how many times each pattern appears first. So if the random experiment in the case of the given Google interview question is repeated 1000000 times and the pattern HHT appears first in 665000 of these experiments (and the pattern HTT appears first in 33500 of the experiments), then the estimated values of the probabilities are 0.665 (for HHT) and 0.335 (for HTH). The program receives as command line parameters the two patterns (of H-s and T-s) and optionally the number of trials (i.e. times to repeat the random experiment) and the number of threads that will be used to solve the problem. If the optional arguments are not provided then the default number of trials is 1000000 and the default number of threads is 10. A sample execution (if you are using Java) may be: java ProbabilityEstimation HHT HTT 2000000 8 Or if you are using POSIX threads may be: ./ProbabilityEstimation HHT HTT 2000000 8 The expected result will look like: Estimated values with 2000000 random experiments with 8 threads: The probability that HHT appears first is 0.66671 The probability that HTT appears first is 0.33329 Another sample execution (if you are using Java) may be: java ProbabilityEstimation THT HTH Or if you are using POSIX threads may be: ./ProbabilityEstimation THT HTH The expected result will look like: Estimated values with 1000000 random experiments with 10 threads: The probability that HTH appears first is 0.49998 The probability that THT appears first is 0.50002 a. Solve the given problem using Java multithreading. b. Solve the given problem using POSIX threads. NOTE: your solution may be tested with patterns of different lengths, for example HTT and TH, but it will not be tested with patterns where one is suffix of another for example HTT and TT, in order to avoid ambiguity (both patterns appearing in the same time)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions