HomeSubjectsUniversityBlogAbout

Sorting Algorithms

Topic in Data Structures & Algorithms

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

A sorting algorithm rearranges the elements of a list into a defined order, typically ascending or descending, based on a comparison or key. MCQs demand you know best, average and worst-case costs: bubble, selection and insertion sort run in O(n^2), while merge sort and heap sort guarantee O(n log n) and quicksort averages O(n log n) but can degrade to O(n^2) with poor pivots. Stability and in-place behaviour are frequent traps, for example stable merge sort versus unstable heap sort. Non-comparison methods such as counting sort in O(n + k) and radix sort in O(d(n + k)) appear, along with the Dutch National Flag partitioning problem.

Below are 30 practice questions from a pool of 210 Sorting Algorithms MCQs, one of 12 topics in Data Structures & Algorithms. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

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?

  1. A.A sort that uses divide and conquer recursion
  2. B.A sort that inserts each element into correct position✓ Correct
  3. C.A sort that only works on integer data types
  4. 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?

  1. A.Yes, it is stable✓ Correct
  2. B.Only for integer data
  3. C.Only for string data
  4. 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?

  1. A.n - 1✓ Correct
  2. B.log n
  3. C.n
  4. 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?

  1. A.Merge sort
  2. B.Quick sort
  3. C.Selection sort
  4. 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?

  1. A.A sort that divides the array in half each time
  2. B.A sort that selects the minimum element each pass
  3. C.A sort that uses a heap for element ordering
  4. 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?

  1. A.O(n^2)
  2. B.O(1)✓ Correct
  3. C.O(n)
  4. 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?

  1. A.O(log n)
  2. B.O(n log n)
  3. C.O(n^2)✓ Correct
  4. 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?

  1. A.A sort that works only on linked list nodes
  2. B.A sort that uses binary search for placement
  3. C.A sort that finds minimum and places it correctly✓ Correct
  4. 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?

  1. A.O(n log n)
  2. B.O(n^2)
  3. C.O(n)✓ Correct
  4. 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?

  1. A.Only for numeric data
  2. B.No, it is unstable✓ Correct
  3. C.Yes, it is stable
  4. 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?

  1. A.O(log n)
  2. B.O(n log n)✓ Correct
  3. C.O(n^2)
  4. 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?

  1. A.O(n)✓ Correct
  2. B.O(n^2)
  3. C.O(1)
  4. 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?

  1. A.Only for linked lists
  2. B.Yes, it is stable✓ Correct
  3. C.Only for array inputs
  4. 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?

  1. A.O(n)
  2. B.O(log n)
  3. C.O(n^2)✓ Correct
  4. 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?

  1. A.O(log n)
  2. B.O(n)
  3. C.O(n log n)✓ Correct
  4. 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?

  1. A.Divide the array into three equal parts
  2. B.Divide in half, sort each half, then merge✓ Correct
  3. C.Divide by selecting a random pivot element
  4. 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?

  1. A.O(n)
  2. B.O(log n)
  3. C.O(n log n)✓ Correct
  4. 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?

  1. A.It is always the first element chosen
  2. B.It is always the exact median value
  3. C.It partitions into smaller and larger groups✓ Correct
  4. 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?

  1. A.A merge sort variant with optimizations
  2. B.A pure insertion sort variant
  3. C.A hybrid starting with quicksort switching to heapsort✓ Correct
  4. 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?

  1. A.O(n)
  2. B.O(n^2)✓ Correct
  3. C.O(n log^2 n)
  4. 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?

  1. A.A sort that only works on string data
  2. B.A sort distributing elements into buckets then merging✓ Correct
  3. C.A merge sort variant with fixed partitions
  4. 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?

  1. A.A real-time sorting algorithm for streaming data
  2. B.A sort that runs in constant time for all input
  3. C.A sort named after its time complexity class
  4. 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?

  1. A.O(n × d^2)
  2. B.O(d × (n + k)) where k is the base✓ Correct
  3. C.O(n^2)
  4. 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?

  1. A.When data is in reverse sorted order
  2. B.When the array is extremely large in size
  3. C.When input is uniformly distributed over a range✓ Correct
  4. 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?

  1. A.O(n log n)
  2. B.O(n)
  3. C.O(log n)
  4. 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?

  1. A.A comparison-based sorting method
  2. B.A non-comparison sort counting occurrences✓ Correct
  3. C.A sort that uses a heap structure
  4. 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?

  1. A.Only with Lomuto partition scheme
  2. B.Only when using random pivots
  3. C.Yes, always stable
  4. 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?

  1. A.Coloring a graph with three distinct colors
  2. B.Sorting elements of three different colors
  3. C.Sorting using three different algorithms
  4. 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?

  1. A.Sorting using network-based remote requests
  2. B.Sorting data too large for memory using disk✓ Correct
  3. C.Sorting using external third-party libraries
  4. 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?

  1. A.O(s log n)
  2. B.O(n^2 × s)
  3. C.O(n × s)✓ Correct
  4. 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

Ready to test yourself on Sorting Algorithms?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Sorting Algorithms Quiz