Sorting Algorithms
A brief overview of the more common sorting algorithms.
Binary search was efficient when given a pre-sorted data set, but what are the most efficient ways to actually sort data sets? There are many different sorting algorithms, but you are going to focus on three of the most common: bubble sort, merge sort, and quicksort. Each has pros and cons when it comes to their efficiency, as you can see in the table below:
Best Case | Worst Case | Average Case | Space Complexity | |
---|---|---|---|---|
Bubble Sort | O(n) | O(n^2) | O(n^2) | O(1) |
Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
Quicksort | O(n log n) | O(n log n) | O(n^2) | O(log n) |
Author
Codecademy Team
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
Learn more on Codecademy
- Skill path
Code Foundations
Start your programming journey with an introduction to the world of code and basic concepts.Includes 5 CoursesWith CertificateBeginner Friendly4 hours - Career path
Full-Stack Engineer
A full-stack engineer can get a project done from start to finish, back-end to front-end.Includes 51 CoursesWith Professional CertificationBeginner Friendly150 hours