cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-3 of 3 results.

A350569 a(n)/n! is the average number of key comparisons required to sort n records with distinct keys using a modified heapsort (Algorithm H in Don Knuth's TAOCP Vol. 3, answer to exercise 18).

Original entry on oeis.org

2, 18, 154, 1257, 10152, 91557, 922368, 10286658, 119281680, 1517655690, 20619929376, 303487939485, 4662169420608
Offset: 2

Views

Author

Hugo Pfoertner, Jan 06 2022

Keywords

Comments

There are two places in R. W. Floyd's modified algorithm where the keys are compared. The first is in step H4 [Find larger child.] and the second in step H9' [Does K fit?]. The sequence is the sum of the counts of these comparisons, taken over all n! possible orders of the records.
The following table shows the maximum and average number of key comparisons for the original algorithm and for its modified version.
Algorithm H Modified algorithm
.
n Worst case Worst case
| A350426(n) A350427(n)
| | Average | Average
| | 2*A350428(n)/n! | A350569(n)/n!
| | | Average/ | | Average/
| | | (n*log(n)) | | (n*log(n))
2 1 1.000 0.721 1 1.000 0.721
3 3 3.000 0.910 3 3.000 0.910
4 7 6.500 1.172 7 6.417 1.157
5 12 10.950 1.361 12 10.475 1.302
6 17 15.133 1.408 16 14.100 1.312
7 22 19.789 1.453 20 18.166 1.334
8 29 25.814 1.552 27 22.876 1.375
9 37 32.524 1.645 34 28.347 1.433
10 44 38.631 1.678 39 32.871 1.428
11 51 45.237 1.715 44 38.020 1.441
12 59 51.845 1.739 51 43.048 1.444
13 66 59.021 1.770 57 48.737 1.462
14 73 65.488 1.773 63 53.479 1.447
This is compatible with Don Knuth's remark, quoted from TAOCP Vol. 3, page 148: Heapsort has the interesting property that its worst case isn't much worse than the average.

References

  • D. E. Knuth, The Art of Computer Programming Second Edition. Vol. 3, Sorting and Searching. Chapter 5.2.3 Sorting by Selection, Pages 145, 156 and 642. Addison-Wesley, Reading, MA, 1998.

Crossrefs

A350428 2*a(n)/n! is the average number of key comparisons required to sort n records with distinct keys using heapsort (Algorithm H in Don Knuth's TAOCP Vol. 3).

Original entry on oeis.org

1, 9, 78, 657, 5448, 49869, 520416, 5901138, 70092000, 902850273, 12416814432, 183763314090, 2854581512832
Offset: 2

Views

Author

Hugo Pfoertner, Jan 05 2022

Keywords

Comments

There are two places in the algorithm where the keys are compared. The first is in step H4 [Find larger child.] and the second in step H6 [Larger than K?]. The sequence is the sum, divided by 2, of the counts of these comparisons, taken over all n! possible orders of the records.

References

  • D. E. Knuth, The Art of Computer Programming Second Edition. Vol. 3, Sorting and Searching. Chapter 5.2.3 Sorting by Selection, Page 145. Addison-Wesley, Reading, MA, 1998.

Crossrefs

A350569 contains a table with the maximum and average number of comparisons for the original algorithm and for its modified version.

A350427 a(n) is the maximum number of key comparisons required to sort n records with distinct keys using a modified heapsort (Algorithm H in Don Knuth's TAOCP Vol. 3, answer to exercise 18).

Original entry on oeis.org

1, 3, 7, 12, 16, 20, 27, 34, 39, 44, 51, 57, 63
Offset: 2

Views

Author

Hugo Pfoertner, Jan 05 2022

Keywords

Comments

There are two places in R. W. Floyd's modified algorithm where the keys are compared. The first is in step H4 [Find larger child.] and the second in step H9' [Does K fit?]. The sequence shows the maxima of the counts of these comparisons, determined over all n! possible orders of the records.

References

  • D. E. Knuth, The Art of Computer Programming Second Edition. Vol. 3, Sorting and Searching. Chapter 5.2.3 Sorting by Selection, Pages 145, 156 and 642. Addison-Wesley, Reading, MA, 1998.

Crossrefs

A350569 contains a table with the maximum and average number of comparisons for the original algorithm and for its modified version.
Showing 1-3 of 3 results.