0
0
DSA Javascriptprogramming~5 mins

Counting Sort Algorithm in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind the Counting Sort Algorithm?
Counting Sort counts how many times each number appears, then uses these counts to place numbers in the right order without comparing them directly.
Click to reveal answer
beginner
Which type of data is Counting Sort best suited for?
Counting Sort works best for sorting numbers that are small and within a known range, like ages from 0 to 100.
Click to reveal answer
intermediate
What is the time complexity of Counting Sort and why?
Counting Sort runs in O(n + k) time, where n is the number of elements and k is the range of input values, because it counts and places elements without comparisons.
Click to reveal answer
intermediate
How does Counting Sort ensure stability (keeping original order of equal elements)?
Counting Sort uses the counts to find exact positions for elements and places them from right to left, preserving the order of equal elements.
Click to reveal answer
intermediate
What is a limitation of Counting Sort compared to comparison-based sorts?
Counting Sort needs extra space proportional to the range of input values, so it is not efficient if the range is very large compared to the number of elements.
Click to reveal answer
What does Counting Sort use to sort elements?
ACounting how many times each value appears
BComparing elements pairwise
CSwapping elements randomly
DDividing elements into halves
Which of these is a requirement for Counting Sort to work efficiently?
AInput must be floating point numbers
BInput must be already sorted
CInput values must be strings
DInput values must be integers within a small range
What is the space complexity of Counting Sort?
AO(n + k), where k is the range of input values
BO(1), constant space
CO(n log n)
DO(n^2)
How does Counting Sort place elements to maintain stability?
ABy swapping elements randomly
BBy placing elements from right to left using counts
CBy sorting elements in reverse order
DBy ignoring original order
Counting Sort is NOT suitable when:
AThe input contains only positive integers
BThe input is small and within a small range
CThe range of input values is very large
DThe input is already sorted
Explain how Counting Sort works step-by-step on a small list of numbers.
Think about counting first, then using counts to find positions.
You got /4 concepts.
    What are the advantages and disadvantages of Counting Sort compared to other sorting algorithms?
    Consider speed and memory use.
    You got /2 concepts.