Questions tagged [sorting]

Use this tag when arranging items in order is the main focus of the code.

53 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
389 views

Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
Neil's user avatar
  • 1,050
7 votes
0 answers
120 views

Stable variation of built-in sort

Ruby's built-in sorts are unstable. The stable_sort gem monkey-patches Ruby's built-in library to have stable sorts which include nearly all the functionality of the built-in sorts, but with the ...
Wayne Conrad's user avatar
  • 3,274
6 votes
0 answers
256 views

Selection sort with reduced comparison count: Python iteration 2

Follow up to Selection sort with reduced comparison count - semi-final Iteration? My goal (and excuse not to tag reinventing…) is to have presentable code to argue the viability of reducing the number ...
greybeard's user avatar
  • 6,416
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
0 answers
111 views

Sorted LinkedList

A linked list is a data structure that has a beginning, and an end. The only way through the structure is to go to the "next step", like stepping stones. This linked list works the same way, but in ...
KGlasier's user avatar
  • 141
4 votes
0 answers
1k views

Selection sort implementation in C++ iterator approach

I am trying to learn the C++ way of writing code. I was wondering if this code could be improved or if there are any major mistakes. Is it ok how I name the variables? ...
puls99's user avatar
  • 323
4 votes
0 answers
111 views

Comb Sort Multi-dimensional Array on Key

Previously: Comb Sort in VBA I've been running two different comb sorts (on arrays) depending on whether I want to sort numbers or strings and I figured I would give using ...
Raystafarian's user avatar
  • 7,139
4 votes
0 answers
250 views

Heap sort in Rust

The tests are taken from this answer on an insertion sort in rust question. The algorithm is taken from Algorithms in a Nutshell (2nd Edition). I'm not looking at crazy performance, the goal being ...
little-dude's user avatar
4 votes
0 answers
2k views

Integer tree sort in Java

I have this algorithm for sorting integer arrays. Basically, it's a balanced tree sort which creates a tree node for each distinct integer, and in each tree node it maintains a counter counting how ...
coderodde's user avatar
  • 28.2k
4 votes
0 answers
313 views

Quick Insert Merge Sort

I have written this code to sort a list of numbers, in increasing order. It is a combination of quick sort, insertion sort, and merge sort. I make the first element of the list a pivot, then I go ...
Rajesh Bhat's user avatar
3 votes
1 answer
86 views

Sorting songs with the ability to save and resume partial sorts

I listen to a lot of music (~4k h/y) and managing thousands of songs is a bit of a challenging. To improve my listening experience I want to better organize my collection. One thing I want to do is ...
Peilonrayz's user avatar
  • 43.3k
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
0 answers
285 views

I recently wrote sort of structs in golang

I am a bit concerned about style (functions, variable names, spacings, etc.). I am also not sure about whether I should return error or panic. What do you think? ...
Ignatij's user avatar
  • 31
3 votes
0 answers
122 views

Breadth First Search Block Puzzle

I am creating a program that will be given a text file as output with the board's dimension and the piece id along with the piece width and length. The goal is to arrange all blocks in the board ...
Mperez's user avatar
  • 39
3 votes
0 answers
93 views

DataManager Class: Sorts Array by 1 or More Dynamically Added Columns in Ascending or Descending Order

I've been struggling to write a QuickSort algorithm to sort multiple columns of an Array for weeks. Finally, I decided to write a class that Implements mscorlib.IComparer and it has exceeded my ...
TinMan's user avatar
  • 4,133
3 votes
0 answers
6k views

Bubble sort using user inputted numbers and size in MIPS assembly

I made this code to take user input, making a specific-sized array and printing user-inputted numbers after being sorted. It works well but I was wondering if there was a way to "shrink" it down. It ...
user162757's user avatar
3 votes
0 answers
156 views

Shakesort in Python 3

I've done the shakesort algorithm win \$O(N^2)\$ but it doesn't seem that \$O(N^2)\$ is correct because it takes 6-9 steps in the while loop for a list of 4 ...
raviolican's user avatar
3 votes
0 answers
52 views

