GCGrowCarrer

Sorting and Searching

Locked

Lesson 22 of 60 · DataStructures · Medium

Finish these first:Recursion →Lists →Or pass the tests below to unlock it now.

1

The big idea

sorted() and list.sort() are stable O(n log n). Binary search needs sorted data and runs in O(log n).

Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Key words (tap to learn):
2

Read the lesson

sorted() and list.sort() are stable O(n log n). Binary search needs sorted data and runs in O(log n).

sorted(words, key=len, reverse=True)
import bisect
bisect.bisect_left(xs, target)
3

Quick check

Before writing code: What should `binary_search([1,3,5,7],5)` return when your implementation of Sorting and Searching is working?

4

Your challenge

2 sample tests, 1 hidden

Write binary_search(xs, target) returning the index or -1.

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

See how Python compares side-by-side with Java.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Sorting and Searching.

Mastery0%

Learn this first

Opens up next

This is the last lesson in this branch.