Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
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 ...
3
votes
1answer
174 views

Basic sorting in Python

Previously asked here. I would like to get my code for implementation of simple sorting algorithms in idiomatic python code reviewed. I am looking for feedback on python idioms used, better ways of ...
3
votes
3answers
377 views

Merge sorting a singly-linked list in C - follow-up

(See the initial iteration.) Continuing from Merge sorting a singly-linked list in C, I have incorporated the points made by @vnp. Now it looks like this: ...
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 ...
3
votes
4answers
510 views

How can I make my Merge Sort Code In C more secure, effective and efficient

I have been implementing the merge-sort algorithm for sorting the data for a long time, each time I use the following source code for implementation. By secure, I ...
3
votes
1answer
81 views

Python: Quick Sort

How to improve this code? In C++ we use templates to write function for all data types. How to write such code in python? ...
3
votes
1answer
679 views

MSD radix sort in Java for parallel arrays

I have this MSD (most-significant digit) radix sort sorting Entry objects holding a sorting key of type long and a satellite ...
3
votes
0answers
68 views

Adaptive counting sort for integer arrays in Java - follow-up

I have refactored this. Once again, the running time can be anything between \$\Omega(n)\$ and \$\mathcal{O}(n^2)\$, yet it adapts to "smoothness" of the input array. ...
3
votes
2answers
541 views

Adaptive counting sort for integer arrays in Java

(See the next iteration.) 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 ...
3
votes
1answer
2k views

Quicksort implementation in Python

I have written an implementation of Quicksort in Python. I am new to Python. Any suggestions for improvement or criticism on my use of Python? ...
2
votes
0answers
279 views

Follow-up 1: Compare 2 unordered, rooted trees for shape-isomorphism

The previous post can be found here. In the previous post I tried to solve an exercise but found through the answer of Peilonrayz a bug in the code and 2 more while fixing it. These have now been ...
2
votes
1answer
1k views

Insertion sorting an int array

I'd like to improve this Insertion sort code ...
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
128 views

Sorting Algorithms (Python)

Selection Sort The selection sort algorithm sorts a list (array) by finding the minimum element from the right (unsorted part) of the list and putting it at the left (sorted part) of the list. The ...
2
votes
1answer
73 views

If given two sorted arrays where first containing -1, merge into one sorted array

If given two arrays arrayOne = [3,6,-1,11,15,-1,32,34,-1,42,-1] arrayTwo = [1,10,17,56] Both the array's are sorted but array1 consists -1 in between the ...
2
votes
2answers
124 views

Write a Java class “Sort” which implements the BubbleSort algorithm

For a further education I had to do the following task: Implement the BubbleSort algorithm within the Java class algorithm.Sort. Submit your solution to ...
2
votes
1answer
192 views

Is my implementation of insertion sort is correct? [closed]

I'm currently learning about different sorting algorithms and after reading on the concept of the insertion sort of how it's done I've tried to implement it by myself before seeing how it was ...
2
votes
1answer
235 views

Simple multithreading C project

I'm fairly new to C, and this is my first time using pthread. I am pretty sure I implemented it correctly, however I'd like to verify it is indeed executing the ...
2
votes
2answers
71 views

Comparing binary insertion sort with straight insertion sort in Java

Straight insertion sort When inserting an element into its proper location to the left, one can achieve that by \$n\$ adjacent swaps which totals to \$3n\$ assignments. Straight insertion sort, ...
2
votes
3answers
3k views

Sorting an array of strings using pointers (followup)

This is a follow-up to this post. Things I've changed: The number of strings is checked. I'm using pointers now. I'll use fgets in more mission critical ...
2
votes
2answers
530 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 ...
2
votes
4answers
399 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 ...
2
votes
3answers
662 views

Natural merge sort in C

I have this C implementation of the natural merge sort: ...
2
votes
2answers
765 views

Compare 2 unordered, rooted trees for shape-isomorphism

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. Edit: This question now also has a ...
1
vote
2answers
283 views

Massive file sorting algorithm

I was trying to sort a massive file of successive chars in C. I did some research and found a few file sorting algorithms that look the same. Their main idea is to read an amount of data to memory, ...
1
vote
1answer
67 views

Python: Selection sort

After implementing suggestions from an earlier, related question (Python: Insertion Sort), I have written this code. Could you help me to improve this code? ...
0
votes
1answer
149 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 ...
0
votes
2answers
1k 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?) ...
-1
votes
2answers
71 views

Remove duplicates from array and save it to another one [duplicate]

I have been tasked to make an array without duplicated values from another existing array. So I did it, but I want to know is there some other better way to do that. Example input/output ...
-1
votes
3answers
200 views

Better sorting speed

import sys x=int(sys.stdin.readline()) lst = [int(sys.stdin.readline()) for i in xrange(x)] lst.sort() print lst How can I make this code faster for large ...
-1
votes
2answers
157 views

BubbleSort - checking if bubblesort is decreasing the iterations through the array

What I'm hoping my code is doing is instead of making 99 comparisons on every pass of a 100 element array, it will now make 98 comparisons on the second pass, 97 on the third pass and so on and thus ...

1 2
3