Algorithms for Beginners / Chapter 1 — Foundations (lessons 1–2) / Lesson 1

Algorithms and complexity (reading Big-O)

Time needed: about 10 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

The same problem, solved two ways

When you think "this code feels slow", can you explain what is slow about it?

That is where this course starts.

First we solve one problem — finding the last value in a million sorted records — two ways.

Linear search looks from the front and works on unsorted data.

Binary search compares against the middle and discards half each time, and works only on sorted data.

The line counts are nearly the same, and so are the features used.

editor.py

Tab indents. To leave the editor, press Esc, then Tab.

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.