# Homework Help: Comp Sci Problem

1. Jan 27, 2005

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:

MergeSort
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

2. Jan 27, 2005

### learningphysics

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.

3. Jan 28, 2005

### Joeyluvluv

I remember downlopading java gives a lot of free soring examples. why not chekc it out ?