# Questions tagged [sorting]

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

928 questions
Filter by
Sorted by
Tagged with
23 views

### Naive implementation of sort inplace

I had the following assignment for the Python 101 course I'm taking in my university. ...
7k views

### Insertion Sort in Python

This is what I wrote for insertion sort in python. But somehow I'm feeling that it's between bubble and insertion sort. ...
25 views

### almostIncreasingSequence CodeSignal [closed]

I have this issue. 35/38 sample tests passed. Execution time limit exceeded on test 36: Program exceeded the execution time limit. Make sure that it completes execution in a few seconds for any ...
778 views

### Deck of cards with shuffle and sort functionality

Going through Head First C#'s Chapter 8: Enums and Collections, I learned about List<T>, as well as IComparable<T> ...
49 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? ...
37 views

### Python: Bubble Sort

After implementing suggestions from an earlier, related question (Python: Selection sort), I have written this code. Could you help me to improve this code? ...
61 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? ...
136 views

### Quick Select C#

I tried to implement https://en.wikipedia.org/wiki/Quickselect quickselect is a selection algorithm to find the k-th smallest element in an unordered list. this is the Pseudo code I was ...
83 views

### SplitSort — An adaptive algorithm to handle collections with few inversions

SplitSort SplitSort is a rather simple Inv-adaptive and Rem-adaptive sorting algorithm described in Splitsort — an adaptive sorting algorithm by Christos Levcopoulos and Ola Petersson. The paper ...
692 views

### In place quicksort

I implemented my own sorting in VBA because it doesn't provide its own, and it's healthy to test yourself. It was surprisingly difficult and I ended up make a few tweaks that I didn't expect to make ...
102 views

### Class for managing a list of scores (game development)

For my game that I'm writing, I need, among other things, a data structure for storing best values. For this purpose, I tried to write a class that meets the most general needs, and yet does not seem ...
6k views

### Bubble sort in PHP

Does this code show proper implementation of bubble sort algorithm? If not, why? Can this code further be improved? ...
157 views

### Hackerrank “Almost Equal” solution

I've spent the best part of a day on this question. It is marked as Expert level. There are about fifteen submission test cases and my solution manages to satisfy the first four. However, from there ...
183 views

### Print strings in order with dynamic arrays

I accomplished the following task to practice allocating on the heap. reading words from stdin sorting them in lexicographical order printing the sorted words to stdout To accomplish this is ...
6k views

### JavaScript drag-and-drop sortable list

I made a simple list with drag and drop ordering function using JavaScript, HTML and CSS. Although I tried to do this as efficient as possible, I'm sure there are some improvements to be made. What ...
116 views

### Evaluation of a variation of quick-sort (pivot-selection)

Here is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers. ...
143 views

### Checking whether two lists contain the same elements

I have two lists of numbers: $$\{i_1, i_2, i_3,i_4\}$$ and $$\{j_1,j_2,j_3,j_4\}$$ The problem I want to solve is: Inside a loop, if the following two conditions are satisfied, then it will do ...
63 views

A linked list is a data structure that has a beginning, and an end. The only way through the structure is to go to the "next step", like stepping stones. This linked list works the same way, but in ...
53 views

### Vanilla Javascript code to sort nested tables

I have written a code to sort a main table containing tables in each of its rows. Here I am trying to sort the table by first sorting the rows in each of the main rows and then sorting the table from ...
802 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 ...
303 views

### Finding the nearest agents to a customer using IComparable

I got a C# class: ...
83 views

### Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
164 views

### Bubble sort algorithms and unittest in Python

I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. So far i wrote a post BubbleSort and I drew conclusions and followed the advices. I ...
222 views

### Bubble sort in Python

I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. I would like to get some feedback about my BubbleSort algorithm which I wrote. Also, is there ...
30k 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 ...
468 views

### C++ parallel merge sort

I'm a first year computer engineering student who's learning about algorithms and data structures. I've implemented a parallel merge sort algorithm in C++ and would like constructive criticism. This ...
72 views

### Merge sorted lists

I want to write a function that merges two sorted lists in Python 3. For example: >> merge_lists([2, 5, 9], [1, 6, 8, 10]) [1, 2, 5, 6, 8, 9, 10] My ...
53 views

### Find all k points which are closest to origin

We have a list of points on the plane. Find the K closest points to the origin (0, 0). (Here, the distance between two points on a plane is the Euclidean distance.) You may return the ...
140k views

### Quick Sort - implementation

Can anything be improved in this code? ...
17k views

### Sort numbers in ascending order using Python

This is Python code to sort the numbers in ascending order (It's my school task). How does it look? It works, but I think that this can be improved. ...
66 views

### Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
53 views

### Efficient counting sort for large byte arrays in Java

I have this counting sort for byte values running in linear time with respect to array length: Arrays.java ...
128 views

### Sorting function from a React app to display JSON data in a sortable table

I created this simple react application for a coding challenge, which is described in the linked README file. Basically, I created the components and helper logic to display dynamic JSON data in a ...
53 views

### Quicksort implementation with pivotal calculated as middle element

I read quick sort algorhitm and implemented in like this: ...
223 views

### New Year Chaos JavaScript, needs to be sped up

Similar to this question but this is for Python Original problem with description on hacker rank I am currently trying to iterate through a large number of arrays and count how many times numbers ...
43 views

### Bubble sort in C (for strings)

What do you think of this bubble sorting function in C, for a string array? I would like to improve the readability, performance, and any good practices. ...
1k 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 ...
66 views

### Searching and sorting ranges in excel with toggle buttons

I have a spreadsheet containing ±100 named ranges (5 rows, 15 colums) which are sorted based on time. My plan was to make toggle buttons to hide or unhide named ranges when they contain a certain ...
1k views

### Sorting a list by country name

A couple of weeks ago a company sent me this coding challenge: Please write a PHP web application and send it back to me as zip file: Which waits for a user action, like clicking buttons. ...
253 views

### Sort a list of pairs representing an acyclic, partial automorphism

I have this sample data: let trips = [ { from: "DEN", to: "JFK" }, { from: "SEA", to: "DEN" }, { from: 'JFK', to: 'SEA' }, ]; ...
429 views

### Sort by value in multidimensional array

I have a multidimensional array of house properties: ...
117 views

### Repeatedly keep removing 2 smallest elements and add its sum back to the list and return newly inserted elements' total

I have a list of unsorted numbers. Each time, I need to remove 2 smallest numbers and insert back its sum into the list. Repeatedly do this till the 1 final element is remaining in the list. Return ...
253 views

### Possibly bubble sort algorithm

I'm trying to figure out what to call this sorting algorithm: ...
1k views

### Minimum swaps algorithm terminated due to timeout

I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...
65 views

### Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
131 views

### Implementation of Radix Sort algorithm for sorting integers in c++

I wrote the following code for Radix Sort algorithm for number sorting. Any review is highly appreciated. You can also view and run/test the code here Radix Sort ...
26 views

### Sort an array of strings using bubble sort

I have this following code to sort an array of strings order by ASCII value (alphabetically) using bubble sort. ...
59 views

### Median of three partitioning taking more time than standard quicksort in java

I implemented a standard quicksort and I have a project where I need to improve it. I am trying to make quicksort faster by implementing median of 3 partitioning. I copied codes from trusted ...