Questions tagged [mergesort]

For code that implements a merge sort or a significant part of it

Filter by
Sorted by
Tagged with
0 votes
3 answers
73 views

another Merge Sort

I've tried to implement merge sort in c with varying degrees of success, one was correctly sorting the array but leaking memory, one was neither sorting the array and leaking memory. The following was ...
Voiceroy's user avatar
  • 103
2 votes
1 answer
74 views

Implementing an improved merge sort that uses insertion sort, with "levels" - Would this work correctly?

We were asked to improve the merge sort algorithm by introducing insertion sort to the code. We have been tasked with doing this by utilising a "levels" logic. Here is the exact description ...
Preatorius's user avatar
1 vote
1 answer
113 views

Queue-mergesort: a mergesort that does optimal number of comparisons in the worst case in Java

Here is the code for queue-mergesort by Mordecai J. Golin and Robert Sedgewick: com.github.coderodde.util.QueueMergesort.java: ...
coderodde's user avatar
  • 28.2k
12 votes
4 answers
2k views

Recursive merge sort in C

Here's my first program in C, which is not my first language. I have been reading Modern C and I attempted this challenge on page 26. The prior pages are pretty much the only exposure I have had to C, ...
user14464173's user avatar
2 votes
1 answer
58 views

Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity

The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
Thomas Mathew's user avatar
3 votes
0 answers
98 views

Destructive quick and merge sort

I've implemented a destructive merge and quick sort in common lisp, but the code feels verbose and highly imperative. I was wondering if anyone could offer guidance on idioms that could make the code ...
bfair's user avatar
  • 131
3 votes
2 answers
236 views

C++ merge sort, logging, unit test, performance check

I wrote a merge sort implementation in C++ today in C++20 way. ...
frozenca's user avatar
  • 1,703
2 votes
3 answers
382 views

Adjusting heaps efficiently

Introduction and context I am working on a small application which involves sorting 20GB files as one of the operations. This is being done, due to memory constraints, by breaking them into ~1GB ...
Oliver Schönrock's user avatar
9 votes
3 answers
1k views

C++ merge sort implementation (looking for advice)

I am trying to practice C++, so I decided to implement canonical algorithms in C++ as a way to learn best practices and idioms of the language. I started with merge sort. How could I improve this ...
nickhealy's user avatar
  • 155
3 votes
1 answer
125 views

Optimize mergesort algorithm

I just started Stanford Coursera algorithms course and I wrote this mergesort based on what was shown: ...
Aayush's user avatar
  • 61
1 vote
2 answers
159 views

Bottom-up merge sort

I think I programmed a bottom-up merge sort, but I'm a little sceptical that it will work under any data set. By now, I've tested it with many random arrays of massive lengths, and it seems to work; ...
Krokodil's user avatar
  • 113
3 votes
1 answer
98 views

IOSP Kata: merge two sorted arrays without iterators

I wrote the code below as a Kata to practice the Integration Operation Segregation Principle (IOSP, clean-code-developers.com). I would like to have some feedback ...
Turing85's user avatar
  • 137
1 vote
2 answers
95 views

Comparison of 2 different ways of writing Merge Sort Algorithm

I have recently learned Merge Sort algorithm in C++ with 2 ways of writing it. 1st Way: ...
DivijM's user avatar
  • 11
1 vote
1 answer
244 views

Find Kth Element in the merged two sorted arrays?

We have been given two sorted arrays and a number K . We have to merge the two sorted arrays in the sorted manner and return the element at the Kth position. My approach is to use two variables ...
Aryaman 's user avatar
1 vote
3 answers
542 views

Parallezing merge step and divide step in mergesort algorithm with OpenMP

We wrote a code that parallelizes the divide phase of the mergesort algorithm. I.e. every recursive call is assigned to a thread but our teacher was disappointed because he said we should also ...
New2Math's user avatar
  • 111
3 votes
4 answers
2k views

Multi-threaded merge sort

Below is the code for merge sort using multithreading. Will this code run for large number of inputs? Does any other part of the code need changing? ...
Zebra's user avatar
  • 31
