Question: A certain string processing language allows the programmer to break a string into two pieces. It costs n units of time to break a string
A certain string processing language allows the programmer to break a string into two pieces. It costs n units of time to break a string of n dharacters into two pieces, since this involves copying the old string. A programmer wants to breaka string into many pieces, and the order in which the breaks are made can affect the total amount of time used. For example, suppose we wish to break a 20-character string after characters 3,8, and 10. If the breaks are made in left-right order, then the first brenk costs 20 units of time, the second break costs 17 units of time, and the third break costs 12 units of time, for a total of 49 steps. If the breaks are made in right-left order, the first break costs 20 units of time, the second break costs 10 units of time, and the third break costs 8 units of time, for a total of only 38 steps. Give a dynamic programming algorithm that takes a list of character positions afer which to break and determines the cheapest break cost in O(n2) time. In your solution to this problem, it is suggested that you let S ss. , be the original string of length n, and let 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
