You must look at all the numbers, but I guess it could be done with a special xmm instruction that sorts its 32bit ints in a single clock cycle (hence O(1)) if the chip producers would consider it worthwile.
Your calculations for big O cost is incorrect for sorting 3 items in O(1). Please write a generic algorithm that will take any three numbers and sort them correctly in one operation without scanning all three of them.
Have another look at the problem. Obama is asked to sort a constant number of items (1,000,000). So if you want to call this constant “n”, then “n” is in this case 1,000,000. Hence bubblesort will run in O(1,000,000^2 / 2) which is in O(1), if you interpret the math correctly. Or look at it this way: can you not sort 3 items in O(1)? Why not 5 items then? What is the biggest constant number of items you can sort in O(1)?
I wouldn’t say I agree 100% regarding certain issues, but you’ve got an interesting point of view. Anyway, I like the quality you add to the blogosphere and that this isn’t just another abandoned, made-for-adsense blog! Take care…
It appears that you’ve put a good amount of effort into your article and I demand a lot more of these on the World Wide Web these days. I truly got a kick out of your post. I do not have a bunch to to say in reply, I only wanted to register to say phenomenal work.
You must look at all the numbers, but I guess it could be done with a special xmm instruction that sorts its 32bit ints in a single clock cycle (hence O(1)) if the chip producers would consider it worthwile.
Your calculations for big O cost is incorrect for sorting 3 items in O(1). Please write a generic algorithm that will take any three numbers and sort them correctly in one operation without scanning all three of them.
Have another look at the problem. Obama is asked to sort a constant number of items (1,000,000). So if you want to call this constant “n”, then “n” is in this case 1,000,000. Hence bubblesort will run in O(1,000,000^2 / 2) which is in O(1), if you interpret the math correctly. Or look at it this way: can you not sort 3 items in O(1)? Why not 5 items then? What is the biggest constant number of items you can sort in O(1)?
@ChristopherDone Exactly.
They obviously set him up with it before hand.
You don’t understand Big-O notation, do you? No biggie, but you should read up on it
Bubble sort is still most definitely O(n^2)
What. The. Fuck?
n….is a constant?!
To be extremely pedantic, any sorting algorithm for this problem would run in O(1), since n is a constant (1,000,000). And I love to pedantic ^ ^
depends on whether or not the data can be assumed to be mostly sorted, and whether or not the data is IO bound.
“bubblesort is the wrong way to go” is a more correct answer than “quicksort”
wow, pergunta pro lula agora HUASHUADHUASD
lolwarmhearted girl who is searching for a man who would be able to satisfy my needs
whose stupid idea is it to ask him this? u really expect him to be able to know? or ur just trying to embarass him?
Hmm, i find Obama quite shallow and pedantic, yes…
Quick! Google ‘God: hidden science’
That’s how I always do it!
Too bad my algorithms rarely finish during the lifetime of the universe.
I wouldn’t say I agree 100% regarding certain issues, but you’ve got an interesting point of view. Anyway, I like the quality you add to the blogosphere and that this isn’t just another abandoned, made-for-adsense blog! Take care…
CombSort – a slight modification of quicksort would do it as good as quicksort (O(n lg n )). Regardless… Thumbs up for Obama!
If it’s written in ztec code, a surface-slot sort would be faster than almost anything else.
tis
Randomized Quick Sort
Quick Sort!
so whats the answer to it ?
Luckysort is the most efficient way. It’s O(0) and also very easy to implement. It does require some luck though.
LOL Obama rocks!!
where da jobs is?
I think insertion sort can still pull through and win this thing.
It appears that you’ve put a good amount of effort into your article and I demand a lot more of these on the World Wide Web these days. I truly got a kick out of your post. I do not have a bunch to to say in reply, I only wanted to register to say phenomenal work.