Intro to
Programming
with Python

Fall 2010
course
navigation

nov 18

Chapter 13 in the text: on to "computer science"
Once you have the basics of "how to write a program", then what?
The analogy is writing: once you know how to put together a subject, verb, and object, you can write a sentence. But the content of what you can write about is a much bigger topic.
Likewise, "computer science" as a field is about how to best represent and implement various information-related tasks. The recipes for doing these sorts of things are called "algorithms", and so the next step is often to look at them.
For example, given a collection of numbers, how do we find if something specific is in there?
First: try as a class exercise. How many different algorithms can you suggest? How can we measure how good they are?
Turns out there's a particularly interesting to do some algorithms, called "recursion".
Discuss the idea and go over the attached code examples : search.py, fib.py, hanoi.py
Linear search is O(n); binary search is O(log(N)). Define these terms and give specific examples.
There are many other tricks besides recursion, for example wikipedia: memoization (particularly helpful for the fibonacci program, for example) and wikipedia: hash functions.
Depending on time, we can also discuss approaches to sorting ; see wikipedia: sorting and http://www.sorting-algorithms.com
http://cs.marlboro.edu/ courses/ fall2010/python/ notes/ nov_18
last modified Wednesday November 17 2010 9:11 pm EST

attachments [paper clip]

     name last modified size
   fib.py Nov 17 2010 9:11 pm 644B    hanoi.py Nov 17 2010 9:11 pm 1.64kB    search.py Nov 17 2010 9:11 pm 1.73kB