Stage 4 · Lesson 7 of 10
Searching and sorting
Searching an unsorted list means checking every item, which is O(n) in . If the list is sorted, checks the middle and throws away half the list at each step, which is O(log n). That is about 20 steps for a million items.
This is why sorting matters. Simple sorts such as bubble, selection and compare pairs and take O(n²). and the sorts built into your language take O(n log n).
Implement binary search and one simple sort yourself to understand them, then use the built-in sort in real code. Binary search is famous for bugs, so test yours on lists of size 0, 1 and 2.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure built from first principles, with solutions in Python, Java, C++, JavaScript and C#
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
Free: weeks 3 and 5 cover searching, sorting, linked lists, hash tables and trees
Practise
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms