CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    54

    Algorithm for two way MergeSort

    Hello

    I am tracing the algorithm for two way merge sort....This algorithm start with loop like
    Repeat for L=1,2,4,....2^[log2N]-1
    If log2 L is even
    then
    call mergesort

    I can't understand value of L start with 1 then 2 then directly 4? what is increment in L and what is exit condition for For loop? and inside the If condition if L=1 then log2=0.3010 . Now 0.3010*l or anything else?
    Can anyone explain?
    Last edited by CSharpque; April 20th, 2012 at 10:11 AM.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Algorithm for two way MergeSort

    You seem to get stuck a lot trying to solve these sorts of problems. I think you need to have a more 'intuitive' understanding of how the algorithm works before you start looking at pseudocode.

    So, to facilitate that, in your own words WITHOUT USING ANY PSEUDOCODE OR MATH, explain what the merge sort algorithm does. How would you sort, say, 32 assignments students turned in by last name using mergesort?

    So explain that (post a reply) and THEN see if the pseudocode makes more sense. If not, more help will be forthcoming. :-)
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jan 2012
    Posts
    54

    Re: Algorithm for two way MergeSort

    i am giving sort example like if i have numbers to be sort like
    42 23 74 11 65 58 94 36 99 87
    First i will sort first two elements, then 3 and 4 then 5 and 6 then 7 and 8 and at last 9 and 10
    23 42 11 74 58 65 36 94 87 99
    Noe i will sort first 4 elements then second four and at last only two elements put as it is bcos it is already in sorted order
    11 23 42 74 36 58 65 94 87 99
    now i will sort first 8 elements then last two which is already sorted
    11 23 36 42 58 65 74 94 87 99
    Noe combine and sort first 8 and last 2
    11 23 36 42 58 65 74 87 94 99

    Now array is in sorted order....
    M i right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured