Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

merge sort

  • 01-05-2006 6:41pm
    #1
    Closed Accounts Posts: 839 ✭✭✭


    can someone explain how a merge sort works, has anyone any examples?


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    There's a very good explanation here with Java source.


  • Closed Accounts Posts: 839 ✭✭✭zap


    ok i get say that you have

    an array 1 5 6 7 8 9

    so that gets split into

    1 5 6 and 7 8 9


    where do i go after that?

    1 5 6 splits into

    1 5 6

    then


    1


    is that correct


  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    Basically you code it as a recursive function

    sort(array) {
    if (arraylength = 1) return

    sort(1st half)
    sort(2nd half)
    merge(1st half, 2nd half)
    }

    Each 1/2 gets fired back into the 'sort' algorithm, you keep splitting in half and merging until each half only has one element in it.

    You don;t actualy write a 'sort' the only thing that matters is the merge, which basically has 2 ordered lists and has to make one ordered list from both parts. There are a number of ways of writing the merge more efficiently.


  • Registered Users, Registered Users 2 Posts: 1,821 ✭✭✭Skud


    http://math.hws.edu/TMCM/java/xSortLab/

    This should help you out. Explains the visual worikings of some common sort algorithms


Advertisement