Articles tagged with #computer-science

Math for CS: Recursive Definition

Recursive data - define something in terms of simpler version of the same thing. Recursive data types play a central role in programming, and induction is really all about them. Recursive data types are specified by recursive definitions, which say how to construct new data elements from previous ones. Along with …



Intro to CS: Problem Set 3

Finished the problem set in about an hour. It was a good exercise. Here is my solution along with test case results: My solution: # Purpose: Check for similarity between two texts by comparing different kinds of word statistics. import string import math ### DO NOT MODIFY THIS FUNCTION def load_file(filename …



Systematic Program Design: Week 9a - Generative Recursion

Generative Recursion Module Generative recursion is in many ways similar to structural recursion: a function calls itself recursively (or several functions call themselves in mutual recursion). For the recursion to terminate, each recursive call must receive an argument that is in some way "closer to the base case". That is …



Intro to CS: Lecture 14 - Dictionaries

Topics: Dictionaries: keys, values, mutability, iteration over a dict, examples This is review for me, I am familiar with dictionaries. I guess one new thing I learned is that dictionary keys must be immutable or technically hash-able objects. Although in practice this is obvious.



Intro to CS: Lecture 13 - Exceptions, Assertions

Topics: Exceptions, assertions Introduced to the try/except code blocks, with some examples. Also introduced to assertions, as a way to program defensively. I sort of forgot about assertions so this is good review. I will look to use them in my future code. They are good for enforcing invariants …



Math for CS: State Machines -- Invariants

State machines are a simple, abstract model of step-by-step processes. One of the most important uses of induction in computer science involves proving one or more desirable properties continues to hold at every step in a process. A property that is preserved through a series of operations or steps is …



Intro to CS: Lecture 12 - List comprehension, functions as objects, testing, debugging

Topics: More Functions as Objects, Keyword Arguments, Default Arguments, Debugging: glass box/black box testing, examples List comprehensions are review for me. Default parameters are also review. Functions can return another function. Why bother returning functions? Code can be rewritten without returning function objects Good software design Embracing ideas of …



Intro to CS: Lecture 11 - Aliasing, Cloning

Topics: Aliasing and cloning Going over some operations on lists, including .clear(), .pop(), del() and .remove(). Iterating over a list as you are mutating the list can lead to unpredictable behavior. Takeaway here is to be careful when mutating a list while iterating over it. Consider using a copy. = sign …



Systematic Program Design: Week 8 - Abstraction

Abstraction Module In this module we look another techniques for improving the structure of code. Most of the problems in this module involve refactoring existing programs -- so there's relatively little new coding to do. But that doesn't mean you won't be designing programs! One of the things that separates good …



Math for CS: Problem Set 3 Thoughts

Problem 1: I was able to get the base cases, but couldn’t make the jump to the induction step. I ended up looking at the solution. Problem 2: This was a little complicated, I didn’t even know where to start. So I looked up solution as well. Problem …