5 votes
1 answer
92 views

Merge Sort implementation is messy

I am using this merge sort function to sort table rows by Date, Letter, and Number. It works, but it is super messy and hard for others to read. The dates are being sorted in two formats YYYY-MM-DD ...
Gunnarhawk's user avatar
3 votes
3 answers
83 views

Trying for an efficient and readable merge-sort implementation

My first implementation of merge sort in C++. I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately....
mastmartelli's user avatar
2 votes
2 answers
93 views

Merge Sort for Linked List Criticism in C

I previously implemented a Merge Sort for arrays, so after fixing up my code for the array-based merge sort I have now implemented a merge sort for a basic singly-linked list data structure which only ...
Reggad's user avatar
  • 419
11 votes
6 answers
4k views

Mergesort Criticism in C

I have written a merge sort in C and would like any advice on how to improve it. Any advice helps to make the code better! ...
Reggad's user avatar
  • 419
2 votes
3 answers
447 views

A Merge Sort implementation for efficiency

This is my version of mergesort. ...
theProgrammer's user avatar
5 votes
1 answer
203 views

External sorting with async read and write

I wrote this code for a home task, and received some negative feedback. Though I really appreciated the reviewer, but I disagree when he said I use auto disorderly, ...
Canh's user avatar
  • 51
1 vote
0 answers
89 views

Sorting Algorithm using Modified Merge sort

I've been messing around with merge sort. Instead of doing a recursive division of the array I chose to keep keep track of the middle index of every three numbers. Using the index of the middle number,...
EL_H4CK0's user avatar
4 votes
1 answer
3k views

Hybrid Merge/Insertion sort algorithm

Explanation: Although merge sort runs in Ω(nlgn) and insertion sort runs in Ω(n^2), the constant factors in insertion sort can make it faster in implementation for small problem sizes. This sorting ...
erwoods89's user avatar
13 votes
3 answers
2k views

Python3 - merge sort, O(n) space efficiency

Any critique of my implementation of Merge sort would be much appreciated! I tested it using a driver function (shown below), and everything works. However, it still feels unwieldy, I am a beginner ...
Joseph Gutstadt's user avatar
3 votes
1 answer
105 views

Mergesort in python

My mergesort implementation currently takes a very long time, for a list with 1 million elements it takes over 130 seconds to get the list sorted. Could someone kindly have a look at my code and ...
Nishil Patel's user avatar
3 votes
2 answers
121 views

Mergesort (using vectors) and some questions about memory

Back from a long C++ hiatus. I thought to implement mergesort from memory, using containers and not based on CLRS's pseudocode and arrays. The compiles and runs ok on the test cases. ...
Minh Tran's user avatar
  • 285
3 votes
2 answers
126 views

HybridSort of QuickSort and MergeSort

I'll try to publish a paper about the programming language I've made (ArithmeticExpressionCompiler, short AEC) in Osječki Matematički List and, in order to demonstrate its usability for implementing ...
FlatAssembler's user avatar
1 vote
1 answer
188 views

Merge Sort Visualisation JS [closed]

...
keemahs's user avatar
  • 129
5 votes
1 answer
96 views

How to merge two descending singly linkedlist into one ascending linkedlist using Recursion without any helper method?

Here is my solution: I want to know if my solution fits the requirement 100%? Or if there is any better solution? Constraint of the question: must be singly linkedlist must use recursion, and no ...
Ziyu Zhong's user avatar
2 votes
1 answer
2k views

Merge Sort using vector c++

I'm learning c++ and I know some algorithms and data structures. I was wondering what is the best way to do merge sort for a vector in c++. ...
Ibrahima Barry's user avatar
4 votes
1 answer
168 views

CLRS implementation (opportunity to sort subarray) of merge sort in golang

I'm reading "Introduction to Algorithms" by CLRS and I can't find an implementation of the pseudo code from the book in golang. By the original implementation I mean that we deal with extra parameters ...
maxim-glyzin's user avatar
4 votes
2 answers
226 views

Merge Sort in C

