Computers and Technology

Given n ropes of different lengths, we need to connect these ropes into one rope. We can connect only 2 ropes at a time. The cost required to connect 2 ropes is equal to sum of their lengths. The length of this connected rope is also equal to the sum of their lengths. This process is repeated until n ropes are connected into a single rope.
Find the min possible cost required to connect all ropes.
For example: Suppose you have three ropes with lengths 2, 5, and 8. If you chose first to connect the length 5 and 8 ropes, then connect the length 2 and 13 ropes, the total cost would be (5 + 8) + (13 + 2) = 28. However, if you first chose to connect the length 2 and 5 ropes, then the length 7 and 8 ropes, the total cost would be (2 + 5) + (7 + 8) = 22 (which happens to be optimal).

(a) Specify with pseudo-code a greedy algorithm to connect the ropes with minimum cost.
(b) Prove your algorithm always finds the least cost solution if the lengths of the ropes are distinct.
(c) Analyze your algorithm's complexity.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:30, kivking12
The blank is type of decision-maker who over analyzes information
Answers: 3
image
Computers and Technology, 22.06.2019 05:00, 105001964
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system. in); is given.
Answers: 3
image
Computers and Technology, 22.06.2019 08:30, ruddymorales1123
Linda subscribes to a cloud service. the service provider hosts the cloud infrastructure and delivers computing resources over the internet. what cloud model is linda using
Answers: 1
image
Computers and Technology, 23.06.2019 07:00, sugaree95
What are three software programs for mobile computing?
Answers: 1
Do you know the correct answer?
Given n ropes of different lengths, we need to connect these ropes into one rope. We can connect onl...

Questions in other subjects:

Konu
History, 25.05.2021 05:20