Comparison Based vs Non Comparison Based Sorting
📖 Scenario: You are working in a small online store. You want to sort the list of product prices to show the cheapest items first. You will learn two ways to sort: one by comparing prices directly, and another by using counting since prices are whole numbers.
🎯 Goal: Build two sorting methods: one using comparison (like bubble sort) and one using counting sort (non-comparison). Then print the sorted prices from both methods.
📋 What You'll Learn
Create an array called
prices with exact values: [40, 10, 30, 20, 10]Create a variable called
maxPrice and set it to 40Write a function called
bubbleSort that sorts the prices array using comparisonWrite a function called
countingSort that sorts the prices array using counting sort and maxPricePrint the sorted arrays from both
bubbleSort and countingSort💡 Why This Matters
🌍 Real World
Sorting prices helps customers find cheaper products quickly in online stores.
💼 Career
Understanding different sorting methods is important for optimizing software performance in real-world applications.
Progress0 / 4 steps