/*! 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} Q9E A certain string-processing lang... [FREE SOLUTION] | 91影视

91影视

A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the first cut at position 3 incurs a total cost of 20+17=37, while doing position first has a better cost of 20+17=37.

Give a dynamic programming algorithm that, given the locations of m cuts in a string of length , finds the minimum cost of breaking the string into m +1 pieces.

Short Answer

Expert verified

It is given in the question, that the primitive operation will take 0n time for copying the original string of length 鈥n鈥. Hence, the cost of complete algorithm will be greater then 0n.

To get minimum cost of breaking the string, we will use dynamic programming algorithm and define our recursion relation which will be our subproblem.

Step by step solution

01

Defining the Subproblem

Let us suppose that we have input string 鈥S鈥 of length 鈥n鈥. Then, also let 鈥i鈥 denote the position of cut. Thusi=1,2.....m.

So, if m cuts are made, that means we havesubstrings.

So, let atmade the cut on our original string

So, we got two substrings: S1....iandSi+1...n . But stillm-1cut is to be made. Now, two cases will arise:

  • Ifm-1remaining cut is made in substringS1....i
  • Ifm-1remaining cut is made in substringSi+1...n

In any one of the above two case, there must be minimum cost.

Let x0,x2,....xm+1be the position(index) where we have to make cut. Here, x1=0and xm=n.

Let Li,jdenotes the minimum cost to cut the string, and i=0...mand j=1....m+1.

These strings will start from xiand ends to xj.

So our recursive equation will be:

L(i,j)={0;forj=i+1xj-xi+mini<k<jLi,k,Lk+1,j;forj>i+1

02

Analysing the recursive equation

The above recursive relation will run for 0n2And it is already mention in the question that we use primitive operation to store each string. And taking our string of length 鈥n鈥, our effective time complexity will be0n3.

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

Give an O(nt) algorithm for the following task. Input: A list of n positive integers a1,a2,...,an; a positive integer t. Question: Does some subset of the ai鈥檚 add up to t? (You can use each ai at most once.) (Hint: Look at subproblems of the form 鈥渄oes a subset of{a1,a2,...,ai} add up to ?鈥)

Suppose two teams, A and B, are playing a match to see who is the first to win games (for some particular n). We can suppose that A and B are equally competent, so each has a 50% chance of winning any particular game. Suppose they have already played i+j games, of which A has won i and B has won j. Give an efficient algorithm to compute the probability that A will go on to win the match. For example, if i=n-1 and j=n-3 then the probability that A will win the match is 78, since it must win any of the next three games.

Alignment with gap penalties. The alignment algorithm of Exercise 6.26 helps to identify DNA sequences that are close to one another. The discrepancies between these closely matched sequences are often caused by errors in DNA replication. However, a closer look at the biological replication process reveals that the scoring function we considered earlier has a qualitative problem: nature often inserts or removes entire substrings of nucleotides (creating long gaps), rather than editing just one position at a time. Therefore, the penalty for a gap of length 10 should not be 10 times the penalty for a gap of length 1, but something significantly smaller.

Repeat Exercise 6.26, but this time use a modified scoring function in which the penalty for a gap of length k is c0 + c1k, where c0 and c1 are given constants (and c0 is larger than c1).

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.

Given an unlimited supply of coins of denominations, we wish to make change for a value ; that is, we wish to find a set of coins whose total value is . This might not be possible: for instance, if the denominations are and 10 then we can make change for 15 but not for 12. Give an dynamic-programming algorithm for the following problem.Input:,; .Question: Is it possible to make change for using coins of denominations ?

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.