Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike...

48
Bubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical Society Colloquium December 2010 1

Transcript of Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike...

Page 1: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort and permutations

Mike AtkinsonMichael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes

New Zealand Mathematical Society ColloquiumDecember 2010

Aspects of Separability

M. H. Albert (Otago)

PP 2007, St Andrews

M. H. Albert (Otago) Aspects of Separability PP 2007, St Andrews 1 / 12

1

Page 2: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Outline of talk

1 Permutations and Pattern classes: basic concepts

2 One pass bubblesort

3 Results and applications

2

Page 3: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Permutations

A permutation of length n is an arrangement of 1, 2, . . . , n (one-linenotation, not cycle notation)

Example: 528639714

Conveniently displayed as a graph

Example

The graph of 528639714

1

2 3 4 5 6 7 8

2

3

4

5

6

7

8

1

9

9

3

Page 4: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Permutations

A permutation of length n is an arrangement of 1, 2, . . . , n (one-linenotation, not cycle notation)

Example: 528639714

Conveniently displayed as a graph

Example

The graph of 528639714

1

2 3 4 5 6 7 8

2

3

4

5

6

7

8

1

9

9

3

Page 5: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Permutations

A permutation of length n is an arrangement of 1, 2, . . . , n (one-linenotation, not cycle notation)

Example: 528639714

Conveniently displayed as a graph

Example

The graph of 528639714

1

2 3 4 5 6 7 8

2

3

4

5

6

7

8

1

9

9

3

Page 6: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Permutations

A permutation of length n is an arrangement of 1, 2, . . . , n (one-linenotation, not cycle notation)

Example: 528639714

Conveniently displayed as a graph

Example

The graph of 528639714

1

2 3 4 5 6 7 8

2

3

4

5

6

7

8

1

9

9

3

Page 7: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

The cardinal sin: unlabeled axes

Example

Increasingly sloppy graphs of 31524

1

2

3

4

5

1 2 3 4 5

4

Page 8: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Subpermutations

Example

The graph of 528639714

4213 is a subpermutation of 528639714.

Notation

4213 � 528639714 and 54321 6� 528639714

The � relation is a partial order on the set of all permutations

5

Page 9: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Subpermutations

Example

The graph of 528639714 and subpermutation 4213

4213 is a subpermutation of 528639714.

Notation

4213 � 528639714 and 54321 6� 528639714

The � relation is a partial order on the set of all permutations

5

Page 10: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Subpermutations

Example

The graph of 528639714 and subpermutation 4213

4213 is a subpermutation of 528639714.

Notation

4213 � 528639714 and 54321 6� 528639714

The � relation is a partial order on the set of all permutations5

Page 11: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Pattern classes

Definition

A pattern class is a set of permutations closed under takingsubpermutations (down-set in the partial order)

Every pattern class X can be defined by a set of avoided permutations.

Notation

Av(B): the pattern class defined by avoiding permutations in the set B.

Main issues

Given a pattern class realise it in the form Av(B) for some set B

Give structural description of permutations in some given Av(B)

Count them of each length

6

Page 12: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 1: all identity permutations

The set of all identity permutations {1, 12, 123, 1234, . . .} forms thepattern class Av(21). It has 1 permutation of every length n.

7

Page 13: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5 1 4 2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 14: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1 4 2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 15: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

51

4 2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 16: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1 4 2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 17: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1

4

2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 18: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1

42

3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 19: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1

4

2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 20: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1

4

2

3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 21: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1

4

2 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 22: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

5

1 42 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 23: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

51 42 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 24: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Example 2: The one pass Stacksort operator

51 42 3

The stack-sortable permutations form the pattern class Av(231). It has(2nn )n+1 permutations of length n

8

Page 25: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Permutations and Pattern classes

Av(4312, 2143) – movie of length 13 permutations

9

Page 26: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

4 1 2 7 6 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 27: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

4 1 2 7 6 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 28: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 7 6 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 29: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 7 6 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 30: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 7 6 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 31: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 32: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 33: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 9 8 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 34: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 98 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 35: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 98 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 36: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

The Bubblesort operator B

1 Bubblesort is an inefficient sorting algorithm that proceeds in anumber of passes.

2 Each pass is a left to right scan

41 2 76 3 98 5

The effect σ → B(σ) of one pass is given by

B(ε) = ε and

B(αnβ) = B(α)βn

10

Page 37: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Bubblesort operator

B sorts a pattern class

1 In general we need n passes to sort a permutation of length n

2 But B (applied once) sorts a small number of permutations

3 The set sortable by B is Av(231, 321)

Theorem

B−1(Av(21)) = Av(231, 321)

