Re: Detailed explanation of how a QuickSort Works



"Paul MH" <paulmorrishill@xxxxxxxxxxxxxx> wrote in message news:1175984924.860130.30740@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The reason i dont use code that i dont understand is that, lets say
im doing a project for a course and someone asks me to explain
what this does and i say "I dont know i didnt write it" that wouldnt
be very good.

I applaud your attiutude, but I think you perhaps missed the "it's only half a joke" phrase in my response. I do understand that in an academic environment you need to be able to show that you understand all of the code you write, but the point I was making is that "in the real world" people often use code that they don't really fully understand and they treat such code merely as a "black box" where all they really know is the output which is generated by any specific item of input. And even in the academic world you must often accept the simple fact of life that it is actually totally impossible for any one person to know everything. For example you might write some code to play an mp3 song, perhaps something like the following:

Static player1 As Object
Set player1 = New FilgraphManager
player1.RenderFile "c:\bad moon rising.mp3"
player1.Run

Most people (including myself) do not *really understand* the above code. All they really know is that if you use the RenderFile method of player1 on a valid mp3 file (or other valid media file) and then use the Run method then the song will play. But actually loading the data from the mp3 file from the disk and analyzing that data and decompressing it and arranging to stream it in a way that causes the song to be played through your speakers is a fairly complicated task, and almost all programmers will happily leave all that "knowledge" safely in the hands of the Player1 object (in the above code) and will treat it merely as a "black box" in the way I mentioned above. So, having accepted that it is simply not possible to know everything, many people sometimes take that a little step further and actually use certain sometimes very large blocks of VB code which they did not themselves write and which they do not themselves totally and fully understand, and they use them in their own programs on the same "black box" principle. They don't always do this of course, and they don't really like doing it, but they sometimes do it nonetheless. Otherwise, if they always allow themselves to be led down the path of making sure they fully and totally understand every single line of code they use, they will spend so much time on the project that they simply will not make any money out of it! And in the commercial world, making money is of course by far the most important thing! Once you step out into the commercial world you no longer have the luxury of the "ivory towers" way of looking at things. I suppose it is sad, in a way, but it is a fact of life. By the way, in order for the above code to work you will need to set a reference to the quartz.dll (the ActiveMovie Control type library).

thanks again this has really helped me. i did a search through my
hard drive for files, it found 91,144 files and order them by size in
about 4 seconds (these are arrays with types) whereas before the
same proccess would have taken over 40 minutes

You're welcome. By the way, when sorting a large number of strings (especially strings of varying lengths) you will find it very much quicker to modify your sort routine so that it sorts "Long pointers" to the strings rather than sorting the string data itself. This is generally referred to as an "Index Sort". It won't speed up your own drive searching code very much (because a lot of the time in that specific code is spent drilling through the file data on the disk or in the disk buffer and that time will still be required) but in general it can increase the speed of standard string sorts quite a lot.

Mike



.



Relevant Pages

  • Re: Getting the hex out of HexEdit
    ... I'd like to be able to scan my entire disk for certain text strings like ... The best thing for that sort of use is Sleuthkit + Autopsy. ...
    (uk.comp.sys.mac)
  • Re: Solution for sorting an array alpha-numerically
    ... strings up into groups and sorting the groups seperately, ... > so that numeric and alphabetic data sort as seperate groups. ... To the same project as the web page, add the class AlphaNumCompare() ...
    (microsoft.public.dotnet.general)
  • Re: a question for sorting keys in Map
    ... I have a Map, actually a TreeMap, which will automatically sort the keys ... You can write your own Comparator object which implements the Compare ... strings so that X10 comes after X2 instead of before it. ... Unix ls command sort file names the way you want your strings to sort. ...
    (comp.lang.java.programmer)
  • Re: fast stable sort
    ... Can you post C code for a stable in place mergesort function? ... How do you load a herd of strings into your ... diddles the pointers, not the strings. ... In this case the requirement is to sort the pointers in place ...
    (comp.programming)
  • One more "strlen" - was: Note to Chuck Crayne
    ... optimize strlen to shave one cycle off it, and you distribute your library to 1000 users, and they each write a program that uses strlen 1000 times, and distribute it to 1000 end-users, and they each run it ... We would of course only do strlen once per string, so we have to imagine we've got a lot of strings being thrown at us. ... When I click on the little hieroglyph to "sort by thread" instead of "sort by date", it takes - by wall clock - approximately a minute and fifteen seconds to complete. ... A better approach would be to keep a running index table for every column the user can sort by and every index table should be updated every time Thunderbird recieves an email/post...this way, the click on the glyph merrly selects which index table to use when picking what message headings to show in the window -- no need to run no freak'n algo. ...
    (alt.lang.asm)

Loading