>>    




Homework Assignment

CS 121 (CS1)

Homework 2   Due Friday, February 14, 2014
  1. Python Data (Chap 2) questions

    1. -- Simple Python Data chapter problems at end of chapter: 1[H], 2[H], 4, 5, 6[H], 10, 12.
      • The problems marked [H] should be written out on paper and submitted in class.

      • The other problems are short programs. Submit these via email to cs1b-graders@stolaf.edu (copying and pasting your code into an email is sufficient; screenshots not needed for these problems).


  2. Reading


  3. CS Trees [h]

    1. ancestors -- Ancestor trees. A tree is a diagram consisting of edges (usually drawn as straight line segments) that do not intersect except at some endpoints of those edges, and which contain no "cycles" (in which following a path of edges returns to the same point). The idea comes from the branch of Mathematics called Graph Theory, and the name "tree" is inspired by biological trees, as suggested in the diagrams below. Here, the red overlay in the second image depicts a tree of edges in this sense.
      (Image from Wikimedia Commons - licensing.)
      As indicated in the diagram, a point in a tree that is the endpoint of one or more edges is called a node, and a point that is the endpoint of only one node is called a leaf; one node in a tree may be designated as the root node (our trees will generally have roots). We also consider a single isolated point to constitute a tree with zero edges, called an empty tree.

      Note: In Computer Science, we frequently draw trees "upside down." For example, the red tree sketched on the right image above would commonly be drawn as

      instead of
      with the root node at the top.

      Also, we consider trees to be equivalent if the have the same configuration of nodes and edges, even if the edges have different lengths and/or different angles. For example, we consider the blue tree below to be equivalent to the red tree above.

      The nodes of a tree may also be labelled, as follows:

      Here, we have labelled the leaves of the tree with capital letters and the non-leaf nodes with lower-case letters, but any labelling could be used.

      DO THIS: Draw an ancestor tree for a real or fictional person, in which each node represents a person, and edges connect parent(s) to a child. Draw your tree so that parents appear on the same level and above a child. For example, here is an ancestor tree for Prince George, the first child of Prince William and Kate (Duke and Duchess of Cambridge in England):

      Note: (1) Siblings do not appear in an ancestor diagram, nor step-parents, but only parents for a child. For example, Charles' sister and brothers do not appear in the diagram above, and any future brother(s)/sister(s) of young George will not appear in George's ancestor diagram. (2) If you're familiar with genograms: These "ancestor trees" are different. For example, they omit divorces, siblings, etc. (3) You can draw an ancestor diagram for yourself or a friend or family member, or you can choose someone else whose information you can obtain. For example, you might research and draw a diagram for Laura Knickerbacker Simpson, found on the Wikipedia page for the Rockefeller family, or a fictional character like Galadriel in Tolkien's Lord of the Rings (authorized editions of The Return of the King contain relevant data, though not necessarily in the form of a ancestor tree).