0
votes
0answers
32 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
1answer
236 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 ...
0
votes
1answer
96 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 ...
0
votes
1answer
97 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
148 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 ...
0
votes
1answer
124 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 ...
0
votes
3answers
141 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
579 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
0answers
35 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
93 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, ...
0
votes
3answers
160 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 ...
0
votes
1answer
58 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
185 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
87 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 ...
2
votes
4answers
343 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 ...
2
votes
4answers
310 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 ...
0
votes
3answers
275 views

How to create single integer index value based on two integers where first is unlimited?

I have table data containing an integer value X ranging from 1.... unknown, and an integer value Y ranging from 1..9 The data need to be presented in order 'X then Y'. For one visual component I can ...
-1
votes
5answers
1k views

Reverse subarray of an array with O(1)

I have an idea how to implement sub array reverse with O(1), not including precalculation such as reading the input. I will have many reverse operations, and I can't use the trivial solution of O(N). ...
2
votes
1answer
97 views

Sorting with continous input

I'm designing (not writing, yet) a task scheduler system for a complex video game. The rest of the program passes it objects containing a function and some metadata including an estimation of how much ...
1
vote
3answers
495 views

Sort an array in a specific order - not ascending/descending

I'm working on an algorithm that works best if the inputs are passed to it in a particular order, so I want to sort them that way. The difference is drastic enough for me to consider re-sorting the ...
6
votes
6answers
4k views

Why is binary search,which needs sorted data, considered better than linear search?

I have always heard that linear search is a naive approach and binary search is better than it in performance due to better asymptotic complexity. But I never understood why is it better than linear ...
6
votes
3answers
1k views

Why is Quicksort called “Quicksort”?

The point of this question is not to debate the merits of this over any other sorting algorithm - certainly there are many other questions that do this. This question is about the name. Why is ...
1
vote
2answers
835 views

Radix exchange sort implementation?

I need a little help understanding the implementation of radix exchange sort algorithm. Radix exchange (I don't know if it's the exact name in english based literature) is a lot similar to quicksort, ...
1
vote
1answer
4k views

Quicksort and middle pivot

I am having a head ache understanding quicksort with middle pivot. I found lot of explanations about using left most or right most, but not many about a middle one. Can I safely assume these?: If ...
2
votes
3answers
145 views

What kind of algorithm could be used to produce an ordering which maximizes # of satisfied 'less than' constraints?

Let's say I have a set of items {e1, e2, ..., en}, and I also have a set of constraints {c1, c2, ..., cm}, with ci := ej appears before ek, for some j and k. I want to produce an ordering of my items ...
32
votes
6answers
2k views

I'd like to write an “ultimate shuffle” algorithm to sort my mp3 collection

I'm looking for pseudocode suggestions for sorting my mp3 files in a way that avoids title and artist repetition. I listen to crooners - Frank Sinatra, Tony Bennett, Ella Fitzgerald etc. singing old ...
2
votes
4answers
992 views

Applications of heapsort

Heapsort is a sorting algorithm that has a time complexity of O(nlogn), and performs sorting using O(1) space complexity. However, I know that because it's unstable, it doesn't find many applications ...
1
vote
3answers
482 views

Should I calculate hotness of a post on request or pre-calculate it?

Here is the Reddit's hot algorithm: cpdef double _hot(long ups, long downs, double date): """The hot formula. Should match the equivalent function in postgres.""" s = score(ups, downs) ...
2
votes
2answers
562 views

About insertion sort and especially why it's said that copy is much faster than swap?

From Lafore's "Data Structures and Algorithms in Java": (about insertion sort (which uses copy + shift instead of swap (used in bubble and selection sort))) However, a copy isn’t as time-consuming ...
2
votes
1answer
460 views

Comparison of my own Insertion Sort versus the standard algorithm

I come from a background of making MVC websites and HTML5 applications, and have recently decided to dive into the sort of stuff i wasn't taught at university, namely the things most people would ...
2
votes
4answers
4k views

What sorting algorithm does STL use?

I recently started using <vector.h> library and I was wondering, since all the operations are already implemented, IF the method of the sorting algorithm is the most efficient one. Everything ...
1
vote
6answers
7k views

Merge sort versus quick sort performance

I have implemented merge sort and quick sort using C (GCC 4.4.3 on Ubuntu 10.04 running on a 4 GB RAM laptop with an Intel DUO CPU at 2GHz) and I wanted to compare the performance of the two ...
1
vote
1answer
224 views

Algorithm for determining grid based on variably sized “blocks”?

I'm trying to convert a set of "blocks" in to a grid-like layout. The blocks have a width of either 25%, 33%, 50%, 66%, or 75% of their container and each row of the grid should try to fit as many ...
1
vote
1answer
312 views

Need help with algorithm for sorting list

The answer is probably obvious but not to me at this moment, so I was wondering if somebody who is better with sorting algorithms can help lead me in the right direction. This is not homework, I am ...
10
votes
8answers
12k views

Sort algorithms that work on large amount of data

I am looking for sorting algorithms that can work on a large amount of data, i.e. that can work even when the whole data set cannot be held in main memory at once. The only candidate that I have ...
4
votes
3answers
2k views

Basic premise on counting sort. How is k related to to Big Oh?

I am reading (Cormen) on counting sort. I understand the structure of the algorithm but the statement: In practice, we usually use counting sort when we have k = O(n), in which case the ...
9
votes
5answers
977 views

Algorithm refresher. Why is heapsort an insort algorithm?

I can not see why the heapsort is considered an inplace sorting algorithm. I mean an extra data structure populated with the elements of the array to be sorted i.e. a heap, is used to assist in the ...
15
votes
3answers
1k views

Java and .NET: Why different sorting algorithms are used by default?

Just wondering why Java and .NET Framework uses different sorting algorithm by default. In Java Array.Sort() uses Merge Sort algorithm by default and as Wikipedia.com says: In Java, the ...
5
votes
3answers
1k views

does quicksort provide less swapping step?

So far, most of the fastest and common sorting method is quicksort. Although it has its pro and cons. However, i'm thinking that although this sorting method is fast but does it provide shortest ...
8
votes
3answers
321 views

Data “unsort” / homogeneity algorithm

In an attempt to not reinvent a wheel, I'm asking if anyone has ideas on a data homogeneity algorithm. A brief example: My data has several elements maybe like Number Color Fruit Letter There ...
1
vote
5answers
4k views

Is Bubble Sort the slowest sorting algorithm? [closed]

Is Bubble Sort the slowest sorting algorithm? If the answer is no, then what is the slowest one?
2
votes
4answers
2k views

Which sorting algorithms have a different worst case complexity than their average case?

I'v been working on sorting for a while now but I can't figure these two questions apart, I'm kind of getting mixed up somewhere ... Somebody help a) Which sorting algorithms have a different worst ...
15
votes
3answers
5k views

Why isn't Radix Sort used more often?

It's stable and has a time complexity of O(n). It should be faster than algorithms like Quicksort and Mergesort, yet I hardly ever see it used.
8
votes
6answers
492 views

Quicksort and don't bother?

Especially when writing 'standard' (non-HPC) applications, do you consider what sorting algorithm to pick, or just settle with quicksort (which is what most libraries just call sort)? To some extent ...