Professional Documents
Culture Documents
Lecture 3 - CS50x 2022
Lecture 3 - CS50x 2022
This is CS50x
CS50’s Introduction to Computer Science
OpenCourseWare
Donate (https://cs50.harvard.edu/donate)
Lecture 3
Last week
Searching
Big O
Linear search, binary search
Searching with code
Structs
Sorting
Selection sort demonstration
Bubble sort demonstration
Selection sort
Bubble sort
Recursion
Merge sort
Last week
https://cs50.harvard.edu/x/2022/notes/3/ 1/20
9/17/23, 2:56 PM Lecture 3 - CS50x 2022
Recall that our purpose for learning a new programming language and other tools is to
solve problems. And we solve those problems by creating some output from input:
We learned about memory, which allows us to store data as bytes, and strings, which are
arrays of characters.
Searching
Recall that arrays are zero-indexed, meaning that the first item has an index of 0.
And with n items, the highest index would be n − 1.
Searching is how we solve the problem of finding information. A simple problem has an
input of some values, and an output of a bool , whether or not a particular value is in the
array.
Big O
Today we’ll look at algorithms for searching. To compare their efficiency, we’ll consider
running time, or how long an algorithm takes to run given some size of input.
Computer scientists tend to describe running time with big O notation, which we can
think of as “on the order of” something, as though we want to convey an idea of running
time and not an exact number of milliseconds or steps.
In week 0, we saw a chart with different types of algorithms and the times they might
take to solve a problem:
https://cs50.harvard.edu/x/2022/notes/3/ 2/20