Counting Sort Algorithm
📖 Scenario: You work in a warehouse where you need to sort boxes by their weight quickly. Each box's weight is a small whole number. You want to organize them from lightest to heaviest using a fast method.
🎯 Goal: Build a program that sorts a list of box weights using the counting sort algorithm. This method counts how many boxes have each weight and then arranges them in order.
📋 What You'll Learn
Create a slice called
weights with exact values: 4, 2, 2, 8, 3, 3, 1Create a variable called
maxWeight to store the highest weight in weightsImplement counting sort logic using a count slice to store frequencies
Print the sorted slice of weights
💡 Why This Matters
🌍 Real World
Counting sort is useful in warehouses or factories where items have small integer weights or categories and need fast sorting.
💼 Career
Understanding counting sort helps in roles like software development and data processing where efficient sorting of limited-range data is required.
Progress0 / 4 steps