The tag has no wiki summary.

learn more… | top users | synonyms

5
votes
1answer
93 views

Kth selection routine - Floyd Algorithm 489

I have recently come across a promising Kth selection routine that reportedly outperforms quickselect the Floyd, Rivest Select routine. This Wikipedia article provides a pseudocode version which I ...
1
vote
1answer
78 views

Sorting a large number of unknown items with multiple stacks

Here is a problem I'm trying to solve for a personal project. I'm not exactly sure how best to even approach it. Problem: I have a single stack already populated with several thousands of unknown ...
6
votes
3answers
388 views

Picking m number in the best possible time

Imagine we want to pick m numbers from n numbers so that the difference of the maximum and minimum of the m numbers be minimum, for example if m = 4 n =6 numbers: 10 12 10 7 5 22 The ...
2
votes
3answers
193 views

fast, say O(log2(N)), sliding median algorithm

So I know how to do a fast O(log2(N)) sliding max or sliding min algorithm. Brookes: "Algorithms for Max and Min Filters with Improved Worst-Case Performance" IEEE TRANSACTIONS ON CIRCUITS AND ...
1
vote
1answer
85 views

How to count sort comparison

When it is said that this sort has M number of comparisons what does it mean? As an example: procedure bubbleSort( A : list of sortable items ) n = length(A) repeat swapped = false ...
0
votes
2answers
92 views

Average number of comparison for sort algorithms

