All Sorting Techniques Easy Way to Learn

Fun with Sorting Algorithms

Sorting Algorithms for Kids

Learn about different ways to sort things through fun examples!

Click on "Generate Array" to create random numbers, then click "Sort" to watch the magic happen!

Bubble Sort

Just Like Bubbles Rising!

Imagine you have a line of friends with different heights. In bubble sort, you start from one end and compare two friends at a time. If they're in the wrong order (taller one before shorter one), you swap them!

You keep doing this until all friends are in the right order from shortest to tallest.

👫 👬 👭 👫

Speed: Not very fast for big groups (O(n²))

Memory: Very good! Doesn't need extra space (O(1))

When to use:

Great for small groups or when things are already almost in the right order, like organizing a small handful of toys.

Steps: 0
Comparisons: 0
Swaps: 0
13
16
75
15
97
83
73
96
97
98
10
77
Slower ←→ Faster

Selection Sort

Finding the Special One!

Imagine you're picking teams for a game. First, you look through everyone and pick the fastest runner for team captain. Then you look through everyone else and find the second fastest, and so on.

Each time, you're selecting the best person from those remaining!

🏃‍♀️ 🏃‍♂️ 🏃‍♀️ 🏃‍♂️

Speed: Not very fast for big groups (O(n²))

Memory: Very good! Doesn't need extra space (O(1))

When to use:

Good for sorting a small collection of items, like organizing your small bookshelf from shortest to tallest books.

Steps: 0
Comparisons: 0
Swaps: 0
35
45
91
84
100
41
10
84
39
25
24
32
Slower ←→ Faster

Insertion Sort

Like Sorting Playing Cards!

Think about how you organize playing cards in your hand. You pick up one card at a time and put it in the right spot among the cards you're already holding.

That's insertion sort! You take each item and insert it exactly where it belongs among the items you've already sorted.

🃏 🎴 🃏 🎴

Speed: Not fast for big groups (O(n²)), but great for small or almost-sorted groups

Memory: Very good! Doesn't need extra space (O(1))

When to use:

Perfect for organizing your hand of cards during a card game or when new items keep arriving that need to be put in the right spot immediately.

Steps: 0
Comparisons: 0
Swaps: 0
65
20
21
51
41
21
89
93
85
33
95
58
Slower ←→ Faster

Merge Sort

Split and Combine!

Imagine you have a big pile of toys to organize. First, you split them into two smaller piles. Then you split those piles again and again until you have many tiny piles with just one toy each.

Now, you start merging these tiny piles back together, putting them in order as you go. By the time you've merged everything back into one pile, all your toys are in order!

🧩 🧸 🎯 🪀

Speed: Very fast, even for big groups (O(n log n))

Memory: Needs extra space to store temporary results (O(n))

When to use:

Great for organizing large collections, like sorting all the books in a library or all the songs in your music player.

Steps: 0
Comparisons: 0
Swaps: 0
20
62
98
85
74
42
85
15
59
30
26
81
Slower ←→ Faster

Quick Sort

The Team Captain Strategy!

Imagine you're organizing friends by height. You pick one friend (called the "pivot") and ask everyone else to stand either to the left (if shorter) or to the right (if taller).

Then you do the same thing with each of these smaller groups, picking a new pivot each time. Keep going until everyone is in the right spot!

👧 👦 👩 👨

Speed: Usually very fast (O(n log n)), but can be slow in certain cases

Memory: Good! Doesn't need much extra space (O(log n))

When to use:

Excellent for sorting almost anything, especially when you need speed. It's used in computer systems for organizing files and data.

Steps: 0
Comparisons: 0
Swaps: 0
24
92
47
76
95
78
54
14
97
45
62
19
Slower ←→ Faster

Heap Sort

The Family Tree Sort!

Imagine organizing your family tree where each parent is always taller than their children. First, you arrange everyone into this special family tree (called a heap).

Then, you keep taking the tallest person (who's at the top of the tree) and putting them in line. After each removal, you reorganize the family tree and repeat until everyone is in order!

👵 👴 👩 👨

Speed: Very reliable, always fast (O(n log n))

Memory: Very good! Doesn't need extra space (O(1))

When to use:

Great for when you need to find the smallest or largest items quickly, like in a game where you keep track of the top 10 highest scores.

Steps: 0
Comparisons: 0
Swaps: 0
76
29
38
44
39
45
26
36
83
100
78
62
Slower ←→ Faster

Radix Sort

Sorting Digit by Digit!

Imagine you're sorting numbered race cars. First, you line them up based on the last digit of their number (ones place), then by the second-to-last digit (tens place), and so on.

After going through all the digits, the cars will be in perfect order from smallest to largest number!

🏎️ 🚗 🚓 🚙

Speed: Very fast for numbers with limited digits (O(nk) where k is the number of digits)

Memory: Needs some extra space for buckets (O(n+k))

When to use:

Perfect for sorting numbers, ZIP codes, dates, or anything where items have the same format and limited range, like organizing race results or student ID numbers.

Steps: 0
Comparisons: 0
Swaps: 0
70
89
50
59
92
24
26
69
49
74
86
18
Slower ←→ Faster

Counting Sort

Count and Place!

Imagine you have colored balls and need to organize them by color. You first count how many of each color you have (3 red, 2 blue, 4 green, etc.).

Then you just place them in order: all the red balls first, then all the blue balls, then all the green balls, and so on!

🔴 🔵 🟢 🟡

Speed: Very fast when the range of values is small (O(n+k) where k is the range of values)

Memory: Needs extra space for counting (O(k))

When to use:

Great for sorting items with a small range of values, like test scores from 0-100, ages of people, or sorting coins by their value.

Steps: 0
Comparisons: 0
Swaps: 0
79
32
65
73
100
51
63
84
19
32
60
34
Slower ←→ Faster

Bucket Sort

Sorting into Buckets!

Imagine sorting toys by size. You have buckets labeled "tiny," "small," "medium," and "large." You toss each toy into the right bucket based on its size.

Then you sort the toys within each bucket and finally put all buckets together in order. That's bucket sort!

🧸 🪀 🧩 🎯

Speed: Very fast when data is evenly distributed (Average: O(n+k))

Memory: Needs space for buckets (O(n+k))

When to use:

Great for sorting data that's spread evenly across a range, like sorting students by their grades (A, B, C, D, F) or organizing clothes by size (XS, S, M, L, XL).

Steps: 0
Comparisons: 0
Swaps: 0
87
16
28
60
59
41
60
84
70
79
79
84
Slower ←→ Faster

Shell Sort

The Big Jump Sort!

Imagine organizing books on a shelf, but instead of comparing only neighboring books, you compare books that are far apart from each other first.

You start by comparing books that are, say, 5 spaces apart, then 3 spaces, then 1 space (neighbors). This helps move books to their approximate positions quickly!

📗 📘 📙 📕

Speed: Better than simple sorts, varies based on gap sequence (Average: O(n log² n))

Memory: Very good! Doesn't need extra space (O(1))

When to use:

Good for medium-sized arrays when you want something faster than simple sorts but don't need the fastest possible solution. Used in some embedded systems where memory is limited.

Steps: 0
Comparisons: 0
Swaps: 0
52
50
85
27
67
19
51
82
58
85
93
11
Slower ←→ Faster

Now You're a Sorting Expert!

Remember, different sorting methods are useful for different situations. The best method depends on what you're sorting and how many items you have!

Post a Comment

Comment Me ;)

Previous Post Next Post