Sorting upcoming events listed in JSON

I've written my first program in GO, a command line tool that parses JSON containing events from a file or from STDIN and outputs the upcoming events in sorted order. Please critique it! ...
Rohan Shah's user avatar
3 votes
0 answers
82 views

Adaptive counting sort for integer arrays in Java - follow-up

I have refactored this. Once again, the running time can be anything between \$\Omega(n)\$ and \$\mathcal{O}(n^2)\$, yet it adapts to "smoothness" of the input array. ...
coderodde's user avatar
  • 28.2k
3 votes
0 answers
726 views

Parallel Merge Sort in Scala

I have been trying to implement parallel merge sort in Scala. My current implementation is about as fast as .sorted, but I have no idea what would be the right ...
warbaque's user avatar
  • 261
3 votes
0 answers
1k views

Nuts and bolts algorithm

I am trying to learn Golang. This is a problem from Robert Sedgewick's Algorithms book: You have a mixed pile of N nuts and N bolts and need to quickly find the corresponding pairs of nuts ...
coder_bro's user avatar
  • 419
2 votes
0 answers
84 views

In place dynamic array sorting without using extra memory

I seek critique on a sorting implementation for a dynamic array data-structure. Design decisions Uses the quicksort algorithm. Uses an optimized XOR swap for swapping the elements. XOR swap doesn't ...
Julius's user avatar
  • 171
2 votes
0 answers
107 views

Sort items so that parents are created before their children

I've been asked to create some code to help automate the loading of data into a system based on employee data in a spreadsheet. However, the data isn't clean, so some people may have no manager, some ...
JohnLBevan's user avatar
  • 1,409
2 votes
0 answers
385 views

Sorting Algorithm (from scratch) in Python

