Computer Science · Ch 5 — Sorting
Introduction
Introduction
Sorting is the process of arranging a given collection of elements in a specific order. This order can be ascending or descending for numbers, or alphabetical for strings. The core idea is to bring order to a set of items so that they become easier to work with.
Consider a dictionary: words are sorted alphabetically. If they were not, finding a single word would mean checking every page until you stumbled upon it — a tedious and time-consuming task. Similarly, seats in an examination hall are ordered by roll number, and a list of students can be sorted by height or weight. In each case, sorting makes searching and retrieval far more efficient.
Sorting a large number of items does take extra time — this is called overhead. However, this overhead is worth it because the time saved when searching a sorted list is far greater than the time spent sorting it. Sorting is a fundamental area of study in computer science, and many algorithms have been developed and analysed for their performance.
In this chapter, you will learn three sorting methods and implement them using Python:
- Bubble sort (Section 5.2)
- Selection sort (Section 5.3)
- Insertion sort (Section 5.4)