Write the algorithm that puts the first four terms of a list of arbitrary length in increasing order. Show that this algorithm has time complexity O(1) in terms of number of comparisons used.

Thanks!

Printable View

- March 16th 2010, 09:39 AMLCopper2010algorithms
Write the algorithm that puts the first four terms of a list of arbitrary length in increasing order. Show that this algorithm has time complexity O(1) in terms of number of comparisons used.

Thanks! - March 16th 2010, 03:22 PMemakarov
Well, if you are given four apples and you have glasses that allow you seeing at most two apples at a time, are you able to arrange them in increasing order? If yes, then write your sequence of actions in a programming language you are using. Also, try to figure out the maximum number of comparisons you need to make to do the job.

- March 16th 2010, 03:25 PMCaptainBlack
This is exactly the same as sorting into ascending order a list of length .

So how would you do this?

Now if is the length of our arbitrary list and is the time to put the first four terms in order this time is obviously independent of the length of the full list. Which is exactly what it means for it to have time complexity , that is the time is independent of the length of the full list.

CB