Suppose you are tasked with sorting a small array of integers, where most elements are already sorted in ascending order. Which sorting algorithm would be most suitable for this scenario and why?

  • Insertion Sort
  • Merge Sort
  • Quick Sort
  • Selection Sort
Insertion Sort would be the most suitable algorithm for this scenario. It has an average-case time complexity of O(n), making it efficient for small arrays, especially when elements are mostly sorted. Its linear time complexity in nearly sorted arrays outperforms other algorithms.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *