Sorting is the process of applying some order to a collection of items.

learn more… | top users | synonyms

8
votes
2answers
193 views

Efficiently create and sort a Collection

The goal of my code is to sort data into two categories. It must use a local copy of the initial data from Collar (Top View).csv. My code creates a Collection of items called Collars using the initial ...
3
votes
2answers
78 views

Merge Sort Implementation: Space Usage

I have made a merge sort algorithm but am unsure of the 'Space Usage' of the algorithm. ...
10
votes
7answers
986 views

Merge sort for a List<T>

Is this merge sort following good coding standards? What are some improvements I can make to make it cleaner? ...
4
votes
4answers
122 views

Quick Sort - implementation

Can anything be improved in this code? ...
4
votes
3answers
45 views

Displaying sorted results of a web crawl

The issue I have with this class is that most of the methods are almost the same. I would like for this code to be more pythonic. Note: I plan on replacing all the ...
1
vote
1answer
40 views

Collection of sorting types

A collection of sorting types as following insertion, radix, selection and heap sorts. Is my implementation correct for them? ...
33
votes
12answers
3k views

Efficiently squaring each element in a sorted array, keeping it sorted

The other day I was asked the following question during an interview: Given a sorted array, how would you square each element of this array, while keeping it sorted? I froze up and wrote a ...
0
votes
0answers
55 views

Recursive partition sort is inefficient

