Re: Ranking Without Sorting
From: Richard Harter (cri_at_tiac.net)
Date: 07/26/04
- Next message: Richard Harter: "Re: Ranking Without Sorting"
- Previous message: Jussi Jumppanen: "ANN: Zeus Programmers Editor V3.93"
- In reply to: Ricardo Gibert: "Re: Ranking Without Sorting"
- Next in thread: Ricardo Gibert: "Re: Ranking Without Sorting"
- Reply: Ricardo Gibert: "Re: Ranking Without Sorting"
- Reply: Ian Woods: "Re: Ranking Without Sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jul 2004 18:42:49 GMT
On Mon, 26 Jul 2004 05:06:10 -0700, "Ricardo Gibert"
<nospamgibert@cox.net> wrote:
>
[snip code]
Congratulations, you have just reinvented the rank sort. Knuth
doesn't index it, although it may be buried somewhere in the problem
sets. It's mostly used in parallel processing AFAIK.
>You'll find that the outer 'i' loop condition has the same
>> pre- and post-conditions as insertion sort, and the inner 'j' loop does
>> the same operation as the insertion loop in insertion sort... albeit in a
>> slightly different manner.
>>
>> You have, to my mind at least, done an insertion sort on an array encoded
>> in a different manner to what 'normal' sorting does (the actual arrays).
>>
>> AFAICS, no matter what you do, no matter how you represent the sorted
>> data, you're almost certainly going to perform a sort. You might as well
>> pick a good sorting technique which easilly allows you to produce the
>> 'rank' array you want.
>>
>> Doing a 'heap sort', for example, where the heap holds the index into
>> your original array. When you're removing elements from the heap
>> (DeleteMin operation), put the indices into your rank array in the order
>> they come out. Running time? O(n log n).
>
>The indices point to the corresponding element in the original array. They are not the same as the rank information I'm after. To
>make this work, you must maintain a counter (initialized to zero) where its value is stored into the rank array just before
>incrementing it with each DeleteMin operation. The indices you wanted to store into the rank array actually get discarded one at a
>time with each DeleteMin operation.
>
>At no time during your adaptation of heap sort will the array actually get sorted, e.g. to find the i-th element of a[], you will
>need O(n) operations to find it in the rank array rather than O(1) operations if a[] were really sorted.
This is incorrect. (I'm not sure where your confusion is so bear with
me.) In Ian's scheme there are two auxillary arrays involved along
with the data array. Let the data array be a[], the array of indices
be x[], and the array of ranks be r[]. No data is moved in a[]. x[]
is an array of indices. During the heapsort it is rearranged so that
the successive indices in x[] correspond to a sort of a[]. Since a
heap sort produces the sorted elements one at a time, one can fill in
the rank array r[] one element at a time. The cost of filling in the
rank array is O(1) per item or O(n) total.
By the way, can you do something about the line lengths in your
posting? They are much too long.
Richard Harter, cri@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
Whoever said money can't buy happiness
didn't know where to shop.
- Next message: Richard Harter: "Re: Ranking Without Sorting"
- Previous message: Jussi Jumppanen: "ANN: Zeus Programmers Editor V3.93"
- In reply to: Ricardo Gibert: "Re: Ranking Without Sorting"
- Next in thread: Ricardo Gibert: "Re: Ranking Without Sorting"
- Reply: Ricardo Gibert: "Re: Ranking Without Sorting"
- Reply: Ian Woods: "Re: Ranking Without Sorting"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|