11

Page 38: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

A general question

Formally generalising the statement of this theorem:

Question

1 For an arbitrary pattern class Av(Π) what is B−1(Av(Π))?

2 Is it even a pattern class? If so, which pattern class is it?

An answer would enable the study of composing B with other sortingoperators.

12

Page 39: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Left to right maxima

Figure: 352419786 has 3 left to right maxima

13

Page 40: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Theorems

Definition

A permutation is good if it either has at most 2 left to right maxima, orhas 3 left to right maxima and ends with its largest term.

Theorem

If Π = {π} then B−1(Av(Π)) is a pattern class if and only if π is good.

Theorem

If Π consists of good permutations then B−1(Av(Π)) is a pattern class.Moreover we have B−1(Av(Π)) = Av(Σ) for some set Σ that is explicitlycomputable in terms of Π – but this margin. . .

14

Page 41: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Theorems

Definition

A permutation is good if it either has at most 2 left to right maxima, orhas 3 left to right maxima and ends with its largest term.

Theorem

If Π = {π} then B−1(Av(Π)) is a pattern class if and only if π is good.

Theorem

If Π consists of good permutations then B−1(Av(Π)) is a pattern class.Moreover we have B−1(Av(Π)) = Av(Σ) for some set Σ that is explicitlycomputable in terms of Π – but this margin. . .

14

Page 42: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Theorems

Definition

A permutation is good if it either has at most 2 left to right maxima, orhas 3 left to right maxima and ends with its largest term.

Theorem

If Π = {π} then B−1(Av(Π)) is a pattern class if and only if π is good.

Theorem

If Π consists of good permutations then B−1(Av(Π)) is a pattern class.Moreover we have B−1(Av(Π)) = Av(Σ) for some set Σ that is explicitlycomputable in terms of Π – but this margin. . .

14

Page 43: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Example application

Question

How many permutations of length n can be sorted by one pass ofBubblesort followed by one pass of Stacksort?

Stacksort is another simple sorting method: the permutations that itcan sort form the pattern class Av(231).

Hence the set we are interested in is B−1(Av(231)).

The explicit forms of the theorem above tells us thatB−1(Av(231)) = Av(3241, 2341, 4231, 2431)

Now a calculation that is quite commonplace in this subject showsthat this set has

(2n−2n−1

)permutations of each length n.

15

Page 44: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Example application

Question

How many permutations of length n can be sorted by one pass ofBubblesort followed by one pass of Stacksort?

Stacksort is another simple sorting method: the permutations that itcan sort form the pattern class Av(231).

Hence the set we are interested in is B−1(Av(231)).

The explicit forms of the theorem above tells us thatB−1(Av(231)) = Av(3241, 2341, 4231, 2431)

Now a calculation that is quite commonplace in this subject showsthat this set has

(2n−2n−1

)permutations of each length n.

15

Page 45: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Example application

Question

How many permutations of length n can be sorted by one pass ofBubblesort followed by one pass of Stacksort?

Stacksort is another simple sorting method: the permutations that itcan sort form the pattern class Av(231).

Hence the set we are interested in is B−1(Av(231)).

The explicit forms of the theorem above tells us thatB−1(Av(231)) = Av(3241, 2341, 4231, 2431)

Now a calculation that is quite commonplace in this subject showsthat this set has

(2n−2n−1

)permutations of each length n.

15

Page 46: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Example application

Question

How many permutations of length n can be sorted by one pass ofBubblesort followed by one pass of Stacksort?

Stacksort is another simple sorting method: the permutations that itcan sort form the pattern class Av(231).

Hence the set we are interested in is B−1(Av(231)).

The explicit forms of the theorem above tells us thatB−1(Av(231)) = Av(3241, 2341, 4231, 2431)

Now a calculation that is quite commonplace in this subject showsthat this set has

(2n−2n−1

)permutations of each length n.

15

Page 47: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Lots more questions

1 Many other sorting algorithms sort in phases – we can ask whatpermutations are sortable by a single phase – when is it a patternclass?

2 Any answers then allow us to investigate the permutations sortable bycombinations of phases from different sorting algorithms

Thank you for listening

16

Page 48: Bubblesort and permutations - University of · PDF fileBubblesort and permutations Mike Atkinson Michael Albert, Mathilde Bouvel, Anders Claesson, Mark Dukes New Zealand Mathematical

Results and applications

Lots more questions

1 Many other sorting algorithms sort in phases – we can ask whatpermutations are sortable by a single phase – when is it a patternclass?

2 Any answers then allow us to investigate the permutations sortable bycombinations of phases from different sorting algorithms

Thank you for listening

16