Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
45
votes
10answers
83k views

Given an array of integers, return the smallest positive integer not in it

Write a function: function solution(A); that, given an array A of N integers, returns ...
3
votes
1answer
60 views

CLRS implementation (opportunity to sort subarray) of merge sort in golang

I'm reading "Introduction to Algorithms" by CLRS and I can't find an implementation of the pseudo code from the book in golang. By the original implementation I mean that we deal with extra parameters ...
0
votes
0answers
47 views

Python - Selection Sort [closed]

I tried to create my first sort algorithm, selection sort, using Python. What do you think? from typing import List ...
5
votes
3answers
3k views

Sort characters in a Python string by frequency

I wrote a solution to the leetcode problem Sort characters by frequency and the solution passes 34/35 test cases. On the last test case, there is a "time limit exceeded" error with an input string of ...
1
vote
2answers
52 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
1answer
85 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 ...
3
votes
1answer
50 views

Bubble sort visualization: JavaScript

I'm very new to the JavaScript, and hence I would like to get a feel on the language by writing some of the basic programs. One of those is the following visualization of the Bubble Sort: Code: <...
1
vote
1answer
62 views

Bubble Sort Implementation | C-ish and Modern C++

For practice purpose, I wrote bubble sort in C++ two styles: C-ish and modern C++ compliant. I would like to have your comments on any point on these implementations. ...
2
votes
1answer
33 views

Merge Sort Implementation Efficiency In Python

I wasn't able to find a standardized source for a working example of Merge Sort. Each learning site had a slightly different take on the algorithm implementation, disregarding the bottom-top ...
3
votes
1answer
42 views

Insertion Sort Implementation Efficiency

Is my approach to insertion Sort in Python efficient? What can be improved efficiency wise? ...
2
votes
2answers
32 views

Radix sort is deceiving

I wanted to compare radix_sort to quick_sort for values limited to 0..127 so I implemented this : ...
4
votes
2answers
79 views

Merge Sort in C

I implemented mergesort in C as an exercise. I have two main questions: Is the code future-proof? 2.1 Will I have problems modifying it to sort float and double? 2.2 What could be problematic for ...
1
vote
0answers
52 views

Reading 100,000 of data with loop and usort is too slow [closed]

The below code is meet to solve the question posted here https://stackoverflow.com/questions/61302983/in-a-meetup-schedule-algorithm-to-get-unique-and-available-date, but I can't post it as a solution ...
2
votes
1answer
207 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 ...
2
votes
1answer
55 views

C++ Sorting Filenames In A Directory

I wanted to have some advice about the code I have. I managed to get what I wanted done, but I do not think it is the "proper" way of doing it in the programmers' world. Could you help me improve ...
2
votes
1answer
74 views
4
votes
2answers
2k 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 ...
5
votes
3answers
3k views

Bubble sort in Haskell

The following code is part of my practice in implementing algorithms in Haskell. I'm aware that bubble sort is a bad choice for sorting sequences in real applications. ...
3
votes
1answer
64 views

C# Quicksort Assignment

For my CS minor I was assigned to implement the Quicksort algorithm in C#. I gave it a go and found that I like the implementation of the algorithm more than Mergesort. Now that I've got my Quicksort ...
1
vote
1answer
29 views

Heap selection sort in Javascript

I have (designed and) implemented this fancy sorting algorithm that combines natural runs in the input array with a heap data structure: ...
6
votes
2answers
575 views

Nearest Neighbor Algorithm (general nearest, forward-nearest, or backward-nearest)

I am trying to write an algorithm that can find user-specified nearest neighbors. By user-specified, I mean that the user can specify whether it's a general nearest neighbor, a forward-nearest ...
3
votes
1answer
55 views

Python implementation of Kahn's Algorithm

Please provide any suggestions on the below code for Kahn's algorithm. Can it be implemented in a better manner, or be improved: ...
3
votes
1answer
6k views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
6
votes
2answers
331 views

Creating and listing a song collection

Songs Class: ...
5
votes
1answer
93 views

Tarjan's Algorithm Python Implementation

