**Sorting Algorithm Tutorials - Herong's Tutorial Examples** - Version 6.01, by Dr. Herong Yang

What Is Sorting?

This section describes what is sorting - A process to organize a collection of data elements based on the order of a comparable property of each element.

**What Is Sorting?**
Sorting is to organize a collection of data elements based on the order of a comparable
property of each element.

There are three concepts in this definition:

- "Data element": A unit of information.
- "Comparable property": A property in each element that can be used to compare element A with element B. The comparison must give one of three possible results: 1. A is in higher order than B; 2. A is in equal order as B; 3. A is in lower order than B.
- "Collection": Sorting works on a collection of data elements, not on a single data element.

Examples of sorting:

A yellow-page book:

- Data element: A business name, its phone number, and possibly its address.
- Comparable property: The alphabetical sequence of the business name.
- Collection: All businesses that registered in the yellow book.

An English dictionary:

- Data element: An English word, its pronunciation, and its meanings.
- Comparable property: The alphabetical sequence of the word.
- Collection: All words collected in the dictionary.

Warning: For certain types of data elements, the comparable property is not so easy to find. For example, what is the comparable property that can be used to sort the characters in a Chinese dictionary?

*Last update: 2011.*

Table of Contents

►Introduction of Sorting Algorithms

Most Popular Sorting Algorithms

Java API for Sorting Algorithms

Insertion Sort Algorithm and Implementation

Selection Sort Algorithm and Implementation

Bubble Sort Algorithm and Implementation

Quicksort Algorithm and Implementation

Merge Sort Algorithm and Implementation

Heap Sort Algorithm and Implementation

Shell Sort Algorithm and Implementation