Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
2
votes
2answers
30 views
3
votes
1answer
41 views

Programming Pearls — Column 1: Sorting unique numbers with bitfield

I've implemented a simple program to sort an input of unique numbers given as decimals on a separate line. The idea is, since all numbers are unique, to use a (long) bitfield where a 1 on index n ...
0
votes
1answer
24 views

Calculating ordered differences between elements in vector

Input I start with a vector of integers or floats, e.g.: [10, 100, 20, 5, 50] Output I want to return a list of differences or "deltas" between elements ...
3
votes
1answer
71 views

benchmarking sorting algorithms: std::sort vs my naive radix

I'm comparing performance of two sorting algorithms applied to sort integers using google benchmark. I'm quite surprised by the results so wanted to ask if you see some mistakes in the way I measure ...
1
vote
1answer
129 views

MSD Quick Radix Sort in Place in C++, Object/Pointer Oriented

Memory: O(log2(max)*2)~O(1) Speed: O(log2(max)*n)~O(n) so i did before a MSD Radix Sort in place but i wanted to do one, with out the count, So i join together the quick sort and radix sort. Think as ...
1
vote
1answer
46 views

Binary Radix Sort implementation on linked list

I am trying to implement binary radix sort in C which sorts a linked list of integers stably. Although my algorithm has a time complexity of O(log2(k).n) (where k ...
0
votes
1answer
90 views

MSD Radix sort in Place in c++, Object/Pointer Oriented

Memory:O(log(max)base(mod)*mod)Speed:O(log(max)base(mod)*n) I did a radix sort in place to not get a auxliar array. In the process i discorver a few things. Is imposible to do LSD radix sort in place ...
1
vote
1answer
103 views

Read and sort 100 numbers from a text file

The program itself reads 100 values from a text file named input.txt. Then sorts those values in ascending order and writes the values to a new file called ...
0
votes
1answer
83 views

Big Sorting - Performant Sorting

Consider an array of numeric strings where each string is a positive whole number. Sort the array's string elements in ascending order of their numeric values, and return the sorted array. Return: ...
0
votes
0answers
12 views

Simple Parallel Sorting

i had made a simple parallel sorting for my personal games. it did well so far, but i would like to get some advises about how to improve it further or perhaps there are an alternative methods for ...
3
votes
2answers
76 views

Sorting a list but the sort order isn't known until runtime

I need to sort a list of strings that I'm reading in but the sorted order of that list is not predetermined (I can't hard code it); I read in the sort order from a source and build a comparator by ...
2
votes
2answers
86 views

Sorting program code

I have done a sorting program, it works but I am new to the coding world and I would love to hear your thoughts. ...
5
votes
3answers
173 views

Sorting Nested Array

Recently on SO there was this question i am trying to get sequence index of each array of array like I have an element of the array and that 5 arrays have multiple elements and I want to get the ...
0
votes
0answers
34 views

Sorting Algorithm Visualiser in React with TypeScript

This code animates sorting algorithms in the browser. I've included all the React components I've used and left out the individual sorting algorithm implementations. SortingVisualiser.tsx ...
2
votes
0answers
46 views

Covid-19 World Case Report Beta 0.1

I am a self-learned programmer and this is my first program. I would really appreciate any critique on my approach. The program should automatically download the who data file to the folder these ...
2
votes
0answers
57 views

PowerShell - Sort strings containing numbers numerically

