📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store

    • Question

      Which of the following sorting algorithms has the best

      average-case time complexity?
      A Bubble Sort Correct Answer Incorrect Answer
      B Insertion Sort Correct Answer Incorrect Answer
      C Selection Sort Correct Answer Incorrect Answer
      D Quick Sort Correct Answer Incorrect Answer
      E Merge Sort Correct Answer Incorrect Answer

      Solution

      Quick Sort is a widely used sorting algorithm that, on average, exhibits a time complexity of O(n log n). This efficiency stems from its divide-and-conquer approach, where the algorithm selects a 'pivot' element and partitions the array into elements less than and greater than the pivot. It recursively sorts the sub-arrays created by this partitioning. Quick Sort is particularly effective for large datasets due to its average-case performance and in-place sorting capability, which means it requires less additional memory compared to algorithms like Merge Sort. While Quick Sort has a worst-case time complexity of O(n^2), which can occur with poor pivot choices (e.g., already sorted data), various strategies, such as randomization or choosing the median as the pivot, can help mitigate this risk. Option A is incorrect because Bubble Sort has an average-case time complexity of O(n^2), making it inefficient for large datasets. Option B is incorrect as Insertion Sort also has an average-case complexity of O(n^2), though it performs well on small or nearly sorted datasets. Option C is incorrect for the same reason as Insertion Sort; Selection Sort also has O(n^2) average-case complexity. Option E, Merge Sort, while having an O(n log n) average-case complexity, requires additional space for merging, making Quick Sort generally faster in practice due to its in-place nature.

      Practice Next

      Relevant for Exams:

      ask-question