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

learn more… | top users | synonyms

6
votes
1answer
64 views

Topological sort

The algorithm works in steps: Produce the graph in the form of an adjacency list e.g. this graph 0 - - 2 \ 1 -- 3 produces this adjacency list ...
5
votes
3answers
403 views

Is the list sorted?

Is the trade-off between simplicity and performance worth it? ...
4
votes
4answers
105 views

Increase performance of a method which finds the element removed from an array

Imagine that you have a TreeSet of numbers, and you copy them into an array, but you remove one element of it. You want to know the element removed. ...
1
vote
2answers
75 views

Big O notation for quicksort implementation [closed]

I am trying to find out what would be the Big O notation of a quick sort implementation I wrote. If I can get some analysis on the code, that would be great. ...
5
votes
1answer
49 views

Implementation of ApplySort method from IBindingList

I am currently developing a family of keyed collections, and I wanted to have one which would implement the IBindingList interface. My ...
4
votes
2answers
122 views

Two functions to impose order on queries

I am writing a c# program to build generic sort algorithm on a request to a collection of data. The data needs to be sorted based on the supplied columns.I am using Entity framework and Expression ...
2
votes
2answers
90 views

Beginner implementation of Merge Sort

This is my first time implementing a merge sort (just getting started with algorithms & data structures). Are there any obvious things I have done wrong? I am also worried that I have overused ...
10
votes
5answers
1k views

Sort three numbers using only if-statements

Beginner here, trying to make a small program that sorts three numbers from smallest to largest only by using ifs. Any thoughts on how to improve this? ...
34
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
60 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
47 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: ...
2
votes
1answer
28 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
86 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
89 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
48 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
150 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
141 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
89 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
156 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
84 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
749 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
68 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
77 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
938 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
37 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
28 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
131 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
96 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
61 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
176 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
69 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
36 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
1answer
47 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
87 views

Custom iComparer

I've got a base class GraphUIControl which is inherited by 4 child classes: BubbleGraphUIControl ...
6
votes
2answers
162 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
405 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
78 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
66 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
70 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
1k views

Array Sorting in C++

I have this simple implementation for array sorting: ...
5
votes
1answer
48 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
212 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
36 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
60 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
55 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
198 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
2answers
72 views

Bubble sort a list of integers for a number of iterations

I wrote a program for this problem, but it stopped because it took too much time. Any tips? The Problem: Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
4
votes
3answers
141 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
63 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 ...