Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
2 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: ...
-1
votes
0answers
8 views

Elegant C++ Quicksort

I was looking at online implementations of Quicksort and was disappointed how many of them seemed to have a low amount of readability. I've written this Quicksort algorithm in C++ with the goal of ...
6
votes
3answers
82 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
64 views

Single Linked List in 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
46 views

In-Place Merging of Two Bubble Sorted Linked Lists

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
60 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
119 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
51 views
6
votes
2answers
78 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(). ...
4
votes
2answers
484 views

Partitioning and sorting even and odd numbers within an array

I solved a problem where it was told to sort an array of numbers such that the even numbers are kept first and the odd numbers should follow. Moreover, the even numbers must be sorted in ascending ...
4
votes
4answers
85 views

MergeSort in Javascript

I implemented the following mergesort algorithm in JavaScript, but I want to know your opinion about if is possible to do better than this. ...
3
votes
2answers
84 views

Descending selection sort in JavaScript

I wrote a simple sort algorithm in JavaScript, but code climate is complaining its complexity being too high (currently sitting on 6 instead of 5, which is code climate wants). I personally cannot ...
2
votes
1answer
42 views

Selection Sort Java -Arraylist

I have implemented selection sort in java using arraylist. This selection sort is only for integers . Please have a look and give feedback. can we improve it ? ...
2
votes
1answer
59 views

Bubble Sort: Time and Space Complexities

Algorithm Bubble sort, also known as sinking sort, is a sorting algorithm that repeatedly steps through a list, compares adjacent pairs and swaps them if they are not in the right order. The pass ...
5
votes
3answers
122 views

I created a sorting algorithm, called Grid Sort

Index & Sorting Index • Counting: when the index, or the position, is dependent on the item. Count from one. (Zero-based index is mathematically wrong.) • Grid: when the index, or the position, ...
4
votes
1answer
67 views

Insertion Sort in C

I have started studying algorithms using the classic CLRS book and decided to hone my C skills at the same time. I wrote this function implementing insertion sort in C. I have tested it and verified ...
3
votes
3answers
617 views

JavaScript Sort Stack Coding Challenge

A coding challenge to write a function sortStack that receives a stack of integers into ascending order (with largest integers on top) and returns another stack ...
2
votes
1answer
34 views

Naive implementation of sort inplace

I had the following assignment for the Python 101 course I'm taking in my university. ...
9
votes
5answers
958 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> ...
3
votes
1answer
76 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? ...
0
votes
1answer
39 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? ...
1
vote
1answer
63 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? ...
2
votes
2answers
151 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 ...
6
votes
3answers
112 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 ...
2
votes
0answers
55 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 ...
3
votes
0answers
69 views

Sorted LinkedList

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 ...
6
votes
3answers
312 views

Finding the nearest agents to a customer using IComparable

I got a C# class: ...
2
votes
1answer
171 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 - ...
4
votes
2answers
74 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 ...
2
votes
2answers
60 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 ...
2
votes
0answers
56 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 ...
2
votes
3answers
537 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 ...
1
vote
1answer
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. ...
9
votes
5answers
254 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' }, ]; ...
5
votes
3answers
121 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 ...
4
votes
2answers
255 views

Possibly bubble sort algorithm

I'm trying to figure out what to call this sorting algorithm: ...
7
votes
0answers
81 views

Engineering an even faster qsort

I understand that C++ STL template sort runs faster than qsort in C because ...
6
votes
2answers
556 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 ...
1
vote
0answers
29 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. ...
3
votes
1answer
135 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 ...
1
vote
0answers
64 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 ...
1
vote
0answers
57 views

Median of 3 partitioning taking more time than quicksort in java

I have a quicksort code in java which I want to improve. The improved code should take less time than the quicksort code. However when using my improved code which implement median of 3 partitioning, ...
2
votes
1answer
80 views

Finding maximum homework grade ECOO 2018

I'm trying to solve ECOO 2018 round 2(regionals) question 2 to prepare for the upcoming contest. Basically, in the question George has to achieve the maximum possible grade by completing the right ...
2
votes
1answer
26 views

Using deftype to create a wrapper class for byte arrays

I want to create a wrapper class for byte arrays so that I can use them as keys in fastutil's Object2LongAVLTreeMap. I have ...
1
vote
0answers
45 views

Sorts (merge, quick, bubble) in Python

I'm new to python, and I wrote the following code. Please review, critique and enhance. This project compares quicksort, mergesort and bubblesort write/test the partition routine for ...
0
votes
2answers
163 views

Counting sort in Swift

I have this sorting algorithm which takes an array of dictionary values: guard var imageUrlString = anyImage.value as? [String:AnyObject] else { return } I then ...
0
votes
0answers
22 views

Priority URL queue that does not block on put()

I am trying to build a priority queue that never blocks on put(), and discards the lowest priority item if it is full and user attempts to ...
2
votes
1answer
59 views

Sorting an assortment of strings and integers together, while keeping them separate

I put a solution to this coding problem together. The problem is this: Create a function that takes an array, finds the most often repeated element(s) within it and returns it/them in an array. The ...
0
votes
1answer
57 views

Time complexity of radix sort

I read time complexity of radix sort is O(wn) or O(n log n), if all n numbers are distinct. After implementation it look to me as if I have implemented radix sort which has time complexity of O(n ^2). ...
5
votes
1answer
69 views

Sorting words by frequency

I'm doing a simple task in Rust after reading the Rust book: read a text file split it at whitespace sanitize words by removing non-letter characters sort the words by their frequency of occurrence ...