Log in

No account? Create an account

Previous Entry | Next Entry

Video Notes
Lec 4 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 - 51:27

So far we have assignment, conditionals, input/output, and looping constructs. This has given us a Turing complete language, enough to write any program. To write code we write it all in one long file. We lack decomposition and abstraction, and that's what we'll add now. Decomposition is breaking up code into modules, reusable, that isolate components of the process. One mechanism for that are functions. They let us break up into modules, suppress detail and let us make new primitives. Syntax of a function: def (variables): Variables are formal parameters. There is a function return that returns from the function and returns the value of the next expression and returns it as the value of the function. For example "return 5", would make 5 the value of the function. Variables defined in parenthesis for a function are local, they have values only within the function. Local bindings do not affect global bindings. Without functions we'd have to copy the same code in all sorts of places and edit it individually everywhere.

Enumerate and check is an example of a brute force algorithm. Instead of using formulas to solve equations we use for loops to iterate through all the possibilities until we find the correct one.

If a function returns a topple with return (x, y) then we can get that answer with x, y = function(x, y). Tooples and lists are very similar and in most cases can be interchanged.

Recursion is when a function calls itself. Base case is the simplest possible solution to the problem. Inductive step is breaking the problem into simpler version of the same problem and other steps. A good example of recursion is Fibonacci.


Future Master

Latest Month

September 2012
Powered by LiveJournal.com
Designed by Tiffany Chow