Professional Documents
Culture Documents
CS50 2023 Notes
CS50 2023 Notes
Lecture 0
problem solving = ^^
inside the box is typically an algorithm
8 bits in a byte.
1 byte can represent 255 different values (remember this since it’s the reason RGB stores up to 255
too)
A = 65, B = 66 …
Lecture 1 - Arrays
Lecture 3 - Algorithms
Lecture #3 - Memory
In C, you need to init values for yourself — else you have garbage values that can be anything!
Hashing
Taking a larger domain and reducing it to a smaller domain. Like taking a deck of cards and splitting it
into suits (before trying to sort the deck). Since you’re then taking a whole class of problems and
reducing it from 1x52 to 4x13. A hash function is used to do this.
` `
Hash Tables
where x is the number of collisions. So you have a tradeoff decision to make based on the nature of
your data — either accept this tradeoff or make the initial array more granular (e.g., bucketing by first
letter → bucketing by first 2 letters) in exchange for using more memory.
** **
In the worst case (e.g., every name starts with H), a hash table is O(n) . But a well-designed hash
` `
table is O(n/k) where k is some constant, so it reduces back down to O(n) . But in practice, it can
` ` ` `
be many times faster than another O(n) structure like a linked list.
` `
Tries
Tries are an O(1) data structure.
` `
E.g. a linked list is very efficient at insertion but quite poor at search
Lecture #6 - Python
```python
```py
x = [1,2,3]
x += [4] # equivalent to x.append(4)
```
```py
x, y = y, x # swap values
```
Lecture #7 - SQL
```
$ sqlite3
sqlite> .mode csv
sqlite> .import favorites.csv favorites
sqlite> .schema
```
Can ease into joining by starting out with nested queries instead
```py
https://www.reddit.com/r/AskReddit/s/tQIbVauGfE
Survivor.ai
Spades AI
something something RAG