Time and Space Complexity
Lesson 7 of 9 in Coddy's Selection Sort - DSA Series course.
Time Complexity:
- Best, Average, and Worst Case: O(n2)
- Selection Sort always scans the entire unsorted part to find the minimum, even if the array is already sorted. The number of comparisons does not depend on the input order.
Space Complexity:
- O(1)
- Selection Sort is an "in-place" algorithm. It rearranges the elements using only a constant amount of extra memory, no matter how large the input is.
Summary:
- Selection Sort is simple and memory-efficient.
- It performs few swaps (at most n-1), which is useful when writes are costly.
- Its quadratic time makes it a poor choice for large datasets, where algorithms like Merge Sort or Quick Sort are preferred.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Selection Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)