I have written a recursive method for a partition sort that sorts the array. However, when I use an array of more than 10-20 elements the program takes a really long time to complete. (On my computer ...
1
vote
2answers
51 views

Sort and display input numbers

How do I decrease time, especially in sorting? Given a list of numbers, you are to sort them in non-decreasing order. Input t – the number of numbers ...
2
votes
1answer
55 views

In-place quicksort algorithm in Python 2

I have tried to implement an in-place quicksort Algorithm in Python 2. Please suggest how I can Make the code more efficient Increase readability Improve writing style Make it more Pythonic ...
4
votes
2answers
48 views

Subsorting with multiple Comparators

I've seen a number of questions on Stack Overflow of the kind of "How do I sort on fields X AND Y?" The most common answers to those questions consists of "Write a custom Comparator." But what if you ...
4
votes
1answer
40 views

Test many sorting algorithms using Python and Nose

I'm trying to learn how to build a good test suite, using simple sorting as an example. Particularly, I am using Nose to generate all the tests based on a simple list of lists, where each sublist is a ...
3
votes
3answers
85 views

Radix sort with C++

At first the input array is traversed and for each number the lsb is found. Then the number is put into appropriate bucket according to it. For example for an input array { 123, 45}, at first 123 will ...
3
votes
0answers
46 views

Parallel MSD radix sort in Java

I have this parallel implementation of MSD radix sort, which processes the entries by one particular byte. At each byte index, it has three phases: Count the bucket sizes. Insert each entry to its ...
1
vote
0answers
24 views

MSD radix sort in Java for parallel arrays - follow-up 2

The previous and second iteration at: MSD radix sort in Java for parallel arrays - follow-up Changes: arrays[j][i] != arrays[j + 1][i] to ...
4
votes
1answer
64 views

MSD radix sort in Java for parallel arrays - follow-up

The previous and initial iteration at MSD radix sort in Java for parallel arrays. Changes: Entry hides both the sort key and satellite datum in private final ...
1
vote
0answers
76 views

Object counting sort in Java

The counting sort for integers counts the amount of each integer, then traverses the count entries in order, and for each entry inserts the integer representing the bucket into the array as many times ...
7
votes
1answer
110 views

Stable Sort in C#

I wrote a stable sort algorithm in C#. It is just a simple iteration, and is probably not very optimal: ...
3
votes
1answer
52 views

3-way merge sort in Java

All those numerous merge sorts split the range in two halves. This is a modification that splits each range into 3 subranges. My demo suggests that 3-way merge sort is pretty efficient on large ...
0
votes
0answers
46 views

A different implementation of Heap Sort

The following implementation is a bit different form the standard implementations I have read. Is it correct? ...
5
votes
1answer
59 views

Reverse Groups challenge at CodeEval.com

I am working through challenges at CodeEval.com and wanted to get your input on my code for this challenge. Given a list of numbers and a positive integer k, reverse the elements of the list, k ...
2
votes
4answers
85 views

Is it correct to use Java Comparator with 3 conditions at the same time?

I am trying to create a class whcih implements Comparator class. The thing is that I have a list with some objects. This object is composed of 3 fields (Strings). My purpose is to sort the list ...
2
votes
1answer
51 views

MSD radix sort in Java for parallel arrays

I have this MSD (most-significant digit) radix sort sorting Entry objects holding a sorting key of type long and a satellite ...
4
votes
1answer
46 views

'Sort By' Function for Rebol

I'm looking for a more consise way to sort a block of objects. Where you can sort a block of blocks based on the numeric position of the values to compare, there's no such shorthand for comparing ...
1
vote
0answers
65 views

Optimizing insertion sort for small amounts of data

I'm building a hybrid sort, and for that I need a fast and adaptive sort ideal for small sizes (< 65 elements). Insertion sort immediately comes to mind, and I've been tinkering with different ...
11
votes
2answers
130 views

Allowing the user to alphabetize or randomize the contents of a text file

As a newbie programmer, I decided to try my hand at making a program whose function actually might be useful to someone, somewhere. This utility takes a text file, reads it out to the user, displays ...
0
votes
0answers
65 views

Radix sort (LSD) and counting sort

I'm reading CLRS, and to practice, I rolled my version of radix sort and counting sort. I was looking at some reference implementations, particularly the LSD one from rosetta code, and mine performs ...
1
vote
0answers
48 views

Elegant way to sort on multiple properties that might be undefined

I'm trying to sort an array with JavaScript. The objects should be sorted based on several properties (about 4 in my real scenario), which are all strings that may also be null or undefined. A null or ...
3
votes
2answers
143 views

Sorting by patients' name or birth

Is there a way to write this simpler? ...
-1
votes
2answers
78 views

Sorting array with respect to two properties

I'm sorting with respect to Width and Length. However, Width has the significance ...
5
votes
3answers
93 views

Could this QuickSort be made more consise and “nicer”?

After seeing this example of a "primitive" QS implementation in F# by Scott W ...
6
votes
2answers
186 views

Merge sort using sentinels

This is my implementation of recursive merge sort, using sentinels: ...
7
votes
3answers
120 views

Python implementation of quicksort

My teacher often tells me that I don't take full advantage of Python capabilities, I would like to know if my implementation of Quicksort is good enough and how could I improve it, aside from doing it ...
5
votes
3answers
273 views

Avoiding label in a loop to sort links

How can I refactor my code to remove the label and the need for it? I am aware that a loop with label is "forbidden". But I can not find a way to rewrite this without the label. ...
5
votes
2answers
336 views

Shell sort seems inefficient

I am testing various sorting algorithms. Right now I am testing shell sort, insertion sort and selection sort. I ran all three algorithms on a randomly-generated list of 1000 integers. The selection ...
4
votes
2answers
83 views

Custom sorting a list of objects efficiently

I'm trying to make sorting of objects in my program as fast as possible. I know that sorting with a cmp function is deprecated in python 3.x and that using keys is faster, but I'm not sure how to get ...
3
votes
1answer
73 views

Mergesort and validation

I have written an implementation of a Mergesort in Python3. An Ideone with the implementation is available. Any suggestions for improvement or any criticisms? ...
2
votes
1answer
152 views

Quicksort implementation in Python

I have written an implementation of Quicksort in Python. I am new to Python. Any suggestions for improvement or criticism on my use of Python? ...
2
votes
0answers
88 views

Sorting an array to match the order of values of another array

I'm running hundreds of curl operations in parallel to my own API, the response array that I get is out of order ( the reason being that the first one to finish gets added to the response array ...
3
votes
2answers
97 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: ...
26
votes
2answers
2k views

Quicksort implementation seems too slow with large data

I've written a program to compare different sorting algorithms with the array size being 10, 1,000, 100,000, 1,000,000 and 10,000,000. I, of course, expect Insertion to win out on 10 and merge heap ...
2
votes
1answer
24 views

Sorting of nested categories inside a Common Table Expression

I have a PostgreSQL database which contains (among other things) the following table definition: ...
6
votes
2answers
179 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 ...
6
votes
4answers
1k views

Arranging words in sentences alphabetically

For an online contest whose problem is here, I wrote some code. In this problem the input will consist of a number of lines of English text consisting of the letters of the English alphabet, the ...
4
votes
1answer
148 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? ...
0
votes
4answers
73 views

Speeding up script for processing three huge files

I have three huge files I need to process in order to rearrange the data contained within. The first file is a list of English example sentences (468,785 lines long). A typical line from this file ...
3
votes
2answers
108 views

Creating a list containing the rank of the elements in the original list

I don't really know how to explain what I'm looking for in a way that makes sense, but here goes: Say I have a list $$L=(4,7,9,10,6,11,3)$$ What I want to produce is a corresponding list $$ K = ...
7
votes
1answer
210 views

Sorting algorithms with utility functions and iterators

My implementation of insertion, merge, and quick sort, with some utility testing functions. I just wanted to know how I can improve the efficiency and general cleanliness of my code. (note: I know ...
9
votes
4answers
1k views

Sort three input values by order

This is a program to sort three inputted integers in order, from least to greatest. I would like to have it reviewed. ...
4
votes
2answers
635 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? ...