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

learn more… | top users | synonyms

3
votes
1answer
55 views

Sorting thousands of records

I have the following list to sort: A 0.53 B 0.56 C 0.56 D 0.98 E 0.33 Please note that my list may contains thousands of such type of records. I am sorting my ...
2
votes
1answer
47 views

Sort a linked list with merge sort in C

This is my version of a linked list in C. The function mergeSort requires a reference to the first and to the last nodes, as well as the indices of the first and ...
4
votes
1answer
50 views

Union of intervals

I am trying to solve for the problem with a bunch of intervals: (1,2),(2,5),(4,7),(9,11) I find their union, which in the above given case would be: ...
4
votes
3answers
911 views

Array Sorting in C++

I have this simple implementation for array sorting: ...
5
votes
1answer
30 views

Update on Weave Merging n lists into single list

This is a follow up to my previous post from 7 months ago. I changed up the algorithm a little. Instead of inserting items into a new list, each item's final place is calculated up front. Sort of like ...
5
votes
1answer
40 views

Sort a stack in ascending order

Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...
3
votes
1answer
32 views

TurboSort challenge

I recently started to do some of the exercises in CodeChef and I did the TurboSort challenge here is it's description. It works fine with smaller arrays but can't pass some of the tests due to the ...
0
votes
1answer
42 views

log(n) “sort by value” Map<K, V>?

I've read so much arguing about "sort by value maps". Well, I wrote the following log(n) sort by value Map . And, by the way, a real Map , does not allow duplicate keys. Many of the maps I googled ...
2
votes
0answers
46 views

Classic sorting algorithms [closed]

I implemented the classic Sorting Algs in JS for practice. I come from a C++/Java background. Just wanted to make sure I didn't miss anything or if there was a 'better' JS way of doing it. Also, I ...
5
votes
3answers
107 views

Shuffle a sorted array so that left portions contains even indices and right portion contains odd indices numbers

I have been solving the following problem: Input array: \$[7,4,2,5,1,9,6]\$ Output array: \$[1,4,6,9,7,5,2]\$ I tried to do it in the following way: Sort the array. So, Input array becomes ...
2
votes
3answers
80 views

Sorting movie search results

I want to sort "movie search results" to get most probable movie that match "search". Input example: CARS.2.2011.720P.AC3.mkv I have a NameMatcher class ...
0
votes
3answers
28 views

Shorten a custom JS sort function

So I have got a sort function that needed to sort in a certain way, that position was sorted by mobile-top first, then empty position followed by mobile-bottom. Then on these I needed to sort by ...
2
votes
2answers
38 views

Improving performance while sorting a JavaScript Object

I am sorting an array (filtered) containing JS-Objects by their attribute sortdist: ...
10
votes
2answers
52 views

Frequency counter utility class

Some very common tasks that keep popping up from time time: Find the most frequent something in a collection of things ... or the count of that thing ... or both (the item and its count) Get the ...
3
votes
1answer
59 views

Quick sort in PHP

Does this code show proper implementation of quick sort algorithm? If not, why? Can this code further be improved? ...
5
votes
1answer
65 views

Adding ranks to objects in an array

This works, and I personally find it elegant and kind of "neat," but then I worry it's a bit too tricky. Comments welcome: ...
1
vote
2answers
58 views

Bubble sort in PHP

Does this code show proper implementation of bubble sort algorithm? If not, why? Can this code further be improved? ...
1
vote
4answers
53 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
2
votes
1answer
72 views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
3
votes
0answers
81 views

Building an efficient bubble sort function

I've been asked to create a bubble sort function that checks whether the array has been filled sorted before all passes are complete, thereby avoiding unnecessary passes. This is to involve ...
4
votes
3answers
118 views

Merge sort implementation and improvements

I would like your opinion on my Java implementation of the merge sort algorithm on an integer array, since I'm not really into algorithms I'd like to know from you if this is a correct implementation ...
1
vote
1answer
38 views

Add sorting to a namedtuple

I currently override the sorting methods provided by namedtuple by doing something like this: ...
2
votes
0answers
52 views

Directed Acyclic Graph with topological sort

I have here a class which represents a directed acyclic graph (Graph) and a vertex in the graph (Vertex). The vertices are ...
2
votes
0answers
34 views

Search/sort/create functionality, implements bubblesort and sequential search

I've moved my main() to the bottom of the code block in order to fit it all in one class for this submission. If there is a better way to do it? ...
3
votes
2answers
109 views

Radix sort with integer divisions

Here's a perhaps naive but simple implementation of Radix sort in Java. It works with any radix, and both positive and negative numbers. ...
0
votes
1answer
65 views

Generic list heapsort in Java

This is an implementation of heapsort as seen on Programming Pearls, adapted for java List collections. It is working on a copy of the list passed-in on purpose at the moment. ...
4
votes
0answers
29 views

Quicksort in SAS for sorting datasets

As a challenge for my own amusement, I decided to write a SAS macro for sorting datasets, deliberately avoiding all of the built-in methods (e.g. proc sort / ...
1
vote
1answer
56 views

Sort by a custom date field

I've got this code to work, but being really new to PHP, I don't know if this is proper. I've sorted a CPT loop by a custom date. I'm displaying items from most recent (or future date) to oldest if ...
3
votes
2answers
101 views

Recursive functions for sorting

I made a few recursive functions for learning purposes which do a variety of tasks. Here is my current and functioning code: ...
3
votes
2answers
68 views

Sort ArrayList in a better way

I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this: on top we should have 2 categories ...
0
votes
0answers
50 views

Natural sorting/comparing algorithm in TypeScript

This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
1
vote
0answers
43 views

Binary heap implementation in Golang

I have implemented a binary heap in Go to get familiar with the language. GitHub ...
8
votes
2answers
210 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
87 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
1k 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
249 views

Quick Sort - implementation

Can anything be improved in this code? ...
4
votes
3answers
54 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 ...
2
votes
1answer
51 views

Collection of sorting types

A collection of sorting types as following insertion, radix, selection and heap sorts. How can i improve it? ...
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
61 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
59 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
67 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
122 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
46 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
213 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
68 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
29 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
172 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
121 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
127 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: ...