Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
2
votes
0answers
54 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*...
11
votes
3answers
2k 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 ...
1
vote
1answer
73 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
55 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
433 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 ...
-1
votes
2answers
60 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 ...
2
votes
2answers
82 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. ...
4
votes
0answers
62 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 ...
1
vote
2answers
977 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
52 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
103 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 ...
3
votes
1answer
83 views

Reverse quick sort in Fortran

I have written a quick sort routine to inplace sort an array in descending order: ...
0
votes
0answers
35 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 ...
6
votes
5answers
149 views

Implemented command-line based merge-sort algorithm. How can I make the code efficient, robust, maintainable, secure?

This is follow up question regarding merge-sort implementation to the previous post. Recently I have implemented a command-line argument based merge-sort sorting algorithm. Format for command-line-...
2
votes
2answers
59 views

Bubble Sort with tests

I've become a bit rusty in Java. This is an attempt at brushing up my skills. Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the ...
3
votes
2answers
48 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 ...
3
votes
2answers
87 views

Merge sort implementation in python 3

I have implemented a Merge sort in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
2
votes
1answer
65 views

Timsort implementation in Python

I wanted to implement a Timsort in python. Here's what I've come up with: ...
4
votes
3answers
98 views

Finding sequential recurrences in a list of numbers

I have a list like this: seq = [-2,3,-2,3,5,3,7,1,4,-5,1,4,-5,1,4,-5] I want to get all the sequential recurrences and where it happens, I feel the way I'm doing ...
6
votes
2answers
111 views

Bubble Sort Implementation in Python 3

I have implemented a Bubble Sort. It works well. But if you think something needs to be improved, say it. This code was tested in Python 3.7.4. ...
0
votes
1answer
55 views

Complexity of bubble sort

I have a simple integer sorting problem at hand and to solve it, I am planning to write a variation of bubble sort. It seems to be working fine but I am not sure about it's complexity in big-O. What ...
3
votes
2answers
125 views

Simple BubbleSort in GoLang

I'm just starting in Go. Please review the below code, and let me know what I can improve in this code. ...
4
votes
1answer
56 views

Merge Sort from Scratch in Python

I built a merge sort in python just to have a more thorough understanding of how the algorithm works. What I have written works fine, but I assume there is room for improvement and ways to make my ...
7
votes
3answers
538 views

Checking an array is sorted in either order efficiently

Here is my code, it works fine, just wondering if there any anything to make it even better. ...
1
vote
0answers
72 views

Python Bubble sort

...
0
votes
0answers
50 views

Bubble sort optimization

This bubble sort code is very slow compared to the original. ...
5
votes
1answer
214 views

Timeout Error in Fraudulent Activity Notification HackerRank

I am solving this problem: Fraudulent Activity Notifications on HackerRank. I am done with my code and is working, but it is inefficient as well for very large inputs. I don't know but after all ...
3
votes
1answer
46 views

Quick Sort implementation in python

Implemented the quick sort algorithm in python, It was just for learning it, now I want to port it to C. Thoughts on the quality of my python implementation? ...
7
votes
2answers
101 views

Quick Sort Implementation with iterators

Most quicksort examples online use C-style arrays and indexes. I have written below quicksort implementation with STL style iterators. It looks fine to me, but I feel like I may be making more than ...
4
votes
2answers
176 views

Heap Sort and Binary Tree Sort Algorithms (Python)

Heap Sort A Binary Heap is a Complete Binary Tree where the items are stored in a special order such that the value in a parent node is greater or smaller than the two values in the children nodes. ...
3
votes
2answers
593 views

Binary Tree Sort Algorithm (Python)

A Binary Tree Sort is an algorithm that builds a binary search tree from the elements to be sorted, and then traverses the tree (in-order) so that the elements come out in sorted order. Average Case ...
6
votes
2answers
346 views

Selection Sort Algorithm (Node.js)

I wanted to implement a selection sort and wanted to make sure that I'm doing it correctly. I wanted to do it in a way that's efficient and use recursion. Please let me know if I am doing this ...
3
votes
1answer
63 views

Quick Sort Algorithm (Python)

QuickSort is a Divide and Conquer algorithm, which picks an element as "pivot" and partitions a given list around the pivot. There are many different versions of Quick Sort, as to how to pick a pivot ...
3
votes
1answer
147 views

Iterative Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Here, our ...
3
votes
0answers
57 views

DataManager Class: Sorts Array by 1 or More Dynamically Added Columns in Ascending or Descending Order

I've been struggling to write a QuickSort algorithm to sort multiple columns of an Array for weeks. Finally, I decided to write a class that Implements mscorlib.IComparer and it has exceeded my ...
3
votes
1answer
112 views

Recursive Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Just for ...
2
votes
1answer
215 views

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms

There are seven sorting algorithms in the code copied below. The first five algorithms have been previously reviewed in this link. Selection Sort The Selection Sort algorithm sorts a list by ...
13
votes
4answers
2k views

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms (Python)

There is a follow-up question available: shell-sort-insertion-sort-bubble-sort-selection-sort-algorithms-python. Selection Sort The selection sort algorithm sorts a list (array) by finding the ...
2
votes
1answer
70 views

LeetCode: Queue Reconstruction by Height C#

https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers \$(h, k)\$, where \$h\$ ...
2
votes
1answer
90 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 ...
8
votes
2answers
831 views

Selection Sort Algorithm (Python)

Selection Sort The selection sort algorithm sorts a list 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 ...
5
votes
1answer
64 views

An alternative algorithm for sorting a stack using only one additional stack

From "Cracking the Coding Interview": Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you may not copy ...
6
votes
3answers
1k views

LeetCode: Top K Frequent Elements C#

https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/799 Given a non-empty array of integers, return the k most frequent elements. Example 1: ...
6
votes
3answers
97 views

Quicksort for ints

I have written the following quicksort without using online help. It seems to be fine, but is there anything to improve? ...
1
vote
1answer
88 views

Single Linked List (Python)

I'm following a tutorial on Single Linked List (SLL). There are so many methods in the code, if you had time please feel free to review any part of it and I can work on it and repost it. I'm ...
2
votes
1answer
53 views

In-Place Merging of Two Bubble Sorted Linked Lists (Python)

I'm following a tutorial on merging two bubble-sorted Single Linked Lists in Python. merge1 does the merging by creating a new list with maybe \$O(N+M)\$ memory ...
3
votes
1answer
83 views

LINQ for extracting N bottom items (async streams)

source.Bottom(n, x => x) should be the same as well known LINQ source.OrderBy(x => x).Take(n) but is more memory/run-time ...
5
votes
2answers
135 views

Quick Sort in C

I'd like to know if there's any issues with this implementation of qsort_r (which is not available in all implementations, so I'm trying to provide one that allows ...
4
votes
1answer
67 views

Sorting email address according to occurrences of each domain

My code: ...
6
votes
2answers
180 views

Quicksort with Insertion Sort and Improved Pivot Selection

Here's a Quicksort I had fun writing and improving, so I thought I'd post it here. In my (brief) testing it's about 15% to 20% faster than Java's Arrays.sort(). ...

1 2 3 4 5 20