Thread: Mergesort bottom-up

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Mergesort bottom-up

    [SOLVED]
    Hi,
    I have a question about merge sort bottom up.

    Let's take the array:
    13, 7, 4, 10, 3, 5

    My first step would be to compare each 2 following integers:
    13, 7, 4, 10, 3, 5
    7, 13, 4, 10, 3, 5
    7, 13, 4, 10, 3, 5
    7, 13, 4, 10, 3, 5

    My second step would be to compare each 4 following integers:
    7, 13, 4, 10, 3, 5
    4, 7, 10, 13, 3, 5

    This is where I'm stuck, how can I get the last 2 integers compared?


    Thx in advance!
    Last edited by christopheva; 04-26-2009 at 11:56 AM.

  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Why not just compare the first four with the last two?
    I think there is no need for both the left and the right arrays to be of equal length
    for a comparison to take place.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by christopheva View Post
    Hi,
    I have a question about merge sort bottom up.
    I would say: do not consider mergesort from the bottom up. If you think you're going to hit on some undiscovered optimization, you're not. So there is no point in trying to think of it that way, it will not make it any easier for you.

    Once you can code a mergesort start to finish, you can decide if I am wrong...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    Quote Originally Posted by stevesmithx View Post
    Why not just compare the first four with the last two?
    I think there is no need for both the left and the right arrays to be of equal length
    for a comparison to take place.
    You are correct. Stupid that I didn't see it my self...

    Quote Originally Posted by MK27 View Post
    I would say: do not consider mergesort from the bottom up. If you think you're going to hit on some undiscovered optimization, you're not. So there is no point in trying to think of it that way, it will not make it any easier for you.

    Once you can code a mergesort start to finish, you can decide if I am wrong...
    I know, I was just wondering :-).

    Thx for the replies!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make opengl draw in lighter colors ?
    By jabka in forum Game Programming
    Replies: 2
    Last Post: 12-17-2007, 06:12 AM
  2. Natural Mergesort
    By wuzzo87 in forum C Programming
    Replies: 31
    Last Post: 04-14-2007, 09:41 PM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  5. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 07:01 PM