Sorting methods that decide the order by comparing elements with each other, like checking if one 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 where elements are compared to sort the list.
Click to reveal answer
beginner
What is non comparison based sorting?
Sorting methods that do not compare elements directly but use other properties like counting or digit positions to sort.
Click to reveal answer
beginner
Give an example of a non comparison based sorting algorithm.
Counting Sort is a non comparison based method that counts occurrences to sort elements.
Click to reveal answer
intermediate
Why can non comparison based sorting be faster than comparison based sorting?
Because they use direct information like counts or digit positions, they can sort in linear time for certain data, unlike comparison sorts which need at least n log n steps.
Click to reveal answer
Which sorting method uses direct element comparisons?
AComparison based sorting
BNon comparison based sorting
CCounting Sort
DBucket Sort
✗ Incorrect
Comparison based sorting relies on comparing elements to decide order.
Which algorithm is an example of non comparison based sorting?
AMerge Sort
BQuick Sort
CCounting Sort
DHeap Sort
✗ Incorrect
Counting Sort uses counts of elements instead of comparisons.
What is the best time complexity lower bound for comparison based sorting?
AO(n log n)
BO(n^2)
CO(n)
DO(log n)
✗ Incorrect
Comparison based sorting cannot be faster than O(n log n) in the general case.
Which sorting type can achieve linear time sorting under certain conditions?
AComparison based sorting
BNon comparison based sorting
CBubble Sort
DInsertion Sort
✗ Incorrect
Non comparison based sorting like Counting Sort can run in O(n) time if data fits constraints.
Radix Sort is an example of which sorting category?
AComparison based sorting
BIn-place sorting
CDivide and conquer sorting
DNon comparison based sorting
✗ Incorrect
Radix Sort sorts numbers by digits without direct comparisons.
Explain the main difference between comparison based and non comparison based sorting.
Think about how the algorithms decide order.
You got /3 concepts.
List examples of comparison based and non comparison based sorting algorithms and their typical use cases.
Consider data size and type.
You got /3 concepts.
Practice
(1/5)
1. Which of the following sorting algorithms is non-comparison based?
easy
A. Merge Sort
B. Counting Sort
C. Quick 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 and indexing, not direct comparisons, so it is non-comparison based.
Final Answer:
Counting Sort -> Option B
Quick Check:
Counting Sort = Non-comparison based [OK]
Hint: Counting Sort uses counts, not comparisons [OK]
Common Mistakes:
Confusing Counting Sort with Quick Sort
Thinking Merge Sort is non-comparison based
Assuming Heap Sort is non-comparison based
2. Which of the following is the correct syntax to call a non-comparison based sorting function CountingSort(arr []int) in Go?
easy
A. CountingSort{arr}
B. CountingSort arr
C. CountingSort(arr)
D. CountingSort->arr
Solution
Step 1: Recall Go function call syntax
In Go, functions are called with the function name followed by parentheses enclosing arguments.
Step 2: Apply syntax to CountingSort
Calling CountingSort with array arr is done as CountingSort(arr).
Final Answer:
CountingSort(arr) -> Option C
Quick Check:
Function call syntax = CountingSort(arr) [OK]
Hint: Use parentheses for function calls in Go [OK]
Common Mistakes:
Omitting parentheses in function call
Using braces {} instead of parentheses
Using arrow notation which is invalid in Go
3. What will be the output of the following Go code snippet?