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

learn more… | top users | synonyms (1)

4
votes
2answers
174 views

Ruby Interrupted Bubble Sort

Working through CodeEval's Interrupted Bubble Sort, I have a working algorithm, but there's a speed issue. I'm trying to do this with Ruby and I keep getting an error that it's timing out after 10 ...
6
votes
1answer
87 views

Sort all the characters according to their brightness

I wrote a little fractal noise generator the other day, and to test it I wanted to display the dark values with a darker character and the bright values with bright characters (I use a dark background ...
5
votes
2answers
153 views

Finding the order of sorting of an array

I am finding the order of sorting of an array. The code works but can it be made better especially the return values of the function findSortOrder. ...
5
votes
2answers
119 views

Merge k Sorted Arrays

Please review my answer for this interview question: Merge k sorted arrays, using min heap. ...
7
votes
2answers
46 views

Shell sort function

I wrote a Python sort function that uses shell sort: ...
6
votes
3answers
79 views

Comparing three O(n^2) search algorithms in C

I'm currently taking Harvard's CS50 course via EdEx.org, and we're learning about sorting algorithms. More specifically, we're studying bubble, insertion, selection, and merge sorts. Just for kicks ...
3
votes
1answer
27 views

Complex sorting of nested data

I am retrieving data from Postgres (jsonb type) and I need to return an OrderedDict that has a predictable order for human and machine consumption. There are some ...
2
votes
2answers
39 views

Adaptive counting sort for integer arrays in Java

I have this adaptive counting sort for integer arrays. Basically, it maintains a doubly-linked list of nodes. Each node knows its integer \$a_i\$ and contains the counter describing the number of ...
5
votes
0answers
40 views

Radix sorts in Java

I was curious, how in-place radix sort compares to the variant which uses an auxiliary array in order to speed up the sorting. I implemented both and tested it against ...
2
votes
2answers
61 views

Introsort in Java

Now I have this Introsort for integer arrays. Basically, Introsort is the same algorithm as Quicksort. However, in the very first invocation of that "Quicksort", it computes an integer threshold that ...
1
vote
1answer
25 views

Heapsort for arbitrary ranges in Java

I plan to work on Introsort, which requires a working implementation of heap sort. Also, the heap sort implementation must be able to sort arbitrary ranges within an array, which, in turn, requires ...
7
votes
2answers
81 views

Selection Sort algorithm in Java

I'm relatively young in Java, and am familiar with only the basics of the language, yet. I've started studying data structures, and I've made an attempt to create a solution for the selection sort ...
5
votes
2answers
72 views

Benchmark a sorting method for fixed-size arrays

During the past few days, I have written a small C++14 library which mainly provides the cppsort::sort function. It is designed to efficiently sort small arrays ...
2
votes
1answer
36 views

Create a text index of files

This program creates a text index of 3 different files in Python. While this works correctly, I am still a beginner in Python. I used a list of class objects. Can this code be further optimised? ...
1
vote
0answers
35 views

Heap selection sort - follow-up

See the previous and initial iteration. I got rid of Run objects and just maintain two integer arrays in the RunHeap: one for ...
2
votes
3answers
81 views

Bubble, selection, and insertion sorting

The following programs are bubble sorting, selection sorting and insertion sorting. As most of the programs online or in books are with Arrays and not ...
0
votes
1answer
52 views

Sorting object with null values underscore sortBy

I'm sorting my object by its property ActivityOrder, which will sometimes contain null values if the user has not explicitly ...
3
votes
1answer
58 views

Sorting colors by the name of the color

I was in need to sort Colors, so the first thing that I tried was this: ...
5
votes
3answers
228 views

Finding k largest (or smallest) elements in an array

I have written this code for the question: Finding k largest (or smallest) elements in an array My approach uses a temporary array. Please suggest any ...
5
votes
2answers
64 views

Optimising a user's-choice sorting algorithm

With the help of some nice folks at Stack Overflow, I wrote an algorithm that will give a user three buttons: option a neither ...
4
votes
1answer
65 views

Heap selection sort in Java

See the next iteration. I designed and implemented this adaptive heap sort in Java. It works as follows: Copy the range to be sorted into auxiliary array \$A\$ Create an empty run heap \$H\$ Scan ...
2
votes
1answer
46 views

Sort files by the type of file

I need to sort files by the type of the File. To accomplish the task I first wrote the code below: ...
3
votes
5answers
134 views

Sorting ArrayList

Here is the task: Create several classes of flowers that extend abstract flower. all fields -- random. make a bunch of 20 different flowers calculate the price of the bunch sort ...
2
votes
1answer
111 views

Bogosort vs bogobogosort [closed]

A question on Stack Overflow had me look up the article on bogosort on Wikipedia. There they describe the bogosort algorithm and the bogobogosort algorithm. They say, about this last algorithm, that: ...
3
votes
2answers
160 views

Measure execution time of sorting algorithms

I have to measure execution time of certain sorting algorithms being passed as functions in following program. I also do not have to measure it on random container but also on ascending as well as ...
4
votes
1answer
112 views

Counting number of inversions

This is a HackerEarth Challenge Problem. Question: Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N ...
-1
votes
2answers
109 views

Quicksort for Objective-C

This is quite plain vanilla, but I'm hoping for Objective-C specific feedback. Also I'd be interested in what folks think about sorting in Objective-C vs. doing all sorting in C or C++ (and which?) ...
5
votes
2answers
61 views

HeapSort implementation

I have implemented the heap sort algorithm which passes my tests. Although, I would like to ask you if I can improve anything from readability to performance. ...
5
votes
3answers
114 views

Recursive and iterative approach for mergesort

Problem: Question 8: * Mergesort is a type of sorting algorithm. It follows a naturally recursive procedure: Break the input list into equally-sized halves Recursively sort both ...
2
votes
1answer
51 views

Sorting an associative array alphabetically

I am using a foreach loop to sort an associative array alphabetically. I would like to know if there is a more proper and/or efficient way of doing it. The array: ...
6
votes
1answer
65 views

Finding most frequent words from Google N-Gram dataset

I have written a program to process Google 1-Gram dataset in order to obtain the list of most frequent words. This is my second more or less working program in Haskell, so I really want to know if it ...
6
votes
1answer
75 views

Multiprocess Bogosort

I only program by hobby, and I'm trying to improve with Python, so along with practicing coding I decided to venture into multiprocessing. This is a command line and will sort a variable number of ...
2
votes
1answer
62 views

Sorting an integer array using heap sort

I have written this program to sort an array using heap sort. Please review it for further improvements. ...
1
vote
2answers
62 views

Function to sort items with an array of keys

I'm working on a function to sort two elements using several properties. I want to know if the function is well structured. ...
4
votes
3answers
171 views

IComparable implementation for a class representing a version

I have an UpdateId class which represents some kind of version (like AssemblyVersion). UpdateId has three int values (listed in their compare priorities order): Year, ReleaseNumber and Revision. How ...
2
votes
1answer
69 views

Bottom up mergesort in Java

See the next iteration. I have this iterative mergesort (a.k.a. bottom-up mergesort). BottomUpMergesort.java: ...
1
vote
2answers
163 views

Sorting an Integer array

The program sorts the array from lowest to highest and outputs the index of the searched value: ...
6
votes
1answer
72 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
2answers
409 views

Is the list sorted?

Is the trade-off between simplicity and performance worth it? ...
4
votes
4answers
108 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. ...
0
votes
2answers
82 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
75 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
142 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 ...
4
votes
1answer
120 views

Sorting a list of names by greatest lexicographical order

This is a puzzle I found online that I have been trying to optimize and make the best version. I've tested it and it works great but I'm curious how it can be improved in any way. Instructions: ...
2
votes
2answers
103 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
2k 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
4k 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
75 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
52 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
30 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 ...