how i can to implement (Balanced Merge Sort) algorithm?

轻俞倾 卺磉?

Hello for all

I want to make Balanced Merge Sort algorithm in my project ,but i face

many problems as,

I can't make this algorithm

and , i don't know ,how i can to establish files to write and read from it ..

Example about this algorithm for members who don't know about BMS

suppose that ::

1-I have main File with name "data.txt" ,

2-I have template files ,F1,F2,F3,F4

2-this file includes these values

10,5,20,30,22,40,35,69,41,25,32,58,21,30,6,55,10,7,8,56,20,30,40,50

22,32,75,88,65,42,84,95,32,64,12,20

Question::

How i can select each time 4 values and put them in array ?

to understand my question please see heare::

first time ,i select (10,5,20,30) store values in array ,after that sort this array and put this sorted values in F1

second time , i select (22,40,35,69) store values in same array,after that sort this array and put this sorted values in F2

3ed tme , i select (41,25,32,58) store values in same array,after that sort this array and put this sorted values in F1

4ed time , i select (21,30,6,55) store values in same array,after that sort this array and put this sorted values in F2

and so on until finishing for all values

[1300 byte] By [balanceda] at [2007-10-2 7:17:32]
# 1
I think default Merge sort is always balanced.Look at the implementation of Arrays.sort(Object[]) - it's a good balanced merge sort I think.Gil
gilroittoa at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 2
Thanks gilroitto::can you give code to show how i can to create 4 files and JTextArea used to display the data from file to jTextArea
balanceda at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 3

> can you give code

These 4 words will always trig a massive repulsion of the forum members, who will always give you the same one answer: Try first, and then if you have more specific questions, post a question where you tell:

1. What you have done so far

2. Where you are stuck

3. Code you have so far

Gil

gilroittoa at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 4

> I think default Merge sort is always balanced.

> Look at the implementation of Arrays.sort(Object[]) -

> it's a good balanced merge sort I think.

Then you are thinking wrong and you should read the Javadoc instead. It says that Arrays.sort() is a quicksort. Nothing to do with merging, nothing to do with balanced merging, and nothing to do with the OP's problem.

The OP should look up balanced merging in e.g. Knuth vol 3 or Sedgewick's Algorithms in Java.

ejpa at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 5

> Then you are thinking wrong and you should read the

> Javadoc instead. It says that Arrays.sort() is a

> quicksort.

Different sorting algorithms are used.

public static void sort(Object[] a) is a modified mergesort

public static void sort(int[] a) is a tuned quicksort

prometheuzza at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 6
and neither of these is a balanced merge. Look it up.
ejpa at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 7
> and neither of these is a balanced merge. Look it up.I didn't say/mean that. But you stated that Arrays.sort() used quicksort. I simply said not all the sort() methods use the same algorithm.
prometheuzza at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...
# 8
You can use the code from here: http://www.mycsresource.net/articles/sorting_algos/mergesort.phpI'm using that one for my project, it's really fast.John
Johnathan77a at 2007-7-16 20:52:44 > top of Java-index,Other Topics,Algorithms...