Friday, March 11, 2016

Entry 7: Week 8: Tree Powers Activate

It seems like we have done a lot after last week... Although only a week has passed? The pace of learning is definitely picked up as there are only a month to school left. Quite scary actually. I had just realized that we have a test next Wednesday after Danny had said so this week, and that the finals are also coming up soon. I am definitely stressed.

From last week to this, there are two topics covered -- even more recursion, and trees, which branches (ahaha) into trees with a defined number of nodes, and binary trees. These two are closely related as most methods for trees requires recursion. The best practice for recursion in trees is probably additional.py under Lab 7 (which the directory can be found here). This file clearly organizes many different useful methods for trees into practices, and can be used as a reference "library" to the class trees.

Recursion:
  • Base Case: stopping condition
    • may have several!!!
  • Recursive step: subcall of own function
Trees (Branched):
  • Number nodes uncertain
  • Arity = max(num children under node)
  • Height = max(num level)
  • Node -(edge)- children -- grandchildren --etc
    • has children [list] == root
    • has no children == leaf
  • Path: sequence of nodes from a1 ->???->an
    • length = num(edge of path)
  • Depth: # layers in
  • More terminology found here.
  • Pre-order:
    • node => children
  • Post-order
    • children => node
  • Level-Order:
    • Depth by depth
    • using WHILE loop
      • recursing using call(n-1)
      • recursing using queue
Trees (Binary):
  • Left/Right = 2 children only
  • Subtypes:
    • Binary Search Trees: L < N < R
      • run time \lceil log_2 numnodes \rceil
    • Arithmetic Trees
      • data = operation
      • leaf = values
  • Difference in Traversals:
    • in-order: L -> node -> R
    • post-order: R -> node -> L
Usable Code:
  • all([list of bool] = \forall = for all
  • any([list of bool]) = \exists = there exist
  • {sets, of, elements}
    • unordered
    • mutable (unless "frozen set")
    • iterable
    • considers only value of elements
    • ex: dictionary

No comments:

Post a Comment