Question: 1 4 - 9 , Breaking a String ( awb variation ) A certain string - processing language allows a programmer to break a string
Breaking a String awb variation A certain stringprocessing language allows a programmer to break a
string into two pieces. Because this operation copies the string, it costs n time units to break a string of n characters
into two pieces. Suppose a programmer wants to break a string into many pieces. The order in which the breaks
occur can affect the total amount of time used. For example, suppose that the programmer wants to break a
character string after and numbering the characters in ascending order from the lefthand end, starting from
If she programs the breaks to occur in lefttoright order, then the first break costs time units, the second break
costs time units breaking the string from to at character and the third break costs time units, totaling
time units. If she programs the breaks to occur in righttoleft order, however, then the first break costs time
units, the second break costs time units, and the third break costs time units, totaling units. In yet another
order, she could break first at costing then break the left peice at costing and finally the right piece at
costing for a total cost of
a Show that this problem has optimal substructure.
b Recursively define the cost of an optimal solution.
c Design an algorithm that, given the numbers of characters after which to break, determines a leastcost way to
sequence those breaks. More formally, given a string S with n characters and an array Lm containing the
break points, compute the lowest cost for a sequence of breaks, along with a sequence of breaks that achieves
this cost. Pseudocode would be reasonable.
d Give the running time of your algorithm.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
