83
Sorting and Listing Combinatorics for Computer Science (Units 2 and 3) S. Gill Williamson

Sorting and Listing - Computer Science and Engineeringcseweb.ucsd.edu/~gill/AlgCombSite/Resources/_CreateSp2_3.pdf · Sorting and Listing Combinatorics for Computer Science (Units

Embed Size (px)

Citation preview

Sorting and Listing

Combinatorics for Computer Science (Units 2 and 3)

S. Gill Williamson

©S. Gill Williamson 2012

Preface

From 1970 to 1990 I ran a graduate seminar on algebraic and algorithmic com-binatorics in the Department of Mathematics, UCSD. From 1972 to 1990 al-gorithmic combinatorics became the principal topic. The seminar notes from1970 to 1985 were combined and published as a book, Combinatorics for Com-puter Science (CCS), published by Computer Science Press. Each of the "unitsof study" from the seminar became a chapter in this book.

My general goal is to re-create the original presentation of these (largely inde-pendent) units in a form that is convenient for individual selection and study.Here, we isolate a combined Unit 2 and Unit 3, corresponding to Chapter 2 andChapter 3 of CCS, and reconstruct the original very helpful unit specific indexassociated with these two units.

Theorems, figures, examples, etc., are numbered sequentially: EXERCISE 2.30and THEOREM 2.38 refer to numbered items 30 and 38 of Unit 2 (or Chapter 2in CCS), DEFINITION 3.39 refers to the numbered item 39 of Unit 3.

These notes focus on the visualization of algorithms through the use of graph-ical and pictorial methods. This approach is both fun and powerful, preparingyou to invent your own algorithms for a wide range of problems.

Basic Concepts of Linear Order is Unit 1 in this series.

S. Gill Williamson, 2012http : \www.cse.ucsd.edu\ ∼ gill

iii

iv

Table of Contents

Unit 2: Sorting introduction .....................................................................1

Sorting networks......................................................................................11

Merge insertion........................................................................................20

Zero-one principle ...................................................................................23

Generalized matrix principle .................................................................24

Batcher odd-even merge and sort ..........................................................26

Unit 3: Listing introduction....................................................................31

Injective functions, rank, unrank, permutations .................................36

Permutations by adjacent marks ..........................................................40

Increasing functions colex and lex order ..............................................42

Nondecreasing functions lex and colex, reverse lex and colex.............46

Ordered set partitions, set partitions, ...................................................49

Restricted growth functions and set partitions ....................................52

Set partitions into k parts ......................................................................64

Loop free algorithms ..............................................................................67

Classical references .................................................................................69

Subject Index ...........................................................................................71

v

vi

UNIT 2

SORTING (TOPIC I)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

UNIT 3

LISTING (TOPIC II)

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

General Classical References (search Web for modern references):

Aho, Hopcroft, Ullman, The Design and Analysis of Comp. Alg., 1974

Baase, Computer Algorithms, 1978

Beckenbach (Ed.), Applied Combinatorial Math., Wiley, 1964

Even, Algorithmic Combinatorics, 1973

Nijenhuis, Wilf, Combinatorial Algorithms, 1975

Page, Wilson, An Introduction to Computational Combinatorics, 1979

Reingold, Nievergelt, Deo, Comb. Alg.: Theory and Practice, 1977

Wirth, Algorithms + Data Structures = Programs, 1976

68

Classical References

For general references (those mentioned below) see page 68

Classical References for Sorting (Web or arXiv.org for recent)

Classical References for Listing (Web or arXiv.org for recent)

69

70

Index

balls into boxesboth labeled, 33lex order

rank, unrank, 33, 34unlabeled to labeled, 48

binary treedata structure, 7

breadth first order, 5

comparatoradjacent, 15sorting strategy, 12tree, 12

contents, v

derangementsorder rank and unrank, 66

functionscoimage, 33lex list, 31lex order

rank, unrank, 34loop free listing, 67one line notation, 32reduced tree, 34residual tree, 34

functions increasingcolex order, 42

rank, unrank, 42lex order

rank, unrank, 43functions injections

3 to 5 , 35adjacent marks, 40

direct insertion, 36falling factorials, 36general case, 35rank, unrank, 35

functions nondecreasing, 44coding, 45colex rank, unrank, 47lex rank, unrank, 46

Gray code - combinatorial, 67

heapmakeheap, 6nearheap, 8reheap, 6, 8

injectionsdirect insertion, 37

integergreatest dxe, 3least bxc, 3

integersbucket notation

n = {0, . . . n−1}, 31underline notationn = {1, . . . n}, 4, 31

inversionadjacent, 15

inversion diagrampermutation, 14

mergeBatcher odd-even, 26, 27recursive in Batcher sort, 28

merge insertiondefined, 20

71

Ford-Johnson, 20main chain, 20not optimal characterized, 22vs. worst case, 21

multinomial indexordered partition, 48ordered partitions, 49

one line notation, 32order isomorphic sets, 32order isomorphism, 32ordered partitions of set, 33

as functon coimage, 33length of, 33lex order, 33

partition of seta set of subsets (blocks){A1, . . . , Ap}, 50

an order conventionon blocks A1, . . . , Ap, 50

partitions of setalternative linear orders, 63block count exactly rE(r)(n,m), 55, 57, 58

block count restrictedT (r)(n,m), 54, 56

integral partition typedefined by, 64rank, unrank, 65

m-restricted growth functionsRG(m), 58

ordered partitionsfixed multinomial index, 48rank, unrank, 49

ranking, unrankingusing E(r)(n,m), 62using T (r)(n,m), 59, 60

recursive definition ofT (r)(n,m), 58

reduced tree diagramsusing T (r)(n,m), 61

restricted growth (RG), 51

RG functions, 51lex order, 52lex order rank, unrank, 53,

54tail coefficients T (n,m), 52–

54Stirling numbers S(d, k), 64uniform random selection, 66

permutationaverage displacement, 10inversion diagram, 14left(x), 9right(x), 9

permutationsadjacent transposition orders,

66loop free algorithms, 68

permutations S4

adjacent markstable, 40

permutations Sr

adjacent marks, 39direct insertion, 37rank, unrank, 38

preface, iii

rank and unrankand random selection, 66defined, 31

Shell’s methodcomplexity, 5h-sort, 4

sortingBatcher sort, 28bounds for S(n), 24, 25bucket, 2comparison based, 10comparison count, 3generalized matrix principle, 24h-sort, 4intuitive ideas, 2network, 12

72

permutations, 4Shell’s method, 4strategy vs. network, 11

sorting networkminimal comparators, 23zero-one principle, 23

sorting networksadjacent comparators, 16

reverse permutation, 17delay time, 13insertion method, 13odd-even transposition, 13

proof of sort, 18select largest, 13select smallest, 13

sorting strategyheapsort, 19lower bounds, 18, 19quicksort, 19

strongpos(x,list), 9subsets

order isomorphic to 32 , 32

treecomplete binary, 5heap vertex labels, 6height, 5residual, 34truncated complete binary, 5vertex, 5

73

NOTES

74

NOTES

75

NOTES

76

NOTES

77