I need to write different sort algorithms such as bubbleSort insertionSort selectionSort quickSort mergeSort And measure how many average comparison does each one for N number (averaging between ...
0
votes
2answers
66 views

Can relational database tables always be topologically sorted by their FK reference relation?

Suppose I have some conceptual, not physical, E-R diagram describing a relational database. I want to sort all the tables in the database using a topological sort, where the partial ordering between ...
1
vote
1answer
41 views

filtering data from db

I've taken over a web application that someone else built. It's a pretty simple application that queries ALL records from a db and displays them in a list. They've also provided a way to 'filter' the ...
0
votes
1answer
147 views

Best data structure to store data sorted alphanumerically AND by weight [on hold]

What is the best data structure to store data sorted alphanumerically AND by weight (where weight is the first sorting criterion) with very low access time probably Olog(n) or better Application: A ...
0
votes
1answer
74 views

Sorting Sentences by New Words in Each

A very useful learning tool I stumbled across for Chinese was a massive list of sentences that, barring the first 10 or 15, only differed by the ones before by one or two words, or at least as few as ...
4
votes
3answers
150 views

Algorithm that generates a group of men and women who are each interested in everyone from the other gender

In my dating app, I need to compile lists of men and women where all of the men in the list are potentially interested in all of the women in the list, and vice versa. That is, in a list of 10 men ...
1
vote
1answer
113 views

What algorithm can be used to determine order given incomplete information?

Given a series of statements such as: a<c a<b b<c (Read as "a is before b", "a is before c", etc.) What is the order of the elements? In this example, the answer is a<b<c. A less ...
0
votes
1answer
68 views

How to efficiently determine when changes occur in event lists

We have a system that stores event information. There is a primary list of events as well as a secondary list, these may overlap. Secondary lists are combined with the primary based on 3 main rules. ...
0
votes
2answers
284 views

Algorithm for merging multiple rows of data

I need an algorithm to merge multiple rows for data, where one column is the index column and if one or more rows have the same index value merge the column values into a single row, and lastly sort ...
-2
votes
3answers
350 views

Situations when O(n^2) better than O(n*log(n)) [duplicate]

Is there any situation a sorting algorithm of time complexity O(n2) could be better than an O(n log(n)) sorting algorithm in any way?
2
votes
1answer
200 views

Insertion sorting Algorithm comparison

I recently came across sorting techniques and of particular, 'insertion sorting'. Although the logic and method is fairly understandable, the actual function seemed a bit complex (given below). ...
3
votes
3answers
116 views

sorting / merging hashtable

For my project I have a hashtable with 1M buckets (sometimes more). Each bucket contains lots of values and they are stored sorted in a dynamic array. I am looking for easy enough way to store all ...
3
votes
4answers
322 views

Why are return values from compare functions in many languages defined loosely?

Many languages define that compare functions should return ANY negative value, zero, or ANY positive value. Is there some reason that it shouldn't be clearly defined as -1 0 and 1? Does a wide range ...
0
votes
1answer
55 views

What would be the best sort to use on a something with sorted “chunks”?

Imagine a sorted deck of N cards that has been cut K times by moving X cards from the top to the bottom (X is a different / random amount each time, X is always < N) - what would be the best way to ...
2
votes
1answer
268 views

Quickest sorting algorithm for sorting a low number of integers

I am making a program on my spare time that I want to run as quickly as possible. The program is written in C. A large set of the procedures operate on pointers to 7 integers that are sorted by their ...
1
vote
2answers
76 views

multiple comparison sorting

I have a set of songs where I want to sort them by a particular quality. In order to do this (by crowdsourcing) I will present users with a comparison between two songs. The user will then choose ...
0
votes
0answers
169 views

In-place merging of sorted intervals in an array?

So I have code producing k sorted intervals in an n-sized array. What I'm brainstorming is the possibility of in-place merge of these intervals into a single sorted interval/array. The problem is ...
1
vote
1answer
67 views

Sorting list and changing same values to nearly the same

I have a list of doubles that need to be sorted and changed so that there are no two numbers that are the same (difference smaller then 0.05) and I need to do it fast. I don't care about preserving ...
5
votes
2answers
306 views

Is there any language-agnostic specification for “String Natural Sorting Order”

As I painfully try to find a good natural sorting algorithm written in JavaScript I then stumble upon a bunch of different implementations, & interesting blog posts & answers on Stack ...
0
votes
0answers
72 views

An algorithm to implement SQL's ORDER BY with TOP/LIMIT or OFFSET/FETCH

Is there a general algorithm to implement SQL's ORDER BY with OFFSET/LIMIT more efficiently than sorting all the records? The algorithm for a simple TOP x is easy enough. It takes one full pass ...
3
votes
2answers
1k views

What makes for a bad case for quick sort?

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 ...
1
vote
1answer
155 views

How to efficiently sort a recursively defined Stack?

I am trying to implement a recursively defined Stack and sort it in Java. I don't have a particular usage of this program in mind. I found this approach of stack implementation a bit useful while ...
0
votes
1answer
449 views

Count Sort Algorithm efficiency

As I am reading a Book about "Algorithm Analysis", I came across count_sort Algorithm. A question has been raised in my head. I read in many other papers, that "Quick Sort/ Merge Sort" are the best ...
1
vote
1answer
440 views

Dual pivot quicksort in face of expensive swaps

I was told this is better place to ask this TLDR Has anyone tested dual pivot quicksort performance with expensive-to-swap elements? It seems that in this case, it should massively underperform ...
1
vote
2answers
314 views

Level order sorted binary tree from a binary tree

Lets suppose we have a binary tree . Tree node structure is as struct node { int val ; struct node *left , *right ; } Now we have to sort the tree in level order manner . For example lets ...
25
votes
2answers
7k views

What does it mean for a sorting algorithm to be “stable”?

In reading about various sorting algorithms I've seen it mentioned that some are "stable" and some are not. What does that mean, and what tradeoffs are involved on that basis when selecting an ...
0
votes
2answers
343 views

How can I rank teams based off of head to head wins/losses

I'm trying to write an algorithm (specifically in Ruby) that will rank teams based on their record against each other. If a team A and team B have won the same amount of games against each other, then ...
1
vote
3answers
415 views

Tournament bracket method to put distance between teammates

I am using a proper binary tree to simulate a tournament bracket. It's preferred any competitors in the bracket that are teammates don't meet each other until the later rounds. What is an efficient ...
2
votes
1answer
2k views

Why is time complexity of k-way merge sort O(nk^2)?

I'm comparatively new to algorithm analysis and am taking a related course on coursera where I came accross k way merge sort. The time complexity of 2 way merge sort is n log2 n, of 3 way merge sort ...
0
votes
3answers
1k views

comparison of floating point numbers vs. comparsion of Integers in C [closed]

Does comparison of floating point numbers takes (considerably) longer time than comparison of Integers in C? I just wrote a C program of heap sort to sort floating point numbers. I am on ubuntu ...
0
votes
1answer
83 views

Maintaining sorted Array speed

I have a for loop running over a list of objects like: [{a: 2001, b: "hello"}, {a: 54, b: "hi"}....] In this loop, I filter out objects based on certain field values (like, b == hello?) and create ...
0
votes
0answers
49 views

Algorithm for inserting into sorted subset

A is a sorted list. B is a sorted list, and a subset of A. If an element is inserted into A at index i what's the most efficient way to determine the correct index i' for it's position in B? Given ...
2
votes
2answers
98 views

Set distances algorithm question

I have multiple sets containing integers. An integer maybe present in one set or multiple sets. I would like to find/match the sets with the most common integers. Example s1 {1, 2, 3, 4} s2 {1, 3, 4, ...
1
vote
2answers
612 views

Python sorted iterable set, modifiable during iteration

I am looking for a datastructure to handle cycling through a large number of ordered subroutines, some of which are active, most of which are not. I am thinking I need an implementation of a python ...
0
votes
3answers
204 views

Sorting an array when values are decreased by each swap [closed]

Recently in an interview I come across a question: We have an unsorted array, we need to sort it with minimum number of swap. We have in sort a 'tax' of 1 is deducted from the number we are ...
-1
votes
1answer
85 views

Short Sequential Search vs. Regular Sequential Search

Assuming a list of elements is sorted in ascending order, we search sequentially from the first element comparing the target to successive elements either until we find the target (succeed) or until ...
0
votes
1answer
77 views

expressing the speed of a sorting algorithm

How would I express the speed of the following sort algorithm? I know bubblesort is n^n (er, I mean n^2...as someone pointed out below). In the following the array decreases each time you call it ...
2
votes
1answer
269 views

Fully Stable, In-Place Unique Algorithm in O(n)

Is there an algorithm that, given a sorted array, swaps all the first unique elements to the beginning of the array and the duplicates to the end, while remaining stable for both the unique subarray ...
3
votes
1answer
92 views

Algorithm that determines relevant attributes in ordered list

Suppose I have a list of objects sorted by a person based on that person's subjective taste. Let's assume that this person is being somewhat consistent in their sorting and that there are quantifiable ...
5
votes
3answers
8k views

Quickest way to split a delimited String in Java

I am building a Comparator that provides multi-column sort capability on a delimited String. I am currently using the split method from String class as my preferred choice for splitting the raw String ...
3
votes
1answer
540 views

which sorting algorithms is using OrderBy

I am litle curious about what sorting algorithm is using OrderBy (linq to objects). quicksort? heapsort? introspective sort ? As i see in MSDN documentation List.Sort is using introspective sort: ...
2
votes
4answers
389 views

Is there any sorting algorithm which is not inherently sequential and is task distributable?

After googling for a couple hours, I came to a conclusion that all sorting algorithms are inherently sequential which can be data distributed but not task distributable. Is there any algorithm which ...
2
votes
3answers
1k views

Sorting an array of numbers with decimal places

Suppose I have an array of float values in the following format: { 1.34, 1.15, 1.1, 1.2, 1.26, 1.10, 1.20, 1.17 } Suppose they have been provided by user input (or some other mechanism), where the ...
1
vote
1answer
106 views

How to queue work orders by date and priority?

In my organization I work on orders based on date, so earliest work orders first. We also have an option for order to be marked "priority" in which case those orders are done first but not always. ...
2
votes
4answers
479 views

Looking for monotonically increasing (integer) hash function

I'm looking for a HashFunction(X,Y: Integer): Integer that is monotonically increasing on X, then Y. So: HashFunction(x1,y1) > HashFunction(x2,y2) if x1>x2 HashFunction(x,y1) > HashFunction(x,y2) if ...