Insertion sort is a simple comparison-based sorting algorithm that builds the sorted list one element at a time. It works by iterating through the list, taking one element at a time, and inserting it into its correct position relative to the already sorted portion of the list. This process continues until the entire list is sorted.
Key Characteristics:
Time Complexity:
- Worst and average case: O(n²), where n is the number of elements.
- Best case: O(n) when the list is already sorted.
Space Complexity: O(1), as it is an in-place sorting algorithm.
#skinformativespot
#education
#datastructure
#sorting
#insertionsort
#bestcase
#averagecase
#worstcase
#timecomplexity
#spacecomplexity
#O(n)
#skinformativespot