Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
4
votes
1answer
365 views

Three implementations of mergesort in F#

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? First solution ...
9
votes
3answers
5k views

Multi-tiered sorting using custom IComparer

I have this custom IComparer I use to sort a list of SurveyResponse objects, but it seems really inefficient, both in terms of ...
3
votes
3answers
3k views

Finding the highest values a and b from an array

I struggled a short while to make this work, so I'm wondering if there are any smarter ways for finding the highest of two values per array element? Uh, hard to explain by words, but by code its easy: ...
3
votes
2answers
1k views

Bubble sort implementation with tests

For practice I tried implementing a bubble sort algorithm in Ruby. I'm especially interested in creating clean DRY and KISS code and keeping things readable, but efficient. Any hints to improve things ...
1
vote
4answers
283 views

Insertion vs Selection

I currently have a selection sorting algorithm, but need some help turning it into a insertion sort, I understand a insertion sort if faster? The hand array is full, and it needs to sort from lowest ...
5
votes
2answers
11k views

Sorting a list of numbers in increasing order

Here's a program I wrote to sort a list of numbers in increasing order (without using inbuilt sort function). ...
8
votes
3answers
2k views

Reorder a list of courses, given their prerequisites

I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
4
votes
2answers
2k views

Merge sort on an Integer class

This is a specific case in merge sort. I'm trying to do a merge sort on an array that's created using the Java Integer class. My implementation is slow and ...
5
votes
4answers
13k views

Groovy: find all elements in a list equal to the max element

Is there any simpler way to find all elements in a list that are equal to the max element. ...
2
votes
1answer
883 views

C++: Data sorting taking a long time

I wrote a simple program that takes the enable1.txt word list of scrabble/words with friends and searches it for an input. In order to search the massive list of ...
5
votes
1answer
798 views

Jon Bentley's bitmap sort implementation

I've implemented Jon Bentley's bitmap sorting algorithm from Column 1 of his Programming Pearls book. This code supports user-defined integer range (works from ...
7
votes
2answers
34k views

Insert sort on a linked list

I want to do insert sort in a linked list without using dummy nodes. This is my code. How can this be improved? Any input is appreciated. ...
12
votes
2answers
5k views

Parallel Quicksort

As my parallel mergesort implementation was very memory dependent, I wanted to write a parallel quicksort one. Here it comes: ...
5
votes
2answers
122 views

Ranking lines of a file according to number of occurrences

I recently dived into Ruby, so I want to improve this code. Is this good enough? ...
14
votes
2answers
8k views

Parallel Merge Sort

Parallism is achieved by using a simple call to tbb::parallel_invoke(). However I can't break a speedup factor of x2 (after ~3-4 parallel HW threads), although 8 ...
3
votes
4answers
2k views

Shifting records in SQL Database while sorting with algorithm

I have a table in a SQL Server database, which holds information of some images, and the relevant gallery of them. The columns are like: ImageId, ...
3
votes
1answer
477 views

JavaScript shuffle idea

Based on the standard implementation of Array.sort in JavaScript, would the following be a reasonable way of shuffling the contents of an array? Is it moderately ...
8
votes
3answers
1k views

Quick Sort Implementation

I have written the below code for quick sort in Java: ...
8
votes
4answers
796 views

Quicksort in C++

Here is the implementation I ended up with. Please post your feedback! ...
6
votes
2answers
457 views

Sorted grep in Haskell

This program implements a sorted grep, that is, a specialized version of grep for sorted files. It uses binary search for the lines of a file that begin with a ...
4
votes
2answers
271 views

Optimizing error-sorting method

I just made this sort method. It runs fine and the code looks okay in my eyes. Is is possible to optimize it so it runs faster? If it's \$O(n^3)\$ now, it would be interesting changing it to \$O(n^2)...
15
votes
2answers
1k views

Is this C++ quicksort program okay?

I wrote a quicksort program in C++. Is it okay to implement it this way? Am I using pointers correctly? Is my style okay? Any ideas to speed it up or save memory? ...
7
votes
4answers
3k views

Heapsort is not modular

For the time being, I am not interested in any recursive solution. The code is not modularized; the whole body is inside the main function. ...
0
votes
3answers
997 views
8
votes
3answers
42k views

Sorting algorithms implemented in C++

Implemented Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, Merge Sort and Radix Sort https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/sorting/SortingAlgorithms.cpp ...
26
votes
5answers
79k views

Java Implementation of Quick Sort

This is my implementation of quicksort (algorithm taken from Cormen book). This is an in place implementation. Please let us know issues with this or any ideas to make it better. It performs at logN. ...
4
votes
4answers
727 views

My own quicksort algorithm

I will make it more reader friendly after I get the algorithm completed. Does anything with the quick sort algorithm stand out as for why it is not working 100%? This is not homework; I am just ...
4
votes
6answers
2k views

Listing books by priority

...
6
votes
3answers
541 views

Khan inspired Insertion Sort

I just watched a Khan Academy video on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program: ...
8
votes
2answers
1k views

Using bucket sort to rank students based on their marks

Problem: n students have marks and names. Rank students based on their marks and print their names. ...
7
votes
1answer
870 views

Merge sort and selection sort comparison taking too long

I have this python code that compares merge sort and selection sort, but it is taking "forever." ...
9
votes
2answers
635 views

Insertion sort implementation adapted from the web

I've found this implementation on the web: ...
5
votes
3answers
940 views

Quicksort application

What do you think about this code? ...
37
votes
5answers
4k views

Sorting strings by length - functional Python

I'm trying to port this little F# snippet while staying pythonic: ...

1
18 19 20 21
22