Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Sorting AlgorithmsEasy
Q1. What is insertion sort?
- A.A sort that uses divide and conquer recursion
- B.A sort that inserts each element into correct position✓ Correct
- C.A sort that only works on integer data types
- D.A sort that inserts elements into a heap structure
Explanation
Insertion sort builds the final sorted array one element at a time by picking each element and inserting it at its correct position in the already sorted portion.
Report an error in this question
Sorting AlgorithmsEasy
Q2. Is bubble sort a stable sorting algorithm?
- A.Yes, it is stable✓ Correct
- B.Only for integer data
- C.Only for string data
- D.No, it is unstable
Explanation
Bubble sort is stable because it only swaps adjacent elements when they are in the wrong order, preserving the relative order of equal elements.
Report an error in this question
Sorting AlgorithmsEasy
Q3. How many passes does bubble sort need in the worst case for n elements?
- A.n - 1✓ Correct
- B.log n
- C.n
- D.n/2
Explanation
Bubble sort requires at most n - 1 passes through the array to guarantee all elements are in their correct positions.
Report an error in this question
Sorting AlgorithmsEasy
Q4. Which sorting algorithm is best for nearly sorted data?
- A.Merge sort
- B.Quick sort
- C.Selection sort
- D.Insertion sort✓ Correct
Explanation
Insertion sort performs very well on nearly sorted data, achieving close to O(n) time since few elements need to be moved.
Report an error in this question
Sorting AlgorithmsEasy
Q5. What is bubble sort?
- A.A sort that divides the array in half each time
- B.A sort that selects the minimum element each pass
- C.A sort that uses a heap for element ordering
- D.A sort that swaps adjacent out-of-order elements✓ Correct
Explanation
Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
Report an error in this question
Sorting AlgorithmsEasy
Q6. What is the space complexity of selection sort?
- A.O(n^2)
- B.O(1)✓ Correct
- C.O(n)
- D.O(log n)
Explanation
Selection sort is an in-place sorting algorithm that uses only a constant amount of extra space, O(1).
Report an error in this question
Sorting AlgorithmsEasy
Q7. What is the worst-case time complexity of bubble sort?
- A.O(log n)
- B.O(n log n)
- C.O(n^2)✓ Correct
- D.O(n)
Explanation
Bubble sort has O(n^2) worst-case time complexity when the array is sorted in reverse order.
Report an error in this question
Sorting AlgorithmsEasy
Q8. What is selection sort?
- A.A sort that works only on linked list nodes
- B.A sort that uses binary search for placement
- C.A sort that finds minimum and places it correctly✓ Correct
- D.A sort that selects a random pivot element
Explanation
Selection sort divides the array into sorted and unsorted parts, repeatedly selecting the minimum from the unsorted part and adding it to the sorted part.
Report an error in this question
Sorting AlgorithmsEasy
Q9. What is the best-case time complexity of insertion sort?
- A.O(n log n)
- B.O(n^2)
- C.O(n)✓ Correct
- D.O(1)
Explanation
When the array is already sorted, insertion sort only makes one comparison per element, giving O(n) time.
Report an error in this question
Sorting AlgorithmsEasy
Q10. Is selection sort a stable sorting algorithm?
- A.Only for numeric data
- B.No, it is unstable✓ Correct
- C.Yes, it is stable
- D.Depends on implementation
Explanation
Selection sort is generally not stable because it swaps non-adjacent elements, which can change the relative order of equal elements.
Report an error in this question
Sorting AlgorithmsMedium
Q11. What is the average-case time complexity of quick sort?
- A.O(log n)
- B.O(n log n)✓ Correct
- C.O(n^2)
- D.O(n)
Explanation
Quick sort has an average-case time complexity of O(n log n) when the pivot divides the array reasonably well.
Report an error in this question
Sorting AlgorithmsMedium
Q12. What is the space complexity of merge sort?
- A.O(n)✓ Correct
- B.O(n^2)
- C.O(1)
- D.O(log n)
Explanation
Merge sort requires O(n) additional space for the temporary arrays used during merging.
Report an error in this question
Sorting AlgorithmsMedium
Q13. Is merge sort a stable sorting algorithm?
- A.Only for linked lists
- B.Yes, it is stable✓ Correct
- C.Only for array inputs
- D.No, it is unstable
Explanation
Merge sort is stable because during merging, when two elements are equal, the one from the left subarray is placed first.
Report an error in this question
Sorting AlgorithmsMedium
Q14. What is the worst-case time complexity of quick sort?
- A.O(n)
- B.O(log n)
- C.O(n^2)✓ Correct
- D.O(n log n)
Explanation
Quick sort's worst case is O(n^2), occurring when the pivot is always the smallest or largest element (e.g., already sorted array with first element as pivot).
Report an error in this question
Sorting AlgorithmsMedium
Q15. What is heap sort's time complexity?
- A.O(log n)
- B.O(n)
- C.O(n log n)✓ Correct
- D.O(n^2)
Explanation
Heap sort builds a heap in O(n) and performs n extract-max operations each costing O(log n), giving O(n log n) overall.
Report an error in this question
Sorting AlgorithmsMedium
Q16. What is the divide-and-conquer strategy in merge sort?
- A.Divide the array into three equal parts
- B.Divide in half, sort each half, then merge✓ Correct
- C.Divide by selecting a random pivot element
- D.Divide into sorted and unsorted portions
Explanation
Merge sort divides the array into two halves, recursively sorts each half, and then merges the two sorted halves.
Report an error in this question
Sorting AlgorithmsMedium
Q17. What is the time complexity of merge sort?
- A.O(n)
- B.O(log n)
- C.O(n log n)✓ Correct
- D.O(n^2)
Explanation
Merge sort always divides the array in half and merges in linear time, giving O(n log n) in all cases.
Report an error in this question
Sorting AlgorithmsMedium
Q18. What is the role of the pivot in quick sort?
- A.It is always the first element chosen
- B.It is always the exact median value
- C.It partitions into smaller and larger groups✓ Correct
- D.It merges two sorted subarrays together
Explanation
The pivot is used to partition the array: elements smaller than the pivot go to one side, and elements larger go to the other.
Report an error in this question
Sorting AlgorithmsHard
Q19. What is introsort?
- A.A merge sort variant with optimizations
- B.A pure insertion sort variant
- C.A hybrid starting with quicksort switching to heapsort✓ Correct
- D.A non-comparison sort using radix method
Explanation
Introsort starts with quicksort but switches to heapsort when the recursion depth exceeds O(log n), ensuring O(n log n) worst-case while retaining quicksort's practical efficiency.
Report an error in this question
Sorting AlgorithmsHard
Q20. What is the worst-case time complexity of randomized quick sort?
- A.O(n)
- B.O(n^2)✓ Correct
- C.O(n log^2 n)
- D.O(n log n)
Explanation
Randomized quick sort still has O(n^2) worst case, but the probability is extremely low. The expected (average) time is O(n log n).
Report an error in this question
Sorting AlgorithmsHard
Q21. What is bucket sort?
- A.A sort that only works on string data
- B.A sort distributing elements into buckets then merging✓ Correct
- C.A merge sort variant with fixed partitions
- D.A comparison sort using memory buckets
Explanation
Bucket sort distributes elements into a number of buckets, sorts each bucket individually (often with insertion sort), and concatenates the results.
Report an error in this question
Sorting AlgorithmsHard
Q22. What is TimSort?
- A.A real-time sorting algorithm for streaming data
- B.A sort that runs in constant time for all input
- C.A sort named after its time complexity class
- D.A hybrid stable sort using merge and insertion sort✓ Correct
Explanation
TimSort is a hybrid sorting algorithm derived from merge sort and insertion sort. It identifies natural runs in the data and merges them efficiently. Used in Python and Java.
Report an error in this question
Sorting AlgorithmsHard
Q23. What is radix sort's time complexity for n integers with d digits?
- A.O(n × d^2)
- B.O(d × (n + k)) where k is the base✓ Correct
- C.O(n^2)
- D.O(n log n)
Explanation
Radix sort processes each digit using a stable sort (like counting sort), taking O(n + k) per digit for d digits, giving O(d × (n + k)).
Report an error in this question
Sorting AlgorithmsHard
Q24. When is bucket sort most efficient?
- A.When data is in reverse sorted order
- B.When the array is extremely large in size
- C.When input is uniformly distributed over a range✓ Correct
- D.When data has many duplicate values present
Explanation
Bucket sort achieves O(n) average time when input is uniformly distributed, as each bucket will have roughly the same number of elements.
Report an error in this question
Sorting AlgorithmsMedium
Q25. What is the space complexity of heap sort?
- A.O(n log n)
- B.O(n)
- C.O(log n)
- D.O(1)✓ Correct
Explanation
Heap sort is an in-place sorting algorithm that uses O(1) extra space (the heap is built within the original array).
Report an error in this question
Sorting AlgorithmsMedium
Q26. What is counting sort?
- A.A comparison-based sorting method
- B.A non-comparison sort counting occurrences✓ Correct
- C.A sort that uses a heap structure
- D.A divide-and-conquer sorting approach
Explanation
Counting sort counts the occurrences of each distinct value and uses those counts to place elements in the correct position. It runs in O(n + k) time where k is the range.
Report an error in this question
Sorting AlgorithmsHard
Q27. Is quick sort a stable sorting algorithm?
- A.Only with Lomuto partition scheme
- B.Only when using random pivots
- C.Yes, always stable
- D.No, in its standard implementation✓ Correct
Explanation
Standard quick sort is not stable because the partitioning process can change the relative order of equal elements.
Report an error in this question
Sorting AlgorithmsHard
Q28. What is the Dutch National Flag problem in the context of sorting?
- A.Coloring a graph with three distinct colors
- B.Sorting elements of three different colors
- C.Sorting using three different algorithms
- D.Three-way partitioning around a pivot value✓ Correct
Explanation
The Dutch National Flag problem involves three-way partitioning: elements less than, equal to, and greater than a pivot are grouped together. It is useful in quick sort with many duplicates.
Report an error in this question
Sorting AlgorithmsHard
Q29. What is external sorting?
- A.Sorting using network-based remote requests
- B.Sorting data too large for memory using disk✓ Correct
- C.Sorting using external third-party libraries
- D.Sorting on external hardware devices only
Explanation
External sorting handles data too large for RAM by dividing it into chunks, sorting each in memory, and merging sorted chunks from disk (e.g., external merge sort).
Report an error in this question
Sorting AlgorithmsHard
Q30. What is the time complexity of sorting n strings of maximum length s using radix sort?
- A.O(s log n)
- B.O(n^2 × s)
- C.O(n × s)✓ Correct
- D.O(n log n)
Explanation
Radix sort processes each character position from least significant to most significant, giving O(n × s) for n strings of maximum length s.
Report an error in this question