1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Comp Sci Problem

  1. Jan 27, 2005 #1
    Let's say you want to write an algorithm for MergeSort given the following:
    Code (Text):
     public void(int[]a, int n1, int m, int n2)
    I know the algorithm:

    1. If array has 1 element dont don anything
    2. Split array in two halves
    3. Sort the first half and the second half
    4. Merge both halves into one.

    Any help is appreciated :smile:
  2. jcsd
  3. Jan 27, 2005 #2


    User Avatar
    Homework Helper

    The tough part of this problem is number 4. I'd suggest working on this part first... assuming you have an array (whose length can be anything >=2) that has the top half sorted, and the bottom half sorted, write an algorithm that merges the two. You want to make this as efficient as possible. You want to take advantage of the fact that the top and bottom are each sorted. Compared to this part, the rest is easy.

    Mergesort is a neat application of recursion.
  4. Jan 28, 2005 #3
    I remember downlopading java gives a lot of free soring examples. why not chekc it out ?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Comp Sci Problem
  1. Comp Sci Questions (Replies: 3)

  2. Comp science hw help (Replies: 6)