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

learn more… | top users | synonyms

-1
votes
0answers
15 views

Kth selection routine - Floyd Algorithm 489 [migrated]

I have recently come across a promising Kth selection routine that reportedly outperforms quickselect the Floyd, Rivest Select routine. This Wikipedia article provides a pseudocode version which I ...
0
votes
0answers
16 views

Am I scanning my contacts right? [on hold]

We are in an iOS app, in Objective-C. I have three types of objects involved here, Contacts, Users & ...
-1
votes
0answers
8 views

JavaScript Table Sorting - tablesorter (parse on the fly) vs stupidtable (`data-` attributes) [on hold]

I am trying to get a grasp as to which jQuery table sorting method/plugin is better. Tablesorter Parses all the table data to sortable data. Stupid Table Plugin Allows the dev to add sortable ...
30
votes
3answers
3k views

Sorting millions of integers

Last Friday I was hit with a sorting interview question that I never really had to deal with. Develop a your own sorting algorithm. It cannot use any other Classes for help. It needs ...
6
votes
2answers
54 views

Bubble sort in Ruby

For practice, I tried implementing Bubble sort in Ruby. I wasn't very sure how nested for loops would look like in Ruby. Is this the 'right way' to do this in Ruby? I found this question, but it looks ...
1
vote
1answer
36 views

boost::spreadsort for std::pair

Boost 1.58 has new library spreadsort, so I tried it out. I wrote simple sample for sorting vector of pairs of int: ...
1
vote
1answer
23 views

Reducing a 2D array to its longest unique series that aren't contained within any other

I have an array whose members are arrays containing strings. Each array has 5 elements, some of which may be empty but always at the end of the array. The order of the strings matters because their ...
2
votes
2answers
76 views

Merge Sort algorithm

I just read and experimented with C++ implementation of the merge sort algorithm from the Wikipedia page. During the experiments I have slightly modified the source code and would like to know how ...
2
votes
1answer
46 views

Treesort in Java

I have this sorting algorithm which constructs an (unbalanced) tree and performs in-order traversal in order to sort the requested range. However, the more order exists in the input array, the closer ...
0
votes
1answer
42 views

Sorting algorithms - Relocation Counter

I want to count the total relocations for each of these sorting algorithms. From the results it seems my code is correct, but I need someone to confirm it. Is the counter variable placed in the right ...
3
votes
1answer
79 views

Create a struct to store student data and perform statistical analysis on data

I had to create a program that had a struct that held data inside of it. I had to read an input file and take the contents and read it into an array of structs. Then, I had to solve for some ...
2
votes
4answers
122 views

Printing all the permutations of a string in alphabetical order

It is a code eval challenge question https://www.codeeval.com/open_challenges/14/. My answer was accepted, and I modified my code again to improve it. Please let me know is it possible to improve it ...
3
votes
1answer
81 views

Modern C++ compliant insertion sort

This is a kind of follow up to my previous sort implementation question with specific questions to insertion sort, and Modern C++ idioms. Anybody seeing this post can see how I got to this modern ...
1
vote
1answer
149 views

Modern C++ compliant selection sort

I am writing, as review, Modern C++ compliant versions of sorting algorithms I previously have seen. This post is about selection sort, and selection sort only. Whilst selection sort is rather ...
5
votes
2answers
75 views

Performance of Median routine using min performs abysmally

I am writing a routine to calculate median using the minimum of the numbers and then changing the value of the minimum to a large value outside the range of numbers (assuming you know the nature of ...
6
votes
4answers
457 views

Bubble sort algorithm in JavaScript

I'm new to JavaScript (and programming) and taking a course. I was tasked with creating a bubble sort on any array using JavaScript. Of course, since this is an algorithm challenge, no sort method ...
1
vote
1answer
50 views

Natural mergesort

This is a problem from Robert Sedgwick's Algorithms book: Write a version of bottom-up mergesort that takes advantage of order in the array by proceeding as follows each time it needs to find two ...
2
votes
0answers
70 views

Nuts and bolts algorithm

I am trying to learn golang. This is a problem from Robert Sedgewick's Algorithm's book: You have a mixed pile of N nuts and N bolts and need to quickly find the corresponding pairs of nuts ...
8
votes
4answers
828 views

Simple comparison of sorting algorithms in C++

I know this has been done a million times before, but this is my implementation of bubble-sort, insertion-sort, merge-sort, heap-sort, and quicksort. Any feedback on how to make it better would be ...
1
vote
1answer
36 views

Parallel natural merge sort

Continuing working on Natural merge sort, I have parallelized it. Requires \$\Theta(N)\$ space and runs in $$\Omega(N + \frac{N}{P}) \cap \mathcal{O}(N + \frac{N}{P}\log_2\frac{N}{P})$$ time, where ...
2
votes
0answers
25 views

Natural merge sort - follow-up

The previous iteration at Natural merge sort Now my code relies on C++14 and looks like: natural_merge_sort.h: ...
4
votes
3answers
88 views

Natural merge sort

Note: the next iteration at Natural merge sort - follow-up I have compiled natural merge sort algorithm from Java to C++. Natural merge sort sacrifices at most \$2N\$ amount of work in order to ...
2
votes
2answers
73 views

Use Selection Sort to Sort Employee Data About Pay

This program is supposed to prompt the user for hours and wage of 4 employees. Then the program will use a selection sort to sort the data into ascending value using the wages. The information like ...
1
vote
1answer
58 views

Is this the best way to check sorting (in recursion) without loops?

Please let me know if there is a shorter way to do it again without any kind of loops. Recursion only. ...
7
votes
1answer
169 views

Is this implementation of Quicksort good?

For fun, I decided to implement the quickest Quicksort I could. This is what I came up with. How can I make it better? I know that it's slower for sorted and already reversed lists (through testing), ...
1
vote
2answers
67 views

Possible sub-optimal selection sort

Why is this code "bad"? In all of the selection sort codes I am learning from, they do it much differently. I will learn the proper code from the book, but I would love to know why this particular ...
1
vote
1answer
34 views

Selection sort implementation in Java

Here's an implementation of selection sort, that sorts an array in ascending order. Please let me know of any improvements/optimisations that can be done. ...
1
vote
0answers
32 views

Insertion sort in Java

I've written a stable implementation of insertion sort, that sorts an array in ascending order. Please let me know of any improvements/optimisations that can be made. ...
3
votes
1answer
83 views

Custom iComparer

I've got a base class GraphUIControl which is inherited by 4 child classes: BubbleGraphUIControl ...
6
votes
0answers
93 views

Asc and desc array sort methods

I've used the typical INT array sort function found all over the internet for years, but I've also had a need to sort other items in an array, or even to just simple take an ...
3
votes
1answer
287 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 ...
3
votes
1answer
71 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 ...
0
votes
0answers
42 views

Sorting products by name or price

Lets preface this by saying that when it comes to javascript, I am a hack. I make what I need happen by cobbling together crappy, inefficient, redundant code. I want to get better. Recently I was ...
4
votes
1answer
62 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
984 views

Array Sorting in C++

I have this simple implementation for array sorting: ...
5
votes
1answer
42 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
76 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
35 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
52 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
54 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
154 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 ...
4
votes
3answers
120 views

Sorting movie search results by similarity

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
44 views

Shorten a custom JS sort function

I have 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 their ...
2
votes
2answers
47 views

Improving performance while sorting a JavaScript Object

I am sorting an array (filtered) containing JS-Objects by their attribute sortdist: ...
10
votes
2answers
66 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
67 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
89 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
76 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
55 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 ...