Updated (at the bottom) I am attempting to write a Python program where I have to create a sorting algorithm without the assistance of the built-ins (like the sort()...
seoul_007's user avatar
  • 434
2 votes
0 answers
81 views

Python's quicksort algorithm

I was playing around with sorting methods, brushing up on my algorithms. I have made the following implementation of quicksort: ...
revliscano's user avatar
2 votes
0 answers
63 views

Construction of external sorts from comparison ones

Here's an example how to construct an external sorting algorithm from the Quicksort. The method may be applicable to other known internal comparison sort algorithms. I have checked that it shows N*...
Skrabák Csaba's user avatar
2 votes
0 answers
216 views

Vanilla Javascript code to sort nested tables

I have written a code to sort a main table containing tables in each of its rows. Here I am trying to sort the table by first sorting the rows in each of the main rows and then sorting the table from ...
Lax_Sam's user avatar
  • 211
2 votes
0 answers
105 views

Generate automatically new groups in a tournament

I'm trying to model a tournament with Python (Django) and I've got a function that assigns teams of the previous stage to the groups of the new one. The teams in the first stage are assigned manually....
Lorenzo Fiamingo's user avatar
2 votes
0 answers
80 views

Sort ascending/descending functionally

I've been trying to get into functional programming with javascript and have tried to make some experiments with currying and function composition. What I've played with so far is a sorter function ...
As above so below's user avatar
2 votes
0 answers
426 views

React widget to display, sort and search remote data

I've created a React widget that pulls data on crypto-token pairs from a remote API and makes that data sortable by headers and searchable. You can view a demo of it here. Is this a maintainable way ...
J.McLaren's user avatar
  • 121
2 votes
0 answers
78 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 ...
Michael D's user avatar
2 votes
0 answers
2k views

Visualization of sorting algorithms

I recently started to learn Qt framework and decided to create an app to visualize the sorting algorithms(for this moment there are 5 sorting algorithms). I just want to know if I'm doing everything ...
letelete's user avatar
2 votes
0 answers
249 views

Comparing speed of common sorting algorithms in an extensible way

I have written a program with the goal of comparing the speed of some common sorting algorithms. It works with many data types. ...
esote's user avatar
  • 3,770
2 votes
0 answers
162 views

Insertion sort slower than bubble sort

...
Tobi's user avatar
  • 241
2 votes
0 answers
367 views

Follow-up 1: Compare 2 unordered, rooted trees for shape-isomorphism

The previous post can be found here. In the previous post I tried to solve an exercise but found through the answer of Peilonrayz a bug in the code and 2 more while fixing it. These have now been ...
Philipp Doerner's user avatar
2 votes
0 answers
122 views

Sorting overlapping shells in dynamical simulation - for loops vs array methods

I didn't know whether it was best to start with the general task I'm trying to solve, or the meat of the programming problem. They're both below but the former is rather long and solving the latter ...
zephyr's user avatar
  • 143
2 votes
0 answers
128 views

Z sorting implementation for a 2D isometric game

This is a naive implementation of a Z-sorting in order to fake 3D depth using sprites in a 2D scene. I would appreciate feedback on this, especially for performance as this has to be called each frame ...
Stud's user avatar
  • 786
2 votes
0 answers
402 views

Shell Sort code

I have a working shell sort code. I had already written a code for insertion sort, which I have used as underlying algorithm for doing shell sort on sub lists. So if you pass value of ...
Amit.rk3's user avatar
  • 121
2 votes
0 answers
135 views

Guidance on grouping equal sets of numbers, so each group has a similar average

Goal: I am trying to build teams of 5 people. Each person has an integer elo (rank). My goal is to make all the teams as equal/fair as possible, by having the average elo of each team be as close as ...
Austin's user avatar
  • 121
2 votes
0 answers
213 views

Can this heap sort be further optimized to have fewer comparisons?

...
Joseph Nields's user avatar
1 vote
0 answers
14 views

Determine top t values with few calls to order(), a given procedure to order k values, Java take 2

My 2nd take of the problem in Determine top t values with few calls to order(), a given procedure to order k values: Given an array and a procedure to order \$k\$ ...
greybeard's user avatar
  • 6,416
1 vote
0 answers
138 views

Making This "Fancy" Sort Algorithm a Little Better

This is my code: ...
Jacob Hornbeck's user avatar
1 vote
0 answers
2k views

PowerShell - Sort strings containing numbers numerically

I am a newbie in programming, but I do have potential, I am using PowerShell to hone my skills, I have written a simple function to sort strings consisted of numbers humanly (i.e. in a order like 1 2 ...
Ξένη Γήινος's user avatar
1 vote
0 answers
88 views

Python Bubble sort

...
Leonard's user avatar
  • 131
1 vote
0 answers
1k views

Median of three partitioning taking more time than standard quicksort in java

I implemented a standard quicksort and I have a project where I need to improve it. I am trying to make quicksort faster by implementing median of 3 partitioning. I copied codes from trusted ...
teddy's user avatar
  • 11
1 vote
0 answers
64 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 ...
Tambah's user avatar
  • 11
1 vote
0 answers
1k views

Sorting cards by suit and value using Shell Sort

The question description: put a deck of cards in order by suit (in the order spades, heart, clubs, diamonds) and by rank within each suit, with the restriction that the card must be laid out face down ...
Lerner Zhang's user avatar
1 vote
0 answers
970 views

Applies the Largest Remainder Method to a number property in a list of objects

I need to round BigDecimal numbers according to the Largest Remainder Method (LRM). Please reference this SO post with this answer. Here's my version of the algorithm in Java: ...
James's user avatar
  • 299
1 vote
0 answers
750 views

Sorting directed graph topological using Kahn's algorithm

For a course I'm doing I need to get up to speed with Java, but unfortunately only Java 1.6 - here is a topological sorting algorithm in said Java version, for practice reasons: ...
BMBM's user avatar
  • 412
1 vote
0 answers
689 views

Compute the minimum distance between two points in a 2-D plane

I have tried to calculate the minimum distance between the two points in a 2D plane. I have used the divide and conquer strategy to attain the complexity of n logn. ...
Suhail Gupta's user avatar