Questions tagged [mergesort]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
383 views

Merge sort in Python

I've written a implementation of a merge sort in Python. It seems correct and I have tested it with this: ...
6
votes
2answers
1k views

Merge Sorting Lists

I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I'm looking for your suggestions to improve this code in the following areas: Correctness - are there ...
5
votes
1answer
892 views

Merge sort in Golang

I am just starting out with golang. I implemented the merge sort algorithm just to practice. Any suggestions or criticisms regarding the coding style? ...
4
votes
2answers
199 views

External bottom up merge sort too slow

My external sort function works but it is way too slow. I think the bottleneck is the merge function. How can I make it faster. Is there a better merge function I can use for merging into a file using ...
12
votes
4answers
41k views

Merge Sort an integer array

I've implemented merge sort an integer array. Is it okay to use i,j,k as variable name for looping? Should I change them to more meaningful names? Overall, any further suggestions on this code? ...
3
votes
3answers
967 views

Merge sort efficiency

I've written this Java code to implement merge sort: ...
6
votes
2answers
10k views

Merge sorting linked lists

This works as expected and I want to get this code reviewed so that I can improve my coding ability. I am concerned about readability and the quality of the code ...
5
votes
3answers
2k views

Merge Sort Implementation in Java (that seems slow…)

I decided to write my own implementation of merge sort. Here is the code: ...
10
votes
1answer
904 views

File-based fixed-record merge sort

A problem posted here to Code Review prompted me to experiment with a general-purpose merge-sort algorithm for any fixed-length record data. External / File-based mergesort I answered that question, ...
7
votes
2answers
7k views

External / File-based mergesort

I've implemented an external mergesort to sort a file consisting of Java int primitives, however it is horribly slow (fortunately it does at least work). Very little happens in the sort method: it ...
7
votes
2answers
2k views

Merge sort in JavaScript

I implemented this merge sort in JS and noticed that for random integer numbers it's a lot faster than the build in sort functions of all the browsers I tested (Chrome, FF, IE). Does anyone have an ...
6
votes
3answers
227 views

Merge Sort implementation in Java

Can you check my merge sort implementation? From all of my testing it seems like it works, but I just wanted to make sure I am doing it as good as possible, and it couldn't be optimized any further. ...
2
votes
3answers
564 views

Merge sort algorithm written in Python

...
4
votes
2answers
633 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? ...
6
votes
1answer
10k 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
341 views

Algorithm for finding inversions in Merge Sort

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

Merge Sort Java Implementation

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

Count array inversions merge sort

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

Merge Sorting in Python

This my implementation of the Merge Sorting Algorithm: ...
2
votes
2answers
2k 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 faster (...
8
votes
3answers
23k 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 ...
4
votes
2answers
2k 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 Python ...
2
votes
2answers
205 views

MergeSort w/ Custom Functions

Please review my implementation of mergesort: ...
4
votes
3answers
20k 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
540 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
154 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
1k 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
842 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
217 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
518 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
1k 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
452 views

Is this merge sort code good enough?

...
8
votes
5answers
19k 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
3k 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: ...
5
votes
1answer
291 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
966 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
3k views

Merge two sorted arrays together

Please review my answer for this interview question: ...
1
vote
1answer
307 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 ...
5
votes
1answer
13k 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: ...
5
votes
3answers
8k 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
5k views

Merge sort with a linked list

I'd like this code reviewed. ...
6
votes
1answer
309 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
1k 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. I'...
1
vote
1answer
975 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
1k views

Mergesort implementation in Clojure

...
8
votes
1answer
4k views

Merge sort in Scala

I've implemented merge sort in Scala: ...
4
votes
3answers
220 views

Mergesort with an inversion counter

I'm new to Lisp and I'm yet to wrap my head around the lisp way of writing programs. Any comments regarding approach, style, missed opportunities appreciated: In particular, please advice if I build ...
5
votes
2answers
995 views

ANSI C Mergesort

This is a working mergesort implementation I wrote as I'm 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 ...
8
votes
4answers
3k 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
757 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? <...