πŸ“’ 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 sorting algorithm is best suited for a nearly

      sorted array, exhibiting O(N) time complexity in its best case?
      A Selection Sort Correct Answer Incorrect Answer
      B Merge Sort Correct Answer Incorrect Answer
      C Insertion Sort Correct Answer Incorrect Answer
      D Heap Sort Correct Answer Incorrect Answer
      E Quick Sort Correct Answer Incorrect Answer

      Solution

      Insertion Sort performs very well on nearly sorted arrays. In the best case, when the array is already sorted, it only needs to iterate through the array once, performing N-1 comparisons and no swaps, resulting in O(N) time complexity. Other algorithms like Selection Sort, Merge Sort, Heap Sort, and Quick Sort generally do not achieve O(N) for nearly sorted inputs.

      Practice Next
      ask-question