Free Republic
Browse · Search
News/Activism
Topics · Post Article

To: ctdonath2
You have an input file with a random assortment of integers from the first one million integers. Design a program to write a file with these integers in order from smallest to largest using the fastest possible method. Assume your computer is a PC or Mac with typical resources.

We have been asking this question for over a decade, and so far only one applicant of hundreds has ever produced the correct algorithm.

Conclusion: either nobody reads Knuth in the CmpSci/CmpEng courses anymore, nobody teaches it, programmers have awful memories, or most coders are not very good.

25 posted on 12/22/2014 9:57:29 AM PST by FredZarguna (I'm gonna take this counter top, and I'm gonna whop you on that side of your face with it.)
[ Post Reply | Private Reply | To 4 | View Replies ]


To: FredZarguna
You have an input file with a random assortment of integers from the first one million integers. Design a program to write a file with these integers in order from smallest to largest using the fastest possible method. Assume your computer is a PC or Mac with typical resources.

Not everyone needs to solve problems like this, but if you do, recursion is one of the fastest ways to do it. At least that's how I'd tackle it.

45 posted on 12/22/2014 12:02:25 PM PST by JoeFromSidney (Book RESISTANCE TO TYRANNY, available from Amazon.)
[ Post Reply | Private Reply | To 25 | View Replies ]

To: FredZarguna

How big a list? I think I’d probably just go with a merge sort but as I’m a tester these days and haven’t written code in a good 6 years I’m probably forgetting something.


51 posted on 12/22/2014 12:54:49 PM PST by JenB
[ Post Reply | Private Reply | To 25 | View Replies ]

To: FredZarguna

I’ve used heapsort in the past. It is not as fast as quicksort, but it was easier to program quickly for me.

These days, I’d use the C++ STL list, and used the built-in sort() function...


54 posted on 12/22/2014 1:40:38 PM PST by kosciusko51 (Enough of "Who is John Galt?" Who is Patrick Henry?)
[ Post Reply | Private Reply | To 25 | View Replies ]

To: FredZarguna

Ah, I’ve re-read you first e-mail. I was thinking a generic algorithm.

If you are limited to the first 1 million numbers, you create an array of 1 million integers initialized to 0, and as you loop through the list, you increment the array at the location for that integer.

i.e, if the number is 1, you increment array item 1 (Fortran) or 0 (C/C++).

Once you have gone through the list, you loop through the array to determine the first in the list.

Correct?


57 posted on 12/22/2014 2:18:05 PM PST by kosciusko51 (Enough of "Who is John Galt?" Who is Patrick Henry?)
[ Post Reply | Private Reply | To 25 | View Replies ]

Free Republic
Browse · Search
News/Activism
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson