Computers and Technology

A string operation breaks a string into two pieces, which costs n time units for a string of n characters. When a string is broken into many pieces, the order in which the breaks occur can affect the total amount of time used. For example, to break a 20-character string after characters 2, 8, and 10 (numbering the characters in ascending order from the left-hand end, starting from 1). If the breaks to occur in left-to-right order, then the first break costs 20 time units, the second break costs 18 time units (breaking the string from characters 3 to 20 at character 8), and the third break costs 12 time units, totaling 50 time units. If the breaks to occur in right-to-left order, however, then the first break costs 20 time units, the second break costs 10 time units, and the third break costs 8 time units, totaling 38 time units. In yet another order, the first break is at 8 (costing 20), then the 2nd break is at 2 (costing 8), and finally the third break is at 10 (costing 12), for a total cost of 40. Given a string S with n characters and an array L[1..m] containing the break points in ascending order): (1) Formulate the recursive relation of the optimal solution; (2) Design a bottom-up algorithm to calculate the lowest cost for a sequence of breaks; (3) Analyze the complexity of your algorithm; (4) Write an algorithm to print out a sequence of breaks that achieves this cost.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, alyssatamayo641
Speed is how fast an object moves a certain distance within a length of time. how is speed calculated? a) distance/time b) time/distance c) velocity/time d) distance x time
Answers: 1
image
Computers and Technology, 22.06.2019 06:00, willowcollins3753
Write a program that uses a widgetviewer object to do the following: generate two random integers between 1 and 9 (inclusive). name one of them x, the other y. display them to the user using jlabel objects. create a jlabel object displaying the text "enter an operation number." create a jtextfield for the user's input. create a jbutton displaying the text "press here when you've entered your operation." use addandwait to add it to the widgetviewer object. when the user clicks the jbutton, evaluate operation in the following order to determine the one and only mathematical operation to perform on x and y. use a jlabel to display the result. if operation is between 1 and 10 inclusive, add x and y. if operation is evenly divisible by 4, subtract y from x. if operation is evenly divisible by 5, use integer division to divide y into x. if operation is an even number, use floating point division to divide y into x. if none of the other tests on operation apply, multiply x and y. note: operation can be negative or zero.
Answers: 2
image
Computers and Technology, 22.06.2019 06:40, EricaLSH7624
Match the personality traits with their description
Answers: 2
image
Computers and Technology, 22.06.2019 15:30, alexdub9649
What is a costume plot? why is it important to a film or theater production?
Answers: 2
Do you know the correct answer?
A string operation breaks a string into two pieces, which costs n time units for a string of n chara...

Questions in other subjects:

Konu
Mathematics, 28.08.2019 08:00
Konu
Chemistry, 28.08.2019 08:00
Konu
Mathematics, 28.08.2019 08:00