For questions about dividing groups of objects based on their properties.

# Questions tagged [sorting]

327 questions

**24**

votes

**1**answer

### Average swaps needed for a random bubble sort algorithm

Suppose we have $n$ elements in a random permutation (each permutation has equal probability initially). While the elements are not fully sorted, we swap two adjacent elements at random (e.g. the permutation $(1, 3, 2)$ can go to $(1, 2, 3)$ or $(3,…

Kyky

- 2,615
- 1
- 14
- 30

**20**

votes

**1**answer

### What is meaning of strict weak ordering in layman's term?

I gone through many pages using Google, but not understand exact meaning of Strict-weak Ordering term.
I have this requirement while sorting strings.

Pranit Kothari

- 436
- 1
- 4
- 14

**16**

votes

**1**answer

### Name for this sorting algorithm

I’ve just been playing around with some numbers and stumbled across this sorting algorithm:
Take a set of integers
$\{2,2,5,1,1\}$.
Count how many numbers you can subtract 1 from (without going negative) - (5)
Same for subtracting 2 - (3)
Same for…

Ben Crossley

- 2,376
- 8
- 28

**15**

votes

**1**answer

### Algorithm to sort based on a partial order

Forgive me if this is too imprecise a question. My math-fu is weak, I'm just a humble programmer.
I'm looking for an algorithm to sort a list of items based on a partial order: each item has a list of other items that it must be before, and a list…

Marcus Downing

- 253
- 2
- 7

**14**

votes

**3**answers

### Quicksort Running Time

I am trying to refresh my knowledge (and hopefully learn more) about Algorithm Analysis. I took a course on this two years ago but I am trying to catch up on what I had learned back then.
The way I am going about it is by doing exercises from the…

JakeClawson

- 171
- 1
- 1
- 6

**13**

votes

**2**answers

### Median of distinct numbers

What is the least number of comparisons we need to find the median of 6 distinct numbers?
I am able to find the answer to the median of 5 distinct numbers to be 6 comparisons, and it makes sense, however in the case of 6 numbers I can't find an…

Sev

- 1,909
- 3
- 17
- 19

**11**

votes

**1**answer

### Why is sorting pancakes NP hard?

An article posted yesterday (http://www.i-programmer.info/news/112-theory/3280-pancake-flipping-is-hard-np-hard.html) references a new study released on Arxiv (http://arxiv.org/abs/1111.0434v1) with the following summary:
Pancake Flipping is the…

Fosco

- 212
- 2
- 7

**10**

votes

**5**answers

### Worst case analysis of MAX-HEAPIFY procedure .

From CLRS book for MAX-HEAPIFY procedure :
The children's subtrees each have size at most 2n/3 - the worst case
occurs when the last row of the tree is exactly half full
I fail to see this intuition for the worst case scenario . Can some one…

Geek

- 2,169
- 9
- 33
- 45

**9**

votes

**1**answer

### Minimum Moves to Sort $n\times n$ Array

I was trying to create a new game where you are given randomized $n\times n$ matrix $A$ with distinct elements taken from the set $\{1,2,...,n^2\}$.
The goal is to sort the matrix in minimum number of moves such that
$a_{i,j}=(i-1)n +j$
after…

8hantanu

- 1,813
- 10
- 27

**7**

votes

**2**answers

### Quicksort with Trivalued Logic

Does anyone know a way to do a quick sort with trivalued logic?
The problem I’m trying to solve is this: I’m trying to display a view of a complex 3d object from a given viewing angle. I’ve broken the object into many 2d surfaces that I can draw…

Simon Robinson

- 73
- 3

**6**

votes

**1**answer

### Average complexity of random-pick comparison sort

Motivation. Suppose we have a number of images that we want to arrange in a linear order from the prettiest to the ugliest. At our disposal we have a trained aesthete, whom we can show two pictures and ask him which is the prettiest. We assume that…

hmakholm left over Monica

- 276,945
- 22
- 401
- 655

**6**

votes

**1**answer

### Reference Request on Order Theory topics

I am looking for some references (especially a good recent book) that covers important topics involving partial orders such as: order polytopes, sorting/selection in partially ordered sets, upper and lower bounds on the amount of linear extensions…

Nizbel99

- 837
- 1
- 8
- 23

**6**

votes

**1**answer

### An expected value puzzle

While working on a larger problem, I encountered this smaller problem that I’ve enjoyed thinking about, but have yet to solve.
Shuffle the numbers 0 to 24 into a 5 by 5 matrix. Sort each column in ascending order, then sort each row in ascending…

Ananab Tilps

- 61
- 1

**6**

votes

**5**answers

### Expected number of items looked at

Currently failing at basic probability…
Given a sequence of items, linear search means looking at each in turn and seeing if it's the one we're looking for. (I.e. in the worst case, it's the last item in the sequence or not in the sequence at all…

User1291

- 526
- 3
- 17

**6**

votes

**1**answer

### Unique Topological Sort for DAG

I have a DAG (directed acyclic graph) which has more than one valid topological sorting. I'm looking for a way to sort it topologically and always get the same, well defined result.
For example take this graph:
A-->B
A-->C
B-->D
C-->D
There are two…

XPlatformer

- 199
- 1
- 6