Hi,

All right, so first of all, this is not my homework, not a homework at all, I don't want any of you to solve it for me. I am just preparing for a programming competition, and there is this one I can't solve, and I would like some hint.

So the problem is that there are books in a library and I have to put them in order. But I have to find the the best way (definetely not the fastest!) to sort it.

So I have these numbers:

7, 10, 1, 3, 2, 8, 4, 9, 6, 5

I have to put them in order. I tried quicksort, but of course thats the fastest but not the best. Bubble sort is out as well, it has to do many steps.

So I have an answer, which is 7 (the count of the steps I have to do to sort it), but I can't find a way to figure out how to do it...

(I didn't know what tags to write, so since I try to write it in C# I just put that one there)

Thank you

That reminds me of a job I applied for back in 2002. Among other things they asked me to submit an example of "a function to sort a list of numbers" in the language of my choice -- no other requirements. What sort of list? An array? On the command line? What?

At the time I was just learning C# and considered just using List.Sort but decided against that as it wasn't a C# job. After giving it some thought I decided to read the list from the command line and use a function I had written in C a few years earlier that added integers to an array in a sorted fashion. (I didn't get the job.)

You could also consider using a binary tree. :shrug:

For instance buble sort swaps numbers based on one of the values being bigger than the other, but iterates through the whole array.

Is a swap already a step, or is a full sweep of the array a step ?

Array.sort doesn't return that to me. (and I think it does it in the fastest way, not the most efficient, im not sure though)

Which is the whole point. Binary search is good enough if the numbers are being input one at a time, and the list is kept sorted in the process of inputting additional numbers and inserting them in the array or whatever containment you use.

Look at it this way. You have a friend, a librarian. He asked you to find a way how he could sort his books numbered from 1 to 10. (above) You have to tell him how many steps he has to do to sort them. :)

So what is the result of quicksort ? That one is one of the quickest I know of. Mind you I never implement sorting myself, because of all the libraries that are there.

There are other ways to sort a list that likewise require no swaps.

By the way, you are right. But that's not the case. :)

Here's another way -- put the 7 at the end, then put the 10 at the end, etc. -- I count five steps this way (for this set of data).

I have two methods that sort that list with five "steps".