/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q10E Counting heads. Given integers聽... [FREE SOLUTION] | 91影视

91影视

Counting heads. Given integersn and k, along with p1,...,pn[0,1], you want to determine the probability of obtaining exactly heads when biased coins are tossed independently at random, where pi is the probability that the ith coin comes up heads. Give an 0(n2)algorithm for this task. Assume you can multiply and add two numbers in [0,1]in 0(1)time.

Short Answer

Expert verified

It is given in that we have 鈥n 鈥 biased coins that are tossed independently, i.e., no mutual exclusion and tossing of one coin have no effect on result of other coin.

Also, ithcoin will produce head, with probability pi.

Step by step solution

01

Subproblem

Let us consider that n-1 coins are already tossed together and nth coin is toss separately.

Now let P1...n,k is the probability of getting exactly 鈥k鈥 heads when 鈥n 鈥 coins are tossed.

Now applying our consideration, we will define a storing table n*kand fill the various probability.

Thus there are two ways of getting exactly 鈥k 鈥 heads with 鈥n 鈥 coins:

  • If n-1coins have kheads and nth coin show tail.
  • If n-1coins have k-1heads and nth coin is head.

According to the above two cases, we can define our subproblem as:

P(n,k)=P(n-1,k)*(1-pn)+P(n-1,k-1)*p[n]

02

Analysing the recursion equation

If we are tossing first icoins, where jis the number of heads,

And L(i,j) as total probability of getting head,

localid="1657267432115" L(i,j)={Pi*Li-1,j-1+1-pi*Li-1,j;forj=0,1..i0;forj0

On solving this recursion equation, the time complexity will be 0nk.

This is because our algorithm will run for 鈥n鈥 coins but will stop if it gets k heads. So we will be using first loop for to toss each coin which would be 鈥n鈥 and then second loop will check for head in the tossed coin.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91影视!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

The garage sale problem (courtesy of Professor Lofti Zadeh). On a given Sunday morning, there are n garage sales going on, g1,g2,g3............gn. For each garage sale gj, you have an estimate of its value to you, vj. For any two garage sales you have an estimate of the transportation cost dijof getting from gito gj. You are also given the costs d0jand dj0of going between your home and each garage sale. You want to find a tour of a subset of the given garage sales, starting and ending at home, that maximizes your total benefit minus your total transportation costs. Give an algorithm that solves this problem in time O(n22n).

(Hint: This is closely related to the traveling salesman problem.)

A mission-critical production system has n stages that have to be performed sequentially; stage i is performed by machine Mi. Each machine Mi has a probability riof functioning reliably and a probability 1-riof failing (and the failures are independent). Therefore, if we implement each stage with a single machine, the probability that the whole system works is r1r2rn. To improve this probability we add redundancy, by having mi copies of the machine Mi that performs stage i. The probability that all mi copies fail simultaneously is only (1-ri)mi,so the probability that stage i is completed correctly is 1 鈭 (1-ri)mi, and the probability that the whole system works isni=1(1-1-rimi).Each machine has a cost ci, and there is a total budget to buy machines. (Assume that B and ciare positive integers.) Given the probabilities r1r2rn, the costsc1,...,cn, and the budget find the redundanciesm1,...,mn that are within the available budget and that maximize the probability that the system works correctly.

Yuckdonald鈥檚 is considering opening a series of restaurant along Quaint Valley Highway(QVH). The n possible locations are along a straight line, and the distances of these locations from the start of QVH are, in miles and in increasing order,m1,m22,....,mn.. The constraints are as follows:

At each location, Yuckdonald may open at most one restaurant. The expected profit from opening a restaurant at location i is given aspi, wherepi>0andi=1,2,,n.

Any two restaurants should be at least k miles apart, where k is a positive integer.

Give an efficient algorithm to compute the maximum expected total profit subject to the given constraints.

Consider the following 3-PARTITION problem. Given integersa1,...,an, we want to determine whether it is possible to partition of {1,...,n} into three disjoint subsets I,J,Ksuch that

aiiI=ajjJ=akkk=13aii1 .

For example, for input(1,2,3,4,4,5,8) the answer is yes, because there is the partition(1,8),(4,5),(2,3,4). On the other hand, for input(2,2,3,5) the answer is no. Devise and analyze a dynamic programming algorithm3-PARTITION for that runs in time polynomial in n and in iai.

Exon chaining.Each gene corresponds to a subregion of the overall genome (the DNA sequence); however, part of this region might be 鈥渏unk DNA.鈥 Frequently, a gene consists of several pieces called exons, which are separated by junk fragments called introns. This complicates the process of identifying genes in a newly sequenced genome.

Suppose we have a new DNA sequence and we want to check whether a certain gene (a string) is present in it. Because we cannot hope that the gene will be a contiguous subsequence, we look for partial matches鈥攆ragments of the DNA that are also present in the gene (actually, even these partial matches will be approximate, not perfect). We then attempt to assemble these fragments.

Let x 1Kndenote the DNA sequence. Each partial match can be represented by a triple li,ri,wi, where xliKriis the fragment and is a weight

representing the strength of the match (it might be a local alignment score or some other statistical quantity). Many of these potential matches could be false, so the goal is to find a subset of the triples that are consistent (nonoverlapping) and have a maximum total weight.

Show how to do this efficiently.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.