mergesort

Explaining merge sort using diagrams

三世轮回 提交于 2020-01-07 09:27:13
问题 I'm supposed to explain a merge sort using the list below. I would like to ask if I have done it correctly. Here is my_list = [ 78, 57, 62, 80, 47, 55, 93, 11, 84, 82] that was generated by python. No merge sort code is needed to explain for my assignment. I just need to explain merge sort in ascending order using the my_list given. Attached below is my explanation of merge sort using diagrams. Can I ask for room of improvements and whether I have done it correctly or not? The left part is

Why Merge sort is used for objects in Android/Java API?

和自甴很熟 提交于 2019-12-30 09:51:12
问题 In Java Arrays.sort() for primitive type uses quick sort. On the other hand Arrays.sort() for objects uses Merge sort. And, same goes for Collection.sort() which also uses Merge sort. Collections sort uses Arrays sort implementation underneath. So, in simple sense i can say that primitives are sorted using quick sort but objects are sorted using Merge sort. My guess is it has something to do with sorting algorithm it self. There are so many discussion on SO on Quick sort vs Merge sort, like

why is in place merge sort not stable?

梦想与她 提交于 2019-12-30 05:24:14
问题 The implementation below is stable as it used <= instead of < at line marked XXX. This also makes it more efficient. Is there any reason to use < and not <= at this line? /** class for In place MergeSort **/ class MergeSortAlgorithm extends SortAlgorithm { void sort(int a[], int lo0, int hi0) throws Exception { int lo = lo0; int hi = hi0; pause(lo, hi); if (lo >= hi) { return; } int mid = (lo + hi) / 2; /* * Partition the list into two lists and sort them recursively */ sort(a, lo, mid); sort

dynamically increasing java heap space

别等时光非礼了梦想. 提交于 2019-12-30 04:24:07
问题 I have written a java program that tests the speed of a couple of multi-threading algorithms on different machines with various numbers of processors. On some machines, merge sort* fails because it requires a sizable heap space to work on very large arrays. I can easily change the java heap space myself before running the program, but I feel like a more robust and easy approach would be to do this task from within the program itself. Is there a way to request/achieve more heap space from the

Why is merge sort worst case run time O (n log n)?

心已入冬 提交于 2019-12-29 10:13:10
问题 Can someone explain to me in simple English or an easy way to explain it? 回答1: On a "traditional" merge sort, each pass through the data doubles the size of the sorted subsections. After the first pass, the file will be sorted into sections of length two. After the second pass, length four. Then eight, sixteen, etc. up to the size of the file. It's necessary to keep doubling the size of the sorted sections until there's one section comprising the whole file. It will take lg(N) doublings of

Multithreaded quicksort or mergesort

与世无争的帅哥 提交于 2019-12-27 10:46:50
问题 How can I implement a concurrent quicksort or mergesort algorithm for Java? We've had issues on a 16-(virtual)-cores Mac where only one core (!) was working using the default Java sorting algo and it was, well, not good to see that very fine machine be completely underused. So we wrote our own (I wrote it) and we did indeed gain good speedups (I wrote a multithreaded quicksort and due to its partitioning nature it parallelize very well but I could have written a mergesort too)... But my

How to make a Worst case in mergesort in c? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 19:01:14
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . DataCount is how many times at sorting numbers. int* MakeMWData(int DataCount) { // make array int* Data = (int*)malloc(DataCount*sizeof(int)); int number = 2; int count = 0; Data[0] = 1; // input data int i,j; for( i = DataCount;; i/=2) { count++; for( j = 1; j<DataCount;j++) { //merge sort worst

Explanation of merge sort using diagrams

左心房为你撑大大i 提交于 2019-12-25 17:07:00
问题 I'm supposed to explain a merge sort using the list below. I would like to ask if i have done it correctly. Here is my_list = [ 78, 57, 62, 80, 47, 55, 93, 11, 84, 82] that was generated by python. No merge sort code is needed to explain for my assignment. I just need to explain merge sort in ascending order using the my_list given. Attach below is my explanation of merge sort using diagrams. can i ask for room of improvements and whether i have done it correctly? The left part is the 1st

Problem with mergesort algorithm in C#

拥有回忆 提交于 2019-12-25 04:45:15
问题 this code should work like merge sort algorithm but it doesnt work and gives the output 0 instead of sorting numbers,whats the problem friends?thanks private void button3_Click(object sender, EventArgs e) { string[] source = textBox1.Text.Split(','); string[] source1 = textBox3.Text.Split(','); int[] nums2 = new int[8]; int[] nums = new int[source.Length]; for (int i = 0; i < source.Length; i++) { nums[i] = Convert.ToInt32(source[i]); } int[] nums1 = new int[source1.Length]; for (int j = 0; j

What is the time complexity of a k-way merge?

流过昼夜 提交于 2019-12-25 00:30:30
问题 I'm trying to understand the time complexity of a k-way merge using a heap, and although there is a plethora of literature available on it, I can't find one that breaks down the analysis such that I can understand. This Wikipedia article claims that "In an O(k) preprocessing step the heap is created using the standard heapify procedure". However, heap insertion is O(log(n)) and find-min is O(1) . We start by inserting the first elements of each array into the heap. This takes ∑log(i) time, i