Sorting methods that decide the order by comparing elements with each other, like checking if one number is bigger or smaller than another.
Click to reveal answer
beginner
Name two common comparison based sorting algorithms.
Bubble Sort and Quick Sort are examples of comparison based sorting algorithms.
Click to reveal answer
beginner
What is non comparison based sorting?
Sorting methods that do not compare elements directly but use other information like digits or keys to sort, such as counting or grouping.
Click to reveal answer
beginner
Give an example of a non comparison based sorting algorithm.
Counting Sort is an example where elements are sorted by counting how many times each value appears.
Click to reveal answer
intermediate
Which type of sorting can be faster than comparison based sorting for certain data, and why?
Non comparison based sorting can be faster because it uses the structure of data (like digits) instead of comparing each pair, which can reduce time especially for numbers within a limited range.
Click to reveal answer
Which sorting method uses direct comparisons between elements?
ARadix Sort
BNon comparison based sorting
CCounting Sort
DComparison based sorting
✗ Incorrect
Comparison based sorting relies on comparing elements to decide their order.
Which algorithm is NOT comparison based?
ACounting Sort
BQuick Sort
CMerge Sort
DHeap Sort
✗ Incorrect
Counting Sort sorts by counting occurrences, not by comparing elements.
What is the best time complexity lower bound for comparison based sorting?
AO(n log n)
BO(n)
CO(log n)
DO(n^2)
✗ Incorrect
Comparison based sorting cannot be faster than O(n log n) in the average or worst case.
Which sorting type can achieve linear time complexity under certain conditions?
AComparison based sorting
BNon comparison based sorting
CBubble Sort
DSelection Sort
✗ Incorrect
Non comparison based sorting like Counting Sort can run in O(n) time if data range is limited.
Radix Sort is an example of which sorting category?
ADivide and conquer sorting
BComparison based sorting
CNon comparison based sorting
DIn-place sorting
✗ Incorrect
Radix Sort sorts numbers digit by digit without direct comparisons.
Explain the main difference between comparison based and non comparison based sorting.
Think about how the sorting decides order.
You got /4 concepts.
List examples of comparison based and non comparison based sorting algorithms and their typical use cases.
Recall algorithm names and when they are preferred.
You got /4 concepts.
Practice
(1/5)
1. Which of the following sorting algorithms is non-comparison based?
easy
A. Merge Sort
B. Quick Sort
C. Counting Sort
D. Heap Sort
Solution
Step 1: Understand comparison based sorting
Comparison based sorting algorithms decide order by comparing elements, like Merge Sort, Quick Sort, and Heap Sort.
Step 2: Identify non-comparison based sorting
Counting Sort uses counting frequencies and does not compare elements directly.
Final Answer:
Counting Sort -> Option C
Quick Check:
Non-comparison based = Counting Sort [OK]
Hint: Non-comparison sorts use counting or buckets, not element comparisons [OK]
Common Mistakes:
Confusing Quick Sort as non-comparison
Thinking Heap Sort is non-comparison
Assuming all sorts compare elements
2. Which of the following is the correct syntax to call Radix Sort method named RadixSort on an integer array arr in C#?
easy
A. RadixSort(arr);
B. arr.RadixSort();
C. RadixSort<int>(arr);
D. RadixSort arr;
Solution
Step 1: Understand method call syntax in C#
Calling a static method with an array argument uses method name and parentheses with the array inside.
Step 2: Analyze options
RadixSort(arr); uses correct syntax: RadixSort(arr); arr.RadixSort(); tries to call as instance method which is incorrect unless defined so. RadixSort<int>(arr); uses generic syntax unnecessarily. RadixSort arr; is invalid syntax.
Final Answer:
RadixSort(arr); -> Option A
Quick Check:
Static method call = RadixSort(arr); [OK]
Hint: Static method calls use MethodName(args) syntax [OK]
Common Mistakes:
Using instance method call on array
Adding unnecessary generic syntax
Writing invalid declaration instead of call
3. What will be the output of the following C# code snippet?
int[] arr = {4, 2, 2, 8, 3, 3, 1};
CountingSort(arr);
Console.WriteLine(string.Join(", ", arr));
void CountingSort(int[] array) {
int max = array.Max();
int[] count = new int[max + 1];
foreach (int num in array) count[num]++;
int index = 0;
for (int i = 0; i <= max; i++) {
while (count[i] > 0) {
array[index++] = i;
count[i]--;
}
}
}
medium
A. 8, 4, 3, 3, 2, 2, 1
B. 1, 2, 2, 3, 3, 4, 8
C. 4, 2, 2, 8, 3, 3, 1
D. 1, 1, 2, 2, 3, 3, 4
Solution
Step 1: Understand Counting Sort logic
Counting Sort counts occurrences of each number and then writes them back in sorted order.