algorithm - Sort array in ascending order while minimizing "cost" -


I'm taking the next 22 hours (data structures) and I'm homework for a summer semester online post till now, I have not had any problem with assignment. Take a look at Assignment 4 below, and see if you can give me a hint about how to contact this. Please do not provide a complete algorithm, thanks only one approach!

A "costed sort" is an algorithm in which the sequence of values ​​should be arranged in ascending order. By doing the difference between the position of two values ​​at a time until the order is in the correct sequence. Each exchange has a cost, which is calculated as the calculation of the two values ​​included in the interchange. The total cost of the sort is the sum of the cost of the interchange. For example, suppose that the initial sequence was {3, 2, 1}. Interchange 1: {3, 1, 2} Interchange cost = 0 interchange 2: {1, 3, 2} Interchange cost = 4 interchange 3: a potential series of interchange:

 Given the total cost of {1, 2, 3} interchange = 5, 9  

You have to write a program that determines the minimum cost to arrange a specific sequence of numbers is. / P>

EDIT: Professor does not allow animals to be compelled.

If you have to be surprised your professor, you can use again, if you manage it , You might skip some courses :) Note that this algorithm will only give an approximate answer.

Otherwise: try the algorithm, or they both will find optimal answers.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -