Key Word(s): Binary trees
Exercise 1¶
Create an iterable named Fibonacci
and an iterator named FibonacciIterator
. The Fibonacci
iterable should be used to create a FibonacciIterator
of a specified number of terms. The FibonacciIterator
should iterate over the Fibonacci sequence and return the next value in the sequence. Here's a basic use case with some output:
fib = Fibonacci(10) # Create a Fibonacci iterator called fib that contains 10 terms
list(iter(fib)) # Iterate over the iterator and create a list.
[1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
Note that the very first term ($0$) was not printed out, but you are welcome to do so.
Deliverables¶
fibo.py
- Contains the
FibonacciIterator
andFibonacci
classes. - Includes a demo like the one above.
- Contains the
Exercise 2¶
In Homework 5 and 6, you will implement BSTs. The implementation should be able to insert new values and optionally be able to delete values from the tree. This exercise is meant to help guide you through the conceptual ideas.
Consider the array $$\left[13, 7, 19, 17, 3, 29, 5, 31, 2, 11\right].$$ Do the following:
- Draw a BST for the array
- Create new trees by deleting the nodes with the following values
- $13$
- $29$
- $31$
Note: The result of part 2 will be three different trees.
Deliverables¶
Submit a picture (.jpg
or .png
) of each tree. This can be three separate files or a single file with all three trees in it.