MIT 600 Flashcards
Algorithm
Sequence of steps
Flow of control process that specifies when each step is executed
A means of determining when to stop
Turning Complete
Anything computable in one language is computable in any other programming language.
Syntax
Determines if code is legal.
Static Semantics
Determines whether code has meaning.
Semantics
Assigns meaning to a legal sentence.
Python Types
Int-integer
Float-real numbers
Bool-boolean, True + False
NoneType - special, value of None.
Casting
Type conversion, i.e.
Changing from Int type to Float.
Float(5)–5.0
Branch Programs
Simplest is a condition. A test, a block of code to execute if true, and optional block to execute if false.
Is a linear program, runs in constant time.
String
Letters, special characters, spaces, digits encompass in single or double quotes.
Concatenation
Adding string together, i.e.
AB+CD=ABCD
While Loops
If condition if true, run code, check condition, repeat until false
Bisection Search -Sqrt Example
Know square root of x is between 1 and x. Rather than starting at 1, start at a number in the middle.
If not close enough, if g**2>x, g is too big.
Throws away half if possible guesses each iteration
Bisection Search Big Oh
Logarithmic time, log2N steps
Implications of Binary
If there’s is not an integer p such that x*(2**p) is whole, then the internal representation is an approximation.
Newton-Raphson
Approximation to root, g is the approximation;
g-p(g)/p1(g) is a better approximation where p1 is the derivative.
Abstraction
Suppress details of method to compute something from the use of that computation
Decomposition
Break problem into different, self-contained pieces
Function
Reusable piece or chunk of code, not run in a program until called or invoked.
Recursion
Divide and conquer or decrease and conquer. Technique where a function calls itself.
Flow passes back to previous scope once the function call returns the value.
Module
A .py file containing of collection of python definitions and statements. Call using the import keyword.
Tuples
Ordered sequence of elements
Immutable, cannot change element values
Represented with parentheses
Iteratable and can be sliced
List
Order sequence of elements
Denotes by square brackets
Mutable
Iterable, can be indexed
List Operations
L.append() L.extend() del(L[index]) L.pop() remove and return the element L.remove(element) removes first occurrence
Memoization
optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
Defensive Programming
Write specifications for functions
Modularity Programs
Check conditions on inputs/outputs
Unit Testing
Validate each piece of program. Testing each function separately.
Regression Testing
Add test for bugs as you find them. Can reintroduce errors that were previously fixed
Integration Testing
Does the overall problem work?