Mid-Term Lessons
- Knuth quote
Code that works but that is incomprehensible is bad
code.
- Back-of-the-envelope calculations
The pigeon hole principle
n2
1 - (1/n) lg n
(n + 1) / n
- Iterators
OTA option feeds.
- Loop and algorithm termination
Can't put value where pointer should be!
Ex:
while current->next != NULL:
current = current->next
current->next = value
Even if you code it right, it's too complicated.
- "Minor" bugs in the real world
Just set timeout to 0!
- Short-circuit or?
- What to return?
Don't just print!
Library code can be running anywhere. Set-top box. Car engine.
Phone. Satellite.
"Siri, I'd like the number for Ashwin Ravishankar."
Returning the key of a dictionary search.
Returning True if the key is there.
- Direct addressing "function"
- Recognize problem in new context
- Indicator variables
- Deleting from linked lists
Singly versus doubley linked code.
- Can't assign number to a function!
h(x) = h1(x) + h2(x)
- Exponential growth:
n
|
n2
|
1.1n
|
10
|
100
|
2.59
|
50
|
2500
|
117.39
|
100
|
10,000
|
13,780.6
|
200
|
40,000
|
189,905,276
|