Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
219 views

Merge sort could work 10 times faster

I am implementing merge sort in Java and I have a performance problem in this method: ...
5
votes
2answers
471 views

How to verify if HTML table sort is stable or not?

I have implemented a HTML table sorting. I actually implemented a sort first using jQuery and then modified it based on the answer to this question for performance as I had done the same mistake. My ...
5
votes
3answers
572 views

Trying to cut down redundancy in my code

I have created a class that has many methods for sorting an ArrayList of objects. Each method is somewhat similar in that they employ some kind of sort on an ArrayList and then return the arrayList. ...
4
votes
1answer
6k views

Implementation of quick sort in C#

I'm currently learning programming for the first time and I've created the following implementation of quick sort in C#. I basically read a very basic overview of how quick sort works recursively and ...
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. ...
5
votes
1answer
1k views

External "bucket" sort

I'm working on a CTags plugin for Sublime Text. One of the open issues revolves around the fact that an in-memory sort of a tag file can cause some form of memory or buffer overflow errors (the stack ...
3
votes
1answer
188 views

Sorting possibly unstable and general jsfiddle/jquery problem

I have a simple sorting algorithm that I was told is possibly unstable. I'm wondering what in the sort is unstable. I have test cases written to test all fields with no issues. A secondary problem is ...
7
votes
1answer
649 views

How can I speed up my shell sort?

I'm trying to implement a bunch of sorting algorithms in JavaScript, and I can't figure out why my shell sort is so slow. It's 6x slower than my merge sort, and only slightly faster than my insertion ...
4
votes
2answers
4k views

Produce a nearly sorted (or K sorted) array

Given an array of n elements, where each element is at most k away from its target position, devise an algorithm that sorts in O(n log k) time. For example, let us consider k is 2, an element at ...
5
votes
1answer
454 views

Is this merge sort code good enough?

...
7
votes
2answers
210 views

Is this quicksort efficient and acceptable?

In order to complete one of my assignment I needed to include a quicksort so I was wondering if this is correct and acceptable. The code: ...
2
votes
2answers
8k views

How to sort two array of objects using Underscore.js? [closed]

I am sorting 2 arrays of object like this, but I know this is very bad. Any good approach, like using each method like so? ( I tried, but using each, I am unable to return the object ) ...
5
votes
1answer
4k views

Selection sort algorithm in Python

I'm learning basic algorithms and implementing them in Python. Critiques needed/welcome. ...
2
votes
1answer
107 views

A package for sort algorithms - v3

Addressed both issues in this codereview post. Fixed the indexing issue and the call mechanism of the function expression. Looking for perfect code. Hope this is the last rev. ...
5
votes
1answer
84 views

Shorten a sorting function

I have this function: ...
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). ...
5
votes
1answer
310 views

Is this an efficient merge sort implementation with regards to average time complexity in Big-O notation?

Is my below merge sort implementation in O(n log n)? I am trying to implement a solution to find k-th largest element in a given integer list with duplicates with O(N*log(N)) average time complexity ...
3
votes
4answers
151 views

A package for sort algorithms

I'm trying to learn basic algorithms which are typically taught in an introduction to CS course, which is usually taught in a compiled language like Java. However, I want to focus on JavaScript, so I ...
4
votes
1answer
1k views

Help with comparison counters in quick sort algorithm

At the suggestion of @templatetypedef, I am posting the code for my quick sort to see if anyone can offer suggestions as to where to make comparisons. And any tips on improving the code. I am using ...
1
vote
1answer
5k views

Merge sort with a linked list

I'd like this code reviewed. ...
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? ...
3
votes
1answer
5k views

Quicksort using pointers

As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any). ...
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, ...
1
vote
1answer
422 views

Review my F# QuickSort Program

OK... last sort of the day and probably the most fun. F# is really awesome. ...
1
vote
2answers
524 views

Review my F# BubbleSort Program

I have written this code for BubbleSort in F#. Can you review and let me know how I can do this in most functional way. ...
4
votes
2answers
85 views

InsertSort F# program

I have written this InsertSort program in F#. It works, but I am not very happy with it. ...
4
votes
3answers
2k views

