Merge sort is an O(n log n) comparison-based sorting algorithm.

learn more… | top users | synonyms

0
votes
0answers
38 views

Is my implementation of a merge sort correct?

I tried to get into programming several times but never did and never got very far past "Hello, World.", until recently when I found and read (most of, still don't get parts of it) "The Little ...
3
votes
2answers
64 views

Implementation of merge sort and bubble sort

I'm new to Go and looking for a review of my merge sort and bubble sort implementations. What can be done better? Can my code be cleaner/clearer? ...
4
votes
1answer
46 views

Counting inversions

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion ...
6
votes
1answer
55 views

Algorithm for finding inversions in Merge Sort

Please help in code reviews for readability, optimizing it, functionality etc. ...
2
votes
2answers
66 views

Merge Sort Java Implementation

Can someone check my Merge Sort implementation on Java? Is it good/bad and can it be improved further? ...
4
votes
1answer
49 views

Count array inversions merge sort

How does it look? Comments, code correctness, etc. ...
3
votes
3answers
90 views

Merge Sorting in Python

This my implementation of the Merge Sorting Algorithm: ...
1
vote
2answers
84 views

Merge sort algorithm implementation using C++ (redux)

This is a follow up question to the one I asked a couple of days ago. I reviewed the suggestions & did some research (specifically, read relevant info on CLRS). The new version is 3 times ...
6
votes
2answers
289 views

Merge sort algorithm implementation using C++

I'm trying to learn proper C++ and algorithms at the same time. I particularly feel weird about my iterators usage in merge function. Is this a good way to handle ...
3
votes
2answers
63 views

How might we make this Python Merge Sort implementation more Pythonic?

I've implemented a (version of) Merge Sort algorithm in Python. My goal here is two-fold: Improve understanding of Merge Sort and recursion in a language agnostic way. Improve understanding of ...
2
votes
2answers
48 views

MergeSort w/ Custom Functions

Please review my implementation of mergesort: ...
2
votes
3answers
82 views

Implementing the merge sort with only arrays, out of place

This has been asked a few times here, but I was wondering what I could do to improve the efficiency and readability of my code. My programming skill has gotten rusty, so I would like to elicit all ...
2
votes
1answer
108 views

Merge Sort optimization

I was looking at other people code and I realized that mine is not so neat after all. In this version, I included a base case for the merge part (when there is only 2 elements to merge, just sort it ...
3
votes
1answer
55 views

Is there a better way to return values with merge sort?

I have been attempting to learn Scala lately and so have produced a couple of different sorting algorithms to build up my basics. I think I have been lucky with the methods returning exactly what I ...
5
votes
2answers
116 views

Racing Java Arrays.sort with NON recursive Merge Sort implementation

I found a bit better implementation for Java Arrays.sort(int[]). To make this code review more simple I divide this questions to several parts. The goal of this ...
6
votes
2answers
97 views

Generic Multiway Merge

Recently I had a problem (not in C++) that required merging a number of sorted lists of values. This is effectively the generalised case of merging together two sorted lists. However, instead of ...
6
votes
1answer
95 views

Merge sort could work 10 times faster

I am implementing merge sort in Java and I have a performance problem in this method: ...
7
votes
4answers
193 views

MergeSort performance

Do you see any inefficient parts with the following code? On internet I see 30 ms for 100.000 integers but I can sort 100.000 integers in 300ms. The data is random. I am using late 2013 macbook pro so ...
3
votes
1answer
159 views

Is there anything to improve in this MergeSort code in Java?

I have written an implementation of the merge sort algorithm in Java. Here is the MergeSort class that I created. ...
5
votes
1answer
146 views
4
votes
3answers
2k views

Merge Sort Algorithm in Python

I'm implementing basic sorting algorithms to learn them, and coding, better. Criticisms and possible optimizations welcome. ...
7
votes
2answers
319 views

Is this non-recursive mergesort efficient and a good way to simulate the recursive version?

My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are: ...
4
votes
1answer
88 views

Is this an efficient merge sort implementation with regards to average time complexity in Big-O notation?

Is my below merge sort implementation in O(n log n)? I am trying to implement a solution to find k-th largest element in a given integer list with duplicates with O(N*log(N)) average time complexity ...
1
vote
1answer
129 views

Merge Sort Program

I have written the following program to implement merge sort in F#. Can you please review this and let me know how can I write this in the most functional way (also most efficient and concise)? In ...
4
votes
2answers
213 views

Merge two sorted arrays together

Please review my answer for this interview question: ...
0
votes
1answer
154 views

MergeSort implementation with java.util.List passed as argument, not returned

I'm working on an implementation of MergeSort which sorts a List given as an argument. As follows ...
3
votes
1answer
7k views

Merge Sort in C++

I've written this code for a merge sort, which is meant to implement the pseudo-code from Cormen's Introduction to Algorithms: ...
2
votes
2answers
521 views

Merge Sort Implementation

Any reviews/ways to speed up/general improvements for my Merge Sort? Maybe something to simplify it or add more to it? ...
1
vote
1answer
2k views

Merge sort with a linked list

I'd like this code reviewed. ...
3
votes
1answer
116 views

Recursive Implementation of merge sort

Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented merge sort in C. The algorithm is structured as a ...
6
votes
2answers
272 views

Merge Sort: exercise

I've decided to learn Haskell by following the current Coursera algorithms course using Haskell to implement the algorithms discussed. First up is merge sort, which I've implemented as shown here. ...
1
vote
1answer
190 views

Debug merge sort and validate comparison counters

I am posting the code for my merge sort to see if I can get folks offer suggestions as to where to make comparisons or if I am making the correctly already. I will post my heap sort and quick sorts ...
3
votes
2answers
348 views
6
votes
3answers
902 views

Merge sort in Scala

I've implemented merge sort in Scala: ...
4
votes
2answers
355 views

ANSI C Mergesort - Pedantic criticism please

This is a mergesort implementation I wrote, trying to get back into C. I am not so much interested in feedback on the optimality of the algorithm (as I could read up countless articles i'm sure), but ...
8
votes
4answers
731 views

Given two sorted arrays, add the elements of the second array into the first

In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following: Given two sorted arrays, A and B. Write a method merging the elements ...
7
votes
3answers
296 views

Is this attempt at a merge sort correct?

I am trying to write a merge sort algorithm. I can't tell if this is actually a canonical merge sort. If I knew how to calculate the runtime I would give that a go. Does anyone have any pointers? ...
1
vote
1answer
417 views

Am I doing this right? Merging 2 ordered source arrays into one destination array

My instructions were: Add a merge() method to the OrdArray class in the orderedArray.java program (Listing 2.4) so that you can merge two ordered source arrays into an ordered destination ...
5
votes
2answers
3k views
5
votes
0answers
573 views

Merge sort in Scheme

...
1
vote
0answers
170 views

F# mergesort code : where to improve

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? ...
4
votes
2answers
1k views

Merge sort on an Integer class

This is a specific case in merge sort. I'm trying to do a merge sort on an array that's created using the Java Integer class. My implementation is slow and ...
10
votes
2answers
2k views

Parallel Merge Sort

Parallism is achieved by using a simple call to tbb::parallel_invoke(). However I can't break a speedup factor of x2 (after ~3-4 parallel HW threads), although 8 ...
6
votes
1answer
388 views

Merge sort and selection sort comparison taking too long

I have this python code that compares merge sort and selection sort, but it is taking "forever." ...