# Questions tagged [mergesort]

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

273 questions
Filter by
Sorted by
Tagged with
63 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. ...
91 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 ...
44 views

...
71 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 ...
60 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++. ...
71 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 ...
82 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 ...
16 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. ...
112 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: ...
88 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: ...
62 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: ...
85 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 ...
218 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 ...
276 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-...
64 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 ...
90 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. ...
67 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 ...
227 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 ...
253 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 ...
118 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 ...
98 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. ...
195 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. ...
48 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 ...
212 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 ...
50 views

### What are the downsides of my Mergesort implementation?

Could I ask you to evaluate my implementation of mergesort? I think that it's consistent with $\mathcal{O}(n \log n)$ complexity but has a downside that I create a new ...
79 views

### Merge sorted lists

I want to write a function that merges two sorted lists in Python 3. For example: >> merge_lists([2, 5, 9], [1, 6, 8, 10]) [1, 2, 5, 6, 8, 9, 10] My ...
59 views

### Parallel merge sort with thread- and bufferpooling

I did wrote this parallel merge sort with no external dependencies. I tried to make use of modern C++ as much as possible. Can you please tell me how it is? ...
215 views

### Merge Sort C++11 C++17

Question Any way I can optimize this further using new C++11 or C++17 features? Would also like feedback on my variable naming, memory management, and style (notice my placement of ...
2k views

### C++ parallel merge sort

I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This ...
49 views

### Sorts (merge, quick, bubble) in Python

I'm new to python, and I wrote the following code. Please review, critique and enhance. This project compares quicksort, mergesort and bubblesort write/test the partition routine for quicksort. (20 ...
52 views

### Python merge sort for a list containing distinct values

This code below is what I think should be the implementation of merge sort in Python and it works as expected. It sorts the given list, where we can safely assume that all values are distinct. But ...
387 views

### External polyphase merge sort

For comparison with other external sorting algorithms, I have implemented external polyphase merge sort, purported to be useful to sort large files that do not fit into main memory. More theoretical ...
212 views

### Adaptive Merge Sort in C++

As the title says, I'm trying to implement a merge sort algorithm in C++ that's also adaptive. This is a personal exercise, and I don't have any specific application in mind. My main goal is to ...
382 views

### Linked-list natural merge sort in Python

I implemented the linked-list natural merge sort in Python, and I referred to this awesome if not poetic gist and this implementation in Go. Here is my code: ...
203 views

I wrote a MergeSort implementation of doubly linked list, based on the MergeSort implementation of array on the textbook Algorithms 4th, which is definitely $O(n \log n)$. I think my linked list ...
341 views

### Natural merge: mergesort that uses already sorted subarrays

The code bellow is my implementation for the natural merge exercise in Robert Sedgwick's Algorithms book: Write a version of bottom-up mergesort that takes advantage of order in the array by ...
80 views

### Merge sort implementation with various improvements

So I was working on merge sort today, and was trying to speed it up. I would like your opinion on the implementation and if it's possible to make it faster. Besides that I was wondering if there are ...
46 views

### Implementation of merge sort that takes sublinear extra space

I implemented an algorithm that takes only sublinear extra space as required in the exercise description: Develop a merge implementation that reduces the extra space requirement to max(M, N/M). (...
95 views

### Python merge sort

In Algorithms Fourth Edition by Robert Sedgewick and Kevin Wayne, the exercise 2.2.10 states that: Implement a version of merge() that copies the second half of a[] to aux[] in decreasing order ...
135 views

### Merge sort approach in Python

I'm working my way through a book on algorithms. One of the first challenges is the merge sort. I've seen this implemented before, but as the book suggested I coded one from just the method without ...
449 views

### How can I make my Merge Sort Code In C more secure, effective and efficient

I have been implementing the merge-sort algorithm for sorting the data for a long time, each time I use the following source code for implementation. By secure, I ...
1k views

### C++ code to sort a list of elements

This is a code uses mergesort algorithm to sort a list of elements.What are the possible improvements on the code?Also are there any unhealthy coding practice involved in this code? ...
432 views

### Merge sort Java implementation for an interview

I just learned Merge sort, and I really like this Merge sort implementation since it is very logical and very easy to follow. If I was asked in an interview to implement merge sort, will this ...
173 views

### Move friendly merge sort - follow-up

This is a follow up to this question. I'm only interested to see if this is implemented correctly for move-only types. ...
1k views

...
392 views

### Merge two sorted lists in Python

Merge two sorted lists ...
291 views

### Bottom up merge sort in Haskell

Although this sort works on Int lists < length million, when the stack overflows, the last clause of the merge function definition looks odd to me, recursing in 2 places. Is there clearer way to ...
69 views

### Mergesort in Python optimization

I am currently writing mergesort in Python and have implemented it to work. I have noticed, though, that it is very slow compared to the standard sorted() method. I understand it will always be faster ...