Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- 1 Iterative Algorithms: Measures of Progress and Loop Invariants
- 2 Examples Using More-of-the-Input Loop Invariants
- 3 Abstract Data Types
- 4 Narrowing the Search Space: Binary Search
- 5 Iterative Sorting Algorithms
- 6 Euclid's GCD algorithm
- 7 The Loop Invariant for Lower Bounds
- Part Two Recursion
- Part Three Optimization Problems
- Part Four Appendix
- Part five Exercise Solutions
- Index
5 - Iterative Sorting Algorithms
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- 1 Iterative Algorithms: Measures of Progress and Loop Invariants
- 2 Examples Using More-of-the-Input Loop Invariants
- 3 Abstract Data Types
- 4 Narrowing the Search Space: Binary Search
- 5 Iterative Sorting Algorithms
- 6 Euclid's GCD algorithm
- 7 The Loop Invariant for Lower Bounds
- Part Two Recursion
- Part Three Optimization Problems
- Part Four Appendix
- Part five Exercise Solutions
- Index
Summary
Sorting is a classic computational problem. During the first few decades of computers, almost all computer time was devoted to sorting. Many sorting algorithms have been developed. It is useful to know a number of them, because sorting needs to be done in many different situations. Some depend on low time complexity, other on small memory, others on simplicity. Throughout the book, we consider a number of sorting algorithms because they are simple yet provide a rich selection of examples for demonstrating different algorithmic techniques. We have already looked at selection, insertion, and bubble sort in Section 1.4. In this chapter we start with a simple version of bucket sort and then look at counting sort. Radix sort, which is another surprising sort, is considered. Finally, counting and radix sort are combined to give radix counting sort.
Most sorting algorithms are said to be comparison-based, because the only way of accessing the input values is by comparing pairs of them, i.e., ai ≤ aj. Radix counting sort manipulates the elements in other ways. Another strange thing about this algorithm is that its loop invariants are rather unexpected.
In Section 9.1, we consider merge sort and quick sort, which is a recursive and randomized version of bucket sort. We look at heap sort in Section 10.4.
Bucket Sort by Hand
Specifications: As a professor, I often have to sort a large stack of students' papers by last name. The algorithm that I use is an iterative version of quick sort and bucket sort. See Section 9.1.
- Type
- Chapter
- Information
- How to Think About Algorithms , pp. 71 - 78Publisher: Cambridge University PressPrint publication year: 2008