Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
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
105 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
113 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
232 views

Timsort implementation in Python

I wanted to implement a Timsort in python. Here's what I've come up with: ...
2
votes
1answer
49 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 ...
4
votes
3answers
176 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
82 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 ...
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 ...
2
votes
1answer
90 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
3answers
622 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
378 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 ...
4
votes
3answers
987 views

Python Bubble sort code

I have written the below bubble sort code in Python. ...
3
votes
1answer
87 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
63 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: ...
3
votes
2answers
24k views

Minimum number of swaps required to sort the array in ascending order

Here is my problem statement. An excerpt: You are given an unordered array consisting of consecutive integers ∈ [1, 2, 3, ..., n] without any duplicates. You are ...
5
votes
1answer
38 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
748 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 ...
4
votes
1answer
288 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 ...
5
votes
2answers
71 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
640 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
47 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 ...
5
votes
0answers
868 views

Bubble sort in parallel

I have done bubble sort algorithm on a vector that is filled with randomly generated values. Bubble sort is actually done with odd-even transition method: ...
7
votes
2answers
123 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
187 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 >...
6
votes
5answers
2k views

Sort an array of 0s, 1s and 2s in Java

Write a program to sort an array of 0's,1's and 2's in ascending order. Input: The first line contains an integer 'T' denoting the total number of test cases. In each test cases, First ...
2
votes
1answer
52 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
42 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 ...
1
vote
2answers
85 views

Sort, & find out duplicates and missing elements in an array

this code is for return duplicates after sorted them, and also to return the missed value between the limits of the given array, it's executed correctly, but i need to optimize it so it excecute ...
8
votes
1answer
276 views

Object-Oriented Sorting Algorithms

I would like a review of a library I've recently published. I realize this is a rather large request, but having looked on meta, it seems this is perfectly on-topic. I'll include a few choice samples ...
3
votes
3answers
2k 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 ...
3
votes
1answer
34 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
36 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 ...
3
votes
4answers
11k views

Sorting dictionary alphabetically

I have this method which successfully sorts the incoming dictionary alphabetically: ...
1
vote
0answers
37 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
66 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: ...
2
votes
1answer
63 views

How to sort and search in JavaScript large set

The array "scores" tells the total points for each person involved in a contest. So for example: ...
21
votes
1answer
2k views

Ford-Johnson merge-insertion sort

The Ford-Johnson algorithm, also known as merge-insertion sort (the name was probably given by Knuth) is an in-place sorting algorithm designed to perform as few comparisons as possible to sort a ...
0
votes
1answer
38 views

QuickSort Algorithm (Python)

This is my implementation of Quick Sort Algorithm : ...
3
votes
2answers
64 views

Unscramble words faster in Python

So I'm currently using python to unscramble words that are retrieved from an OCR program (pytesseract). The current code I am using to unscramble words is this: ...
4
votes
1answer
46 views

Selection sort algorithm in x86_64 Yasm assembler

I returned to study assembly language. And this is actually my first function written in Yasm. Implementing this function is a suggested project from this book. I slightly modified the pseudo code ...
4
votes
1answer
89 views

Code for sorting items in recyclerView

I'm have recyclerView which is needed for displayed for show list of my audio records. I added the ability to sort my audio records. Please take a look at the code that I use for sorting and tell me ...
4
votes
2answers
596 views

Python Merge Sort Implementation

I doing some algorithm reviews and am soliciting opinions on my implementation of the Merge Sort in Python. Anything from readability to optimization is fair game. In particular, I am wondering if ...
1
vote
1answer
50 views

Unscramble words faster in Python

So I'm currently using python to unscramble words that are retrieved from an OCR program, and checked in the 'dictionary'. The current code I am using to unscramble words is this: ...
2
votes
3answers
786 views

How do you “sordid sort” alphanumeric strings?

The question is about sorting alphanumeric string in a "more natural" order. Source: Marc LeBrun's "Sordid Sort" Computist Quiz Often a system string comparison sorts alphanumeric data “unnaturally”...
3
votes
0answers
65 views

Is this a topological sort? [closed]

I am trying to implement topological sort. The idea is that I have a vector of pairs in which the first element is indegree and the second is a linked list. I tried a bunch of tests, they seem to work,...
48
votes
10answers
92k 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 ...
4
votes
1answer
77 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 ...
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 ...
2
votes
2answers
65 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, ...
3
votes
1answer
61 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
2 3 4 5
21