0% found this document useful (0 votes)
4 views2 pages

Sorting Algorithms Explained with Examples

The document outlines various sorting algorithms including Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Quick Sort, Heap Sort, and Counting Sort, along with their definitions, real-life examples, and time complexities. Each algorithm is illustrated with a relatable example, such as arranging cards or sorting exam scores. The summary table provides a quick reference for the best and worst time complexities, stability, and real-life applications of each algorithm.

Uploaded by

anshucheekurthi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Sorting Algorithms Explained with Examples

The document outlines various sorting algorithms including Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Quick Sort, Heap Sort, and Counting Sort, along with their definitions, real-life examples, and time complexities. Each algorithm is illustrated with a relatable example, such as arranging cards or sorting exam scores. The summary table provides a quick reference for the best and worst time complexities, stability, and real-life applications of each algorithm.

Uploaded by

anshucheekurthi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Sorting Algorithms with Real-Life Examples

Bubble Sort
Definition: Compares each pair and swaps if needed until sorted.
Real-life Example: Arranging playing cards by swapping wrong pairs.
Time Complexity: O(n²)

Insertion Sort
Definition: Builds sorted list one element at a time.
Real-life Example: Inserting each card into the correct position in your hand.
Time Complexity: O(n²)

Selection Sort
Definition: Finds the smallest element and places it in the correct position.
Real-life Example: Picking the smallest exam paper one by one.
Time Complexity: O(n²)

Merge Sort
Definition: Divides array, sorts halves, and merges them back.
Real-life Example: Dividing and merging sorted piles of cards.
Time Complexity: O(n log n)

Quick Sort
Definition: Chooses a pivot and partitions around it.
Real-life Example: Grouping people shorter or taller than a pivot person.
Time Complexity: O(n log n)

Heap Sort
Definition: Uses a heap to repeatedly extract the largest element.
Real-life Example: Ranking tournament players from highest to lowest.
Time Complexity: O(n log n)

Counting Sort
Definition: Counts occurrences of each number to place elements in order.
Real-life Example: Sorting exam scores (0–100) by counting occurrences.
Time Complexity: O(n + k)

Summary Table
Algorithm Best Worst Stable Real-life Example
Bubble Sort O(n) O(n²) Yes Swapping wrong pairs
Insertion Sort O(n) O(n²) Yes Arranging playing cards
Selection Sort O(n²) O(n²) No Picking smallest repeatedly
Merge Sort O(n log n) O(n log n) Yes Merging sorted piles
Quick Sort O(n log n) O(n²) No Grouping around pivot
Heap Sort O(n log n) O(n log n) No Ranking winners
Counting Sort O(n+k) O(n+k) Yes Counting exam scores

You might also like