Comparison Based vs Non Comparison Based Sorting
📖 Scenario: You work in a warehouse where you need to organize boxes by their weights. Some boxes have small weights (0 to 9 kg), and others have larger weights. You want to sort these boxes quickly using two different methods: one that compares boxes directly and one that uses their weight values without direct comparison.
🎯 Goal: Build two sorting methods in C++: one using comparison-based sorting (Bubble Sort) and one using non-comparison-based sorting (Counting Sort). See how they sort the same list of box weights.
📋 What You'll Learn
Create an array called
boxes with these exact weights: 4, 2, 7, 3, 8, 2, 3, 0, 9, 1Create an integer variable called
size that stores the number of boxesWrite a function called
bubbleSort that sorts the boxes array using comparison-based sortingWrite a function called
countingSort that sorts the boxes array using non-comparison-based sortingPrint the sorted arrays after each sorting method
💡 Why This Matters
🌍 Real World
Sorting items quickly is important in warehouses, online stores, and many apps to organize data efficiently.
💼 Career
Understanding different sorting methods helps in choosing the right algorithm for performance in software development and data processing jobs.
Progress0 / 4 steps