mergesort

Parallel Merge Sort [closed]

a 夏天 提交于 2019-12-06 16:27:37
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . I searched in Google: "parallel merge sort" and found algorithm where "odd/even merge" is base component, but did not understand how to use it. Can you give me links to an implementation or pseudo code of

Merge Sort Implementation Check

不问归期 提交于 2019-12-06 16:25:36
问题 I am doubtful of my implementation of the merge sort for two cases specifically: 1. If the size of the list is 2 , then i have swapped the values if they are not in the ascending order else i have returned them. 2. In the merge function when the list tries to check outside the number of elements in it , I have assigned the greatest number(9999), so that in case of comparison with it always comes false. Can anyone tell me if the implementation of my merge sort is correct or not? As in sorting

Using Mergesort to calculate number of inversions in C++

拥有回忆 提交于 2019-12-06 16:04:38
void MergeSort(int A[], int n, int B[], int C[]) { if(n > 1) { Copy(A,0,floor(n/2),B,0,floor(n/2)); Copy(A,floor(n/2),n-1,C,0,floor(n/2)-1); MergeSort(B,floor(n/2),B,C); MergeSort(C,floor(n/2),B,C); Merge(A,B,0,floor(n/2),C,0,floor(n/2)-1); } }; void Copy(int A[], int startIndexA, int endIndexA, int B[], int startIndexB, int endIndexB) { while(startIndexA < endIndexA && startIndexB < endIndexB) { B[startIndexB]=A[startIndexA]; startIndexA++; startIndexB++; } }; void Merge(int A[], int B[],int leftp, int rightp, int C[], int leftq, int rightq) //Here each sub array (B and C) have both left and

Choosing minimum length k of array for merge sort where use of insertion sort to sort the subarrays is more optimal than standard merge sort

我怕爱的太早我们不能终老 提交于 2019-12-06 15:17:44
This is a question from Introduction to Algorithms By Cormen. But this isn't a homework problem instead self-study. There is an array of length n . Consider a modification to merge sort in which n/k sublists each of length k are sorted using insertion sort and then merged using merging mechanism, where k is a value to be determined. The relationship between n and k isn't known. The length of array is n . k sublists of n/k means n * (n/k) equals n elements of the array. Hence k is simply a limit at which the splitting of array for use with merge-sort is stopped and instead insertion-sort is

Merge Sort in R

心已入冬 提交于 2019-12-06 12:00:17
问题 I am self studying the book "Introduction to Algorithms" by Cormen et alli. In their book, they use pseudo-code which assumes that arrays are passed by pointer (by reference). This is different from R (where objects are passed by value), so I am having some difficulties trying to translate their pseudo-code as close as possible, especially when recursion is involved. Most of the time, I have to implement things a lot differently. For example, with the Merge Sort algorithm, they define the

recurrence relation on a Merge Sort algorithm

流过昼夜 提交于 2019-12-06 10:34:15
The question is : UNBALANCED MERGE SORT is a sorting algorithm, which is a modified version of the standard MERGE SORT algorithm. The only difference is that instead of dividing the input into 2 equal parts in each stage, we divide it into two unequal parts – the first 2/5 of the input, and the other 3/5. a. Write the recurrence relation for the worst case time complexity of the UNBALANCED MERGE SORT algorithm. b. What is the worst case time complexity of the UNBALANCEDMERGESORT algorithm? Solve the recurrence relation from the previous section. So i'm thinkin the recurrence relation is : T(n)

mergeSort implementation to find number of inversions not working when trying to read from a file

让人想犯罪 __ 提交于 2019-12-06 10:08:05
Im trying to do a mergesort implementation to find the number of inversions. . The array seems to return the right results for a small list of numbers that are hard coded, but returns an incorrect number when I read from a file. I guess its something to do with string- integer comparison, but cant figure out what exactly the issue is, . Any insight would be helpful.Here's the (relevant) code- public class ReadFile { public static void main(String args[]){ int count=0; int n[]; int i=0; try{ n=OpenFile(); int num[] = new int[n.length]; for (i=0;i<n.length;i++){ num[i]=n[i]; // System.out

Mergesort Swaps and Comparisons

若如初见. 提交于 2019-12-06 09:02:30
I'm currently working on an analysis project where I'm observing how different algorithms behave when implemented in Java. I got some code which implements a Mergesort algorithm from online, now I need to run this code on an array of 10,000 randomly generated integers (between 1 and 100,000) and record how many swaps and comparisons were made. I'm not exactly sure at which point in the code to increment the variables that count Swaps and Comparisons. What would the expected value be? Since best, worst, and average case for Mergesort are all nlog(n) does this mean I should expect 10,000*(log

Merge sort implementation

不羁岁月 提交于 2019-12-06 08:14:04
问题 I am new to c++ and was trying develop a code for merge sort. I tested it with a sample array of size 5 but the answer put out by the code is not right. I can't figure what's going wrong. Here is my code: #include <iostream> #include <cstring> #include <sstream> #include <fstream> #include <iomanip> using namespace std; void merge(int, int, int, int*); void merge_sort(int low, int high, int* p){ int pivot; static int i(1); if (high>low) { cout << "calling merge_sort: "<<i<<endl; i++; pivot =

Multi-threading sorting algorithms

隐身守侯 提交于 2019-12-06 06:53:02
问题 I have to implement a multi threaded Merge Sort and Quick sort in Java for my algorithms class and compare them to my single threaded versions. However, I have never multithreaded before. Is the code I have able to be multi threaded or do I have to start again? Here is my code for the single thread algorithms Merge Sort. the sort() method is part of the strategy pattern I have to implement. @Override public int[] sort(int[] list) { int array_size = list.length; list = msort(list, 0, array