I implemented mergesort in C as an exercise. I have two main questions: Is the code future-proof? 2.1 Will I have problems modifying it to sort float and double? 2.2 What could be problematic for ...
Miha's user avatar
  • 53
2 votes
1 answer
51 views

Return union and complement of three sets

I would be especially happy to hear opinions about complement_union. The rest of the code is just there to test the output. ...
mcocdawc's user avatar
  • 944
4 votes
3 answers
449 views

C++ Merge Sort Algorithm

I have created this first-timer implementation of Merge Sort and I got confused by the C++ syntax once or twice. So I have some questions about this code: ...
TVSuchty's user avatar
  • 595
2 votes
1 answer
391 views

Parallel MergeSort in C++

I've tried to implement parallel MergeSort in C++, that also tracks how many comparisons it's made and how many threads it uses: ...
FlatAssembler's user avatar
0 votes
1 answer
545 views

Memory efficient way to merge multiple Pandas DataFrames [closed]

I am trying to merge multiple pandas data-frames that I read from a file. Here is the function I wrote: ...
Medhat's user avatar
  • 123
4 votes
0 answers
260 views

Rust Iterative and Recursive Merge Sort Implementation

I'm in the process of learning both Rust and algorithms after primarily focusing on web development. As such I've had a go at implementing merge sort both iteratively and recursively. I've looked for ...
Naaman's user avatar
  • 71
4 votes
3 answers
638 views

Merge Sort in Java with Test cases

I've become a bit rusty in Java. This is an attempt at brushing up my skills. In computer science, merge sort is an efficient, general-purpose, comparison-based sorting algorithm. Questions How ...
JaDogg's user avatar
  • 4,531
6 votes
5 answers
438 views

Implemented command-line based merge-sort algorithm. How can I make the code efficient, robust, maintainable, secure?

This is follow up question regarding merge-sort implementation to the previous post. Recently I have implemented a command-line argument based merge-sort sorting algorithm. Format for command-line-...
strikersps's user avatar
2 votes
2 answers
359 views

Recursive Mergesort using goroutines

When learning a new language, one of my first tasks I like to go through is writing a few different sorting algorithms in that language to help familiarize myself with the syntax and see if there are ...
c4llmeco4ch's user avatar
2 votes
2 answers
140 views

Merge sort implementation in python 3

I have implemented a Merge sort in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
Brijesh Kalkani's user avatar
4 votes
1 answer
271 views

Merge Sort from Scratch in Python

I built a merge sort in python just to have a more thorough understanding of how the algorithm works. What I have written works fine, but I assume there is room for improvement and ways to make my ...
eric's user avatar
  • 143
3 votes
1 answer
475 views

Iterative Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Here, our ...
Emma's user avatar
  • 3,517
3 votes
1 answer
1k views

Recursive Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Just for ...
Emma's user avatar
  • 3,517
1 vote
2 answers
159 views

Merge k sorted lists in Java

I hava a question similiar with mege in Python but I am trying to write Java code. Here is my code: The input is: The first line - a number of arrays (k); Each next line - the first number is the ...
A user's user avatar
  • 53
4 votes
1 answer
181 views

LeetCode: Merge k sorted lists C#

https://leetcode.com/problems/merge-k-sorted-lists/ Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. ...
Gilad's user avatar
  • 5,321
5 votes
4 answers
552 views

MergeSort in Javascript

I implemented the following mergesort algorithm in JavaScript, but I want to know your opinion about if is possible to do better than this. ...
Es-Loop's user avatar
  • 71
1 vote
0 answers
65 views

Vector of numbers where merge sort is slow

I'm starting to study sorting algorithms in Python. Merge Sort has a complexity at best and worst cases \$\mathcal{O}(n\log{}n)\$, I want generation a list where Merge Sort is slow but I would some ...
veronica's user avatar
5 votes
4 answers
336 views

C-based hash matching cracker

How can I improve this hash matching program using either abstraction or search/sort algorithms? We briefly were introduced to searching methods such as bubble sort and merge sort, but I'm not sure ...
stiction's user avatar

1
2 3 4 5 6