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
11 views

Quicksort Invariant and steps to determine correcteness

I am having trouble with applying to 3 steps needed to proof correctness, most likely because I did not formally study CS or Mathematics and am still learning about loop and class invariants. The ...
1
vote
4answers
93 views

Sorting based on multiple fields using IComparer

I use the below code to sort List<DataAccessViewModel> list. Here is the sort order : PriorityScore ...
0
votes
0answers
31 views

React filter-and-search algorithm

Currently working on a website with the following sorting function, but it's slow and reloads several times when I search for someone; how can I improve its performance? Or, more importantly, which ...
2
votes
2answers
57 views

Function to find substring in a list of strings and add them to the resulting list

I am trying to look for a substring in a list of strings. My end result is an array that contains the presence of substring first based on course.name and then ...
2
votes
3answers
101 views

Sort one array base on another array

The problem is as below: Two archery teams A and B compete with the same number of members. If the score of team A[i] is higher than that of team B[i], the total score of team A will be +1, so given ...
5
votes
3answers
264 views

Counting swaps in a sequence sorting algorithm

I have been working on this question, https://open.kattis.com/problems/sequences. You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are n ‘?’s. ...
3
votes
1answer
76 views

Quicksort using generics in java

The goal is to have a function that can sort a series of all object types that implement the comparable interface. I'm not trying to improve the performance of the sort. I'm only trying to optimize my ...
0
votes
1answer
47 views

custom array sorting algorithm

So I came up with a "new" sorting algorithm: ...
3
votes
1answer
61 views

Sorting algorithm in the element cost model Python

1. Task Using standard input I read four rows of data: number of elements (elements are numbered from 1 to n) n numbers corresponding to cost of moving each element n numbers corresponding to current ...
0
votes
2answers
61 views

Sort table with ascending or descending order without a library

This is my first day coding, and I need help with sorting a table in ascending/descending order. The idea is that when a column is clicked it will sort in ascending order, and then it is clicked again ...
1
vote
1answer
86 views

Find Kth Element in the merged two sorted arrays?

We have been given two sorted arrays and a number K . We have to merge the two sorted arrays in the sorted manner and return the element at the Kth position. My approach is to use two variables ...
2
votes
2answers
73 views

Sort array of dates

