Sometime ago , i have written a very simple C code for counting the number of inversion where the inversions are if i<j then a[i]>a[j]( Cormen exercise ). It uses merge sort methodology. I m attaching that code , so c if that can work by modifying the condition in merge function, i think it will work.

On 3/8/06, SPX2 <[EMAIL PROTECTED]> wrote:

about the 3rd problem such an algorithm could be.
where L1,L2 are as the limits are for quicksort(its a divide and
conquer method)
By bunchtype i mean a set.
v is the primordial bunch consisting of v1...vn cards(the big set)

T;//will be the solution

bunchtype evaluate(L1,L2)
{
if(L2=L1+1)
     if(corespond(vL2,vL1)=1)return  {{L2},{L1}}
     else return {L2,L1}
if(can_split_more)
      {bunch1=evaluate(L1,(L1+L2)/2);
       bunch2=evaluate([L1+L2)/2]+1,L2);
       V=V-(bunch1+bunch2)+recombine(bunch1,bunch2);
       //also here its essential to retain positions of elements
       //wich will be permuted through the alogirthm.
      }
}

now for recombine you have basically an interclassation of sets wich is
actually
a reunion.
this could be done linearly.
Anyway...i cant really remember quicksort very well...
maybe someone will look at this or better..propose a better solution http://ajay.mishra19.googlepages.com
IIT KGP
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Attachment: merge.c
Description: Binary data

Reply via email to