NOTES:

  • This web page summarizes the topics covered in COMP 208 in Fall 2023. Detailed course materials (slides, lecture recordings, exercises, etc) are available on the mycourses page for students registered in the course.

  • There is a large overlap (about 80%) between the topics covered in this course and COMP 202 and 204. The main differences are that COMP 208 uses examples and covers a few extra topics that are accessible to students with a background in basic Calculus and Linear Algebra. I encourage BSc students in the Phys/Chem/Math/CS to take COMP 208 rather than 202 in order get some exposure to these examples and topics.

  • COMP 202, 208, and 204 (for Life Sciences) are equivalent as prerequisites for further COMP courses at McGill, namely COMP 250 and COMP 206.

  • Here is the COMP 208 Course Outline from Fall 2023.

LECTURE TOPICS

  • Introduction course outline, binary numbers, converting from binary to decimal. Binary in computers: int, float, text, images & audio. Programming languages: high and low level, compilers vs interpreters.
  • Python basics, IDE's (Thonny) Hello World. Comments, strings, statements, errors. Print function. String concatenation. Escape sequences. Values and types. Type casting. Shell vs editor. Operators (+, *). Syntax coloring (green functions and pink strings).
  • Variables and assignment statements. Variable naming rules and conventions, objects, aliasing, swapping, garbage collection. Input prompt. Operations on numbers. implicit casting. order of operations. expressions.
  • Operators Comparison operators, boolean values. equality and float. logical operators (not, and, or), boolean expressions and short circuit evaluation. shorthand assignments (e.g. x += 3).
  • Control flow : if, if-else if-elif,nesting & indentation. Style.
  • Functions built in math functions, void versus non-void, creating own function: header, parameters, body. Nested functions. Flow of execution. void functions that take input, arguments, scope (local vs global variables), function parameters. None type. Non-void functions: return statements, examples of non-void functions. Docstrings.
  • Loops : while loops, iteration. if versus while. infinite loop. for loops : break, continue, and while vs. for.
  • Numerical methods as examples of loops: Newton's method for sqrt, numerical integration using midpoint method (for loop), root finding using bisection.
  • Modules and import: __name__ and "__main__", math, Turtle, random
  • Strings : indexing, slicing, immutability. string methods, in, traversing a string with while/for loops, loop by value/index, off-by-one errors
  • Debugging: syntax errors, runtime errors & code execution, logic errors, infinite loops, Using print statements vs. debugger. Raising exceptions. doctest.
  • Lists: indexing, slicing, concatenating, replicating, in, not in. list functions and methods. List patterns: reduce, map, filter. List comprehension. String methods, some using lists: strip, split, join.
  • List algorithms: Linear search. Binary search. Bubble sort.
  • Mutability. id(), "is" versus ==, lists vs strings. Optimization issues (caching, garbage collection).
  • Nesting: nested loops, nested lists, shallow and deep copy of a list.
  • File IO. open, methods: read, write, close. iterating over lines, appending to file. CSV format, pickle
  • Tuples. unpacking and multiple assignments. for loops and lists of tuples. enumerate
  • Sets and Dictionaries . keys (immutable and unique) and values, adding and removing items, KeyError, dict methods : get, pop, keys, values, len, in, iterating through dict, set/dict comprehensions
  • Matplotlib. Visualization.
  • OOP: classes, instantiating objects, attributes. constructors, default arguments, instance methods, __str__, copy module
  • NumPy: creating array, type, indexing, shape, mathematical ops, vectorization, slicing reference vs copy, boolean indexing, matrices (creation, eye, reshape, indexing, operations incl. matrix mult), image analysis, random in np, seed, distributions, random walks, Monte Carlo integration, linear algebra: numpy matrix manipulations, Gauss-Jordan elimination, linear regression