I am a newbie in programming, but I do have potential, I am using PowerShell to hone my skills, I have written a simple function to sort strings consisted of numbers humanly (i.e. in a order like 1 2 ...
4
votes
1answer
126 views

Performant Sort function for big arrays

In sort(arr), I want to sort an array. Children must be beneath their parent. And children of the same parent are sorted using ...
4
votes
0answers
96 views

Sorting Algorithm (from scratch) in Python

Updated (at the bottom) I am attempting to write a Python program where I have to create a sorting algorithm without the assistance of the built-ins (like the sort()...
1
vote
1answer
46 views

Pandas DataFrame.sort_values() new method to exclude by row name

I was working on new function with Pandas DataFrame. It's meant to sort values by column name but exclude specific rows from sorting and return sorted dataframe with that has rows with preserved ...
-1
votes
2answers
74 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 ...
3
votes
3answers
134 views

Remove duplicates from array and save it to another one

So 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: ...
3
votes
1answer
46 views

How do I optimize the bubble sort in Assembly8086?

I tried to implement bubble sort in Assembly 8086. ...
5
votes
2answers
99 views

Best way to find the largest sorted suffix in a list - USACO Sleepy Cow Sorting Python

Solving this problem. Right now, my solution entails finding the largest sorted sublist, starting from the beginning, all the way to the end. However, I feel like the way I wrote the ...
4
votes
1answer
145 views

Hybrid Merge/Insertion sort algorithm

Explanation: Although merge sort runs in Ω(nlgn) and insertion sort runs in Ω(n^2), the constant factors in insertion sort can make it faster in implementation for small problem sizes. This sorting ...
1
vote
2answers
87 views

Sorting string with if-else

I was asked to write a program that sorts three strings alphabetically using only if-else (no sorting algorithms, usage of arrays whatsover). I'm fairly new to C++ programming but I've come up with ...
4
votes
1answer
84 views

Scheduling COVID-19 testing in a hospital using a heuristic

I recently came across a problem scheduling Coronavirus testing at a hospital; the testing capacity needed to be allocated to: high risk wards (combining many factors) ones which hadn't been tested ...
14
votes
3answers
2k views

Python3 - merge sort, O(n) space efficiency

Any critique of my implementation of Merge sort would be much appreciated! I tested it using a driver function (shown below), and everything works. However, it still feels unwieldy, I am a beginner ...
3
votes
2answers
292 views

Football management game in C++

Recently, I have been working on a College Football Manager game, in which you coach a team from the ground up. I have successfully made it to where you can win games, lose games, and change your team ...
4
votes
2answers
123 views

Merge/Insertion sort program taking longer than an hour to finish - C++

My program uses merge and insertion sort to sort a set of numbers. It works perfectly fine for small inputs, less than 2 seconds for 1,000 ints. But I need to sort 1,000,000 ints. When I try with 1 ...
2
votes
1answer
83 views

Interview Coding Test: Transaction Processing: Find Duplicates

I had given a coding test for a job which failed. It had two problems and one of them is shared in this question along with my solution and other I already posted at this link. Problem: Find duplicate ...
3
votes
1answer
90 views

Mergesort in python

My mergesort implementation currently takes a very long time, for a list with 1 million elements it takes over 130 seconds to get the list sorted. Could someone kindly have a look at my code and ...
4
votes
3answers
183 views

My insertion sort version

I'd like to know what you think of my insertion sort version. I tried to be pythonic and avoid while loops with "ugly" index-management: ...
3
votes
1answer
76 views

Sorts and data structures: a bucket sort

I am currently going through and implementing basic algorithms and data structures as I feel I didn't learn enough about this during my Data Structures and Algorithms unit. So far I've done the ...
3
votes
3answers
689 views

Sorting an array of integers in C++

This is a follow up to my previous post as it contained a lot of errors and wasn't accurate. I am using the Bubble sort algorithm to sort an array of integers and I would like to know whether I could ...
2
votes
4answers
421 views

Sorting an array in C++ using Bubble sort

Here is my bubble sort algorithm that I would like to improve in any way possible ...
3
votes
1answer
90 views

Bubble Sort In C++

I'm learning modern C++ and also algorithms, and am doing some practice by coding up some simple algorithms. Also trying to use templates whenever possible as I'm quite unfamiliar with generic ...
4
votes
2answers
65 views

Move two element of an array to the front - Javascript

I want to move two element of my array to the beginning. This solution works but I would like to know a better approach since using sort() twice is probably not the best. Array Input: ...
5
votes
1answer
43 views

Selection Sort Java and Analysis

I have written a selection sort code in java. I know its very elementary algorithm, but since i am learning, so wanted your input about the quality of the code. Please have a look at the code: package ...
10
votes
4answers
795 views

Insertion sort vs Selection Sort benchmarking

Over on Stack Overflow, I read an answer asserting that Insertion Sort was inferior to Selection Sort for array data (as opposed to linked list data) on account of the larger amount of data movement ...
5
votes
2answers
103 views

Sorting algorithm visualizer in C++ and SDL2 Improved

Original post: Sorting algorithm visualizer in C++ and SDL2 I followed the advice you gave me and improved my code. I also added two more sorting algorithms. I'm mainly looking for code readability ...
19
votes
1answer
815 views

Sorting algorithm visualizer in C++ and SDL2

I finished a sorting algorithm visualizer (for now only uses bubble sort) and this is the code. I'd like some suggestions to improve the memory usage or time elapsed. Built with Cmake and Ninja on ...
2
votes
1answer
49 views

Filtering out, a list of games, based on their followers

so I am playing with Rawg.io 's API. U can sort their game list by their release date, however there are just too many games. In their website, there's an option called "Popular only", which ...
7
votes
2answers
126 views

Determine the complexity of sorting a binary array

The challenge is to sort an integer array containing only ones and zeros with the lowest complexity possible. As always, I am interested in any improvements suggested but in this question I am most ...
5
votes
1answer
202 views

ZigZag array implementation

I have implemented a zigzag array which will sort smaller greater smaller and goes on... For example : 3 7 4 8 2 6 1 is a valid ordering. The relationship between numbers is 3 < 7 > 4 < 8 >...
2
votes
1answer
81 views

Generic sort function

I'm building a functional React component that allows a list of products to be sorted by various properties. The properties could be top-level or nested properties. And I'd also like a sort order to ...
2
votes
1answer
44 views

Leet code Majority element

Problem :- Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority ...
3
votes
1answer
35 views

SelectionSort Algorithm using Python

I am a rookie and I need help optimizing this SelectionSort() algorithm which I have tried using Python. ...
4
votes
1answer
47 views

Bubble Sort in Forth (for strings)

I wrote the following Forth code for sorting a string with the Bubble Sort method. It looks nice to my eyes, but I'd like your experienced opinion and any comments about the code you might have. In ...
1
vote
0answers
41 views

Sorting Algorithm Visualiser in Javascript

I'm new to Javascript and Web Dev in general, so they'll likely be some conventions that I'm not aware of. I'm at an odds of whether to use Javascript's functional features more. In my opinion it's ...
2
votes
0answers
69 views

Python's quicksort algorithm

I was playing around with sorting methods, brushing up on my algorithms. I have made the following implementation of quicksort: ...

1
2 3 4 5
22