Sorting strings in a one dimensional array

What are the better solutions possible? I have a character array with different strings. There is a max size for the strings. In case a string is smaller than max size remaining places are filled ...
1
vote
3answers
221 views

Sorting integer array

Please check this program that sorts an integer array. It doesn't look very efficient. Please tell me how to correct this. ...
1
vote
2answers
2k views

Suggestions on improving Sorting Algorithm (Progress ABL/4GL)

I have written some sort routines for PROGRESS 4GL/ABL and wanting to get some input whether these sorts can be improved. And whether my sorts are true to name. And I would also be very interested in ...
4
votes
1answer
2k views

Improving performance when sorting array of structs by multiple fields

I have an array of a struct containing 5 byte values. I need to sort this array by each value in a different order depending on the situation. These arrays are sometimes quite small (10-30 elements), ...
2
votes
1answer
222 views

Visualization of bubble sort in progress

I've written a program showing the process of bubble sort arithmetic in C. I need some suggestions on improving it. ...
1
vote
1answer
8k views

sorting a numerical list using basic scheme

I would like some feedback on the appropriate way of ordering a numerical list using the most elementary scheme functions (sorry, i realise that elementary is not ...
3
votes
1answer
3k views

Counting sort review

I've just wrote a program in C# for counting sort. space complexity is O(N+K) time complexity is O(N+K) I want reviews on my code and any better ways to implement this. ...
1
vote
1answer
309 views

MergeSort implementation with java.util.List passed as argument, not returned

I'm working on an implementation of MergeSort which sorts a List given as an argument. As follows ...
1
vote
1answer
70 views

Sorting Each Entry (code review + optimization)

I have a requirement where there are 3 selection criteria user selects countries from a map displayed as lets say in 3 categories , i am maintaining 3 arraylist for the same.Each time he selects a ...
6
votes
4answers
723 views

A character array of arbitary length with 'R', 'B', 'W' is needed to be sorted in that order

There is a char array of n length. The array can have elements only from any order of R, B, W. You need to sort the array so that order should R,B,W (i.e. all R will come first followed by B and ...
1
vote
1answer
126 views

Extracting Javascript functions

I have this jQuery click handler function that has three jobs: Set the time interval for the refresh rate Change the color on the clicked refresh rate selection Callback the tablesort functions to ...
1
vote
1answer
290 views

Counting inversions

I'm trying to implement an inversion counting routine in Scala in a functional way (I don't want to port Java solution) but have real troubles with it. The sorting routine works fine but adding the ...
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. ...
5
votes
2answers
4k views

In-Place Quicksort in Python

Code is below. I'd like to know if this is a solid/efficient implementation of the in-place quicksort algorithm and if my Python style is good (I know there are no comments for now). Code is also on ...
4
votes
4answers
2k views

My first javascript sorting

I started learning JavaScript a week ago, and I made a sorting function on my own. It does work, but I need reviews and how to write a better one. ...
2
votes
4answers
2k views

Sort a list in Python

My aim is to sort a list of strings where words have to be sorted alphabetically. Words starting with s should be at the start of the list (they should be sorted as ...
2
votes
1answer
435 views

Sorting an array

I wrote this program for sorting an array of type String alphabetical without using compareTo() method so I am saying that if ...
8
votes
4answers
10k views

C++ vectors sort ascending/descending

How can I eliminate repetition from this code? ...
1
vote
2answers
1k views

Quicksort in Ruby!

I've been teaching myself Ruby this weekend. First of all, I am aware that there is a built-in sort function. I've written this code strictly as an exercise. I have background primarily in C# and ...
3
votes
2answers
1k views
4
votes
3answers
9k views

Sort List By Boolean

I have a class called Task that contain a member boolean variable Completed. I created a list of ...
2
votes
1answer
2k views

Sorting parallel ArrayList

I have a model class that contains 3 ArrayList which are in order by parallel of the same size. ...
1
vote
4answers
284 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 ...
3
votes
2answers
527 views

creating a hash based sorting algorithm

For experimental and learning purposes. I was trying to create a sorting algorithm from a hash function that gives a value biased on alphabetical sequence of the string, it then would ideally place it ...