I'm planning to use Tarjan's algorithm for a program in which I would be processing a file, converting the processed data to a dictionary, doing a topological sort on that dictionary (using this ...
3
votes
2answers
92 views

My C++ sorting algorithm for vector

As I'm learning c++, I decided to implement my own sorting algorithm. As I'm a beginner I didn't use any template to be able to use them for different types of variable and they can only sort item in ...
5
votes
1answer
9k views

Directed acyclic graph with topological sort

I have here a class which represents a directed acyclic graph (Graph) and a vertex in the graph (Vertex). The vertices are ...
7
votes
1answer
107 views
3
votes
2answers
87 views

Heap Sort in Python

NOTE: I am beginner in Python I learnt the Heap sort today and tried my own implementation using Python. Can i get feedback for my code and areas of improvement. I have tried to add comments inline, ...
-2
votes
1answer
31 views

Selection sort in C

...
4
votes
1answer
86 views

Inserting Elements Into a Sorted Array

Very new to JS (wrote my "Hello World" around 3 days ago), but not to programming in general. My documentation is inspired by the approach I followed for Python (since I haven't learned JS ...
10
votes
3answers
3k views

My approach to sorting algorithm

For practicing purposes, I had the idea of making a sorting algorithm in Python. My approach to it was to iterate through a given unsorted list to find the shortest number in it, add the number to a ...
2
votes
1answer
131 views

Testing the Dutch national flag task

I recently coded the Dutch national flag problem in Java and wrote some tests. The array in zero-indexed. Please take a look at how I verify that elements of the output array are in the right order. ...
2
votes
0answers
56 views

Construction of external sorts from comparison ones

Here's an example how to construct an external sorting algorithm from the Quicksort. The method may be applicable to other known internal comparison sort algorithms. I have checked that it shows N*...
1
vote
1answer
84 views

Novel sorting algorithm

I have devised a novel sorting algorithm, named Oracle Sort, which I believe is far superior to all currently known sorting algorithms (under certain assumptions). It utilizes an oracle to achieve a ...
1
vote
1answer
60 views

Simple sorting algorithm speed

I was working on an assignment in my Python class to sort 10 numbers but I wanted to be able to sort any set of numbers be it large or small. The assignment didn't really cover any sorting algorithms ...
2
votes
3answers
610 views

Sorting a list in ascending/descending order with a button toggle

I have this piece of code written as a function to handle a button-toggle for sorting a list in ascending and descending order. Below is the code which is working as expected, but I would appreciate ...
4
votes
1answer
124 views

Reverse quick sort in Fortran

I have written a quick sort routine to inplace sort an array in descending order: ...
-1
votes
2answers
62 views

sort a list with equivalence classes [closed]

I'm trying to optimize the following function f, written in python. It is a function of an integer k. First it calls another ...
4
votes
0answers
79 views

Rust Iterative and Recursive Merge Sort Implementation

I'm in the process of learning both Rust and algorithms after primarily focusing on web development. As such I've had a go at implementing merge sort both iteratively and recursively. I've looked for ...
2
votes
2answers
87 views

Sorting multiple vectors based on a reference vector

I am trying to sort vectors based on a reference vector. First I am getting the indexes for the reference vector and then using that I am doing inplace sorting for the rest of the vectors. ...
1
vote
2answers
985 views

Bubble Sort and Selection Sort (C)

I used the "long" form of all math statements, avoided the use of pointers, and used only while loops for aesthetic purposes (simply put, I think the code is prettier when it is written like that.) I ...
4
votes
0answers
53 views

Opinion on a small app I created using JavaScript

Recently I created a small app using JavaScript, and I would love for some JavaScript developers if they have the time of day, to tell me their opinions so I can grow and improve. I'm mostly working ...
6
votes
1answer
179 views

Animation of sorting algorithms

I have created a visualisation of sorting algorithms using tkinter and matplotlib. Please let me know what you think and if you have any suggestions or find errors. The aim of this code is to create ...
6
votes
1answer
425 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 ...
3
votes
2answers
51 views

Reduction of time for the code of sorting RGB and Depth images according to timestamp values

I have RGB Images, Depth images and OpenPose Images(generated from RGB Images). The number of RGB and Depth images are different so I have to find the exactly which RGB images corresponds to which ...
1
vote
0answers
256 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 ...
2
votes
1answer
100 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 ...
4
votes
1answer
338 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 ...

1
2 3 4 5
21