Posts

Showing posts from June, 2017

6.00.1x - Week 3

Image
3.5.1 Tuples ordered sequence of mixed element types immutable, represented with parentheses () must add comma ',' at the end of 1 element tuple, convenient for swapping variable values 3.5.2 Lists ordered sequence of mixed element types mutable, represented with square brackets [] https://docs.python.org/3/tutorial/datastructures.html 3.5.3 List Operations append, extend (change the list) del, pop, remove, list (convert string to list) sort vs. sorted, reverse range returns something that behaves like a tuple or a list 3.5.4 Mutation, Aliasing, Cloning clone: chill = old[:] sort: mutates the list, returns nothing sorted: does not mutate list, returns a new sorted list 3.5.5 Functions as Objects Can pass function name as parameter map(abs, [1, -2, -3, -4] => [1, 2, 3, 4] map(min, L1, L2) 3.6.1 Quick Review 3.6.2 Dictionaries instead of using multiple lists, use dictionary represented with curly braces: {} mutable, keys, values, no order key:

6.00.1x - Week 2

Image
2.3.1 Simple Algorithms slice string using: start:stop:step s[::-1] reverse the string string is immutable 2 ways to write for loop: "for char in s" "for index in range(len(s))" 2.3.2 Approximate Solutions Exhaustive enumeration start with initial guess step: any small number, takes many steps 2.3.3 Bisection Search takes log time to get an answer works well with problem with "ordering" property: value increases as input increases print("Hi", end=' ') print("there") will print "Hi there" 2.3.4 Floats and Fractions This is why sometimes we get weird result because in binary you can get close to it, but not exact Should not use == to compare float, instead use abs(a-b) < epsilon 2.3.5 Newton-Raphson Algorithm Approximation algorithm to find roots of a polynomial: g -> g - p(g)/p'(g) Even better than Bisection search

6.00.1x - Week 1

1.1 Introduction: Machine are good at calculations and remember results. Some problems require better algorithm to solve faster. Some problems are fundamentally hard:turing halting or decrypt encryption which is benefical for us. 1.1 Knowledge Declarative knowledge: statement of fact Imperative knowledge: recipe, how to solve Algorithm = sequence of steps + flow of control + when/how to stop 1.2 Machines Fixed program vs. Stored program Core of machine: Memory, Arithmetic Logic Unit (ALU), and Control Unit with program counter Interpreter vs Compiler: read 1 Turing machine: infinite tape, 6 primitives: move left, move right, scan, read, write, do nothing Anything computable in one language is computable in any other programming language 1.3 Languages Expression: legal combination of primitives Syntax: combination of primitives that makes sense, legal expression Static semantics: valid syntax that has meaning Semantic: meaning associated with a syntac