I have this array with dates. All the dates are checked before creating the array with preg_match and check_dates. GoodDates ( ...
4
votes
1answer
153 views

recursive bin packing

For the company I work for we spec lengths of tube of varying lengths. For a given project let's say there is a list like this 100', 115', 105', 205', 195', 240', 240', 130', 180', 140', 225', 85' ...
2
votes
2answers
161 views

Using JavaScript, given a JSON value, recursively find all JSON objects, then sort keys in-place

Some background: JavaScript is not my primary language, so I'm looking to get some constructive criticism here. I built a tiny single page HTML app that pretty prints JSON text. It's very useful when ...
0
votes
0answers
43 views

GUIComparer with MVVM dialog to allow user input in ArrayList sorting algorithm

download Bit of an esoteric title, but let me explain. I wanted to create an IComparer that can be supplied to a sorting algorithm, which rather than using the ...
0
votes
0answers
16 views

Bayesian ranking of fanfics with python and sqlite

I've done a script to sort fanfics by the bayesian average of views and rating. I've used views because it took much longer to scrape the dlp website for reviews. I leave all the code so that it works....
2
votes
2answers
118 views

Sort three numbers

So, I wrote this function to sort three numbers in Julia. Any feedback on readability, performance, and Julian-ness would be appreciated. ...
6
votes
1answer
1k views

friend locator app

I was rejected after a tech screening for the following code. I mainly struggled to make the code 'production ready'. I was running out of time so I did not create a class for testing. How could I ...
1
vote
1answer
118 views

C++ vector bubble sort in my edition

I made a small adaptive function that sorts vector: ...
2
votes
0answers
69 views

In place dynamic array sorting without using extra memory

I seek critique on a sorting implementation for a dynamic array data-structure. Design decisions Uses the quicksort algorithm. Uses an optimized XOR swap for swapping the elements. XOR swap doesn't ...
3
votes
0answers
71 views

I recently wrote sort of structs in golang

I am a bit concerned about style (functions, variable names, spacings, etc.). I am also not sure about whether I should return error or panic. What do you think? ...
1
vote
1answer
41 views

I have a query like this that seems complicated and I want to do it by using Java Stream Api

I have method that fetches sorted and filtered data from Mysql Database, Firstly I had done It by using Java. Now I did it by Mysql but I don't like the way the code looks I have entity that named ...
2
votes
2answers
61 views

Trying for an efficient and readable heap-sort implementation

I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately. ...
3
votes
3answers
68 views

Trying for an efficient and readable merge-sort implementation

My first implementation of merge sort in C++. I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately....
3
votes
3answers
63 views

PHP Sort Associative Array first by relativity of value then by other value desc

I am trying to sort an associative array by following this scheme: Sort by 'qt': positives first, non-positives after. Magnitude does not matter, only sign. In positive part: sort by sa DESC In ...
3
votes
2answers
154 views

Sorting an array of positive integers including 0 much faster than Radix Sort

I was working on an Limit Order Book structure in JS and came up with this algorithm. I am pretty sure this must have already been implemented but couldn't even find a clue over the web. The thing is, ...
2
votes
0answers
73 views

How to make this algorithm faster. Calculates and searches through large arrays

Ive got this algoritm thats "complex". The comments in code give examples of how large the various data types could be. My cpu usage is less than 10% when running this and ram usage is good. ...
2
votes
1answer
67 views

Generating a performance report for clans in Clash Royale

The following code generates a report showing performance of clan members in a game called Clash Royale. Everything is pretty self-explanatory, we are working with a lot of https requests, arrays and ...
0
votes
2answers
74 views

Is my Insertion Sort optimal?

I'm learning sorting algorithms and wrote my own implementation of Insertion Sort. Is it optimal? Is there anything that can be done better? ...
2
votes
1answer
90 views

C++ Incredibly Precise Sorter | Efficiency and speed of sorting algorithms

Hey Guys, I'm in the process of building a console program in C ++ that allows users to: sort a sequence of numbers loaded from a TXT file save sorted sequence in a new TXT file measure the sorting ...
11
votes
6answers
3k views

Mergesort Criticism in C

I have written a merge sort in C and would like any advice on how to improve it. Any advice helps to make the code better! ...
2
votes
2answers
250 views

Recursive function for bubble sort

I often see nested loops as a solution to the bubble sort, but my solution involves a recursive function. Is the following solution less efficient than the traditional method? ...
1
vote
1answer
54 views

Insertion Sort- inserting from the left

I've implemented my own insertion sort algorithm, and here's the code. ...
3
votes
0answers
51 views

Breadth First Search Block Puzzle

I am creating a program that will be given a text file as output with the board's dimension and the piece id along with the piece width and length. The goal is to arrange all blocks in the board ...
2
votes
2answers
101 views

Sorting alphabetically ascending and descending using .sort()

I have created this basic use case of .sort() for my own reference. I am asking for a review to see if there are bad practices present or areas that could be ...
3
votes
0answers
147 views

Quicksort using Lomuto partition scheme in C

This is my implementation of the divide-and-conquer Quicksort algorithm using the Lomuto partition scheme in C. This is part of a personal project and I'm following Linus Torvalds's coding style. <...
0
votes
1answer
110 views

Array member set its own index in the array

I'm writing a code where a class member, if != -1, set its own position at array. If the value is == -1, the next free index (whose range is 0 too array's length) is used. In this review, I'm more ...
4
votes
2answers
54 views

Radix Sort Speed

I have implemented a radix sort algorithm in Python 3. It first finds the maximum number of digits in the list, then changes them to strings and adds 0's. For example, [7, 23, 107, 1, 53] to ['007', '...
5
votes
1answer
119 views

Quicksort Algorithm Speed

I have made a sorting algorithm in Python 3. This sorting algorithm is a modified optimized median of 3 quicksort, with network sorting for lists of size up to 16 and for finding the median. I have ...
0
votes
1answer
58 views

C.Insertion sort with guard

I have already addressed this issue and corrected something .really..now the graph looks different Please tell me if the program works correctly?You can see the results in the picture above.I will be ...
0
votes
3answers
432 views

sorting vector of pair in efficient way

I'm trying to solve the sorting problem but I always get TLE(Time Limit Exceeded/ 1s) so... can you guys suggest a more efficient way to solve this problem? (i can't link the exercise because it is on ...
13
votes
3answers
2k views

Count word frequencies, and print them most-frequent first

I'm writing a comparison of a simple word-counting program in various languages. The task is to count the frequencies of unique, space-separated words in the input, and output the results most ...
1
vote
0answers
55 views

Making This "Fancy" Sort Algorithm a Little Better

This is my code: ...
2
votes
0answers
31 views

Sort items so that parents are created before their children

I've been asked to create some code to help automate the loading of data into a system based on employee data in a spreadsheet. However, the data isn't clean, so some people may have no manager, some ...
2
votes
3answers
73 views

Read and sort an array of integers

...
3
votes
1answer
70 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
27 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
92 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
147 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
66 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 ...

1
2 3 4 5
23