Outline for October 19, 2023

Reading: §4.5
Due: Homework 2, due October 26, 2023


  1. Recursion
    1. n factorial [nfact.py]

  2. Thinking recursively [recfun.py]
    1. First: think of the recursive case (write the problem in terms of something involving a smaller instance of the problem)
    2. Next: think of base case (when to stop)
    3. Example: Find the length of a string
    4. Example: Does the string only have alphabetic characters in it?
    5. Example: Find the maximum element of a list
    6. Example: Construct a string from a list of strings
    7. Example: Reverse a string

  3. Recursion
    1. Palindromes [palindrome.py]
    2. Fibonacci numbers [rfib.py]
    3. Sum of digits [sumdigits.py]
    4. Greatest common divisor [gcd.py]
    5. Nested lists: is an item in a list? [isinlist.py]
    6. Tower of Hanoi [hanoi.py]

  4. Using random numbers
    1. Problem: compute π by tossing darts at a unit square
    2. First build routine to simulate dart toss at unit square [mc-1.py]
    3. Then build routine to see if co-ordinates are in unit circle [mc-2.py]
    4. Then build routine to read in number of tosses [mc-3.py]
    5. Put it all together [mc-4.py]
    6. Graphics! [mc-5.py]

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
ECS 235A, Computer and Information Security
Version of October 18, 2023 at 10:05PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh