Week 7, we continued studying Trees, specifically, binary trees.
In this week's lab, we looked at evaluating a simple math statement, such as 3 + 4.
The node would be the operation, i.e., '+', and its children would either be numbers, or another operation.
That means that we would have to pay attention to the order of operations by placing parentheses around the correct evaluation statements.
The first function that we had to write, parenthesize, was not difficult.
All we had to do was access the value stored in each node, and place parenthesize before and after the return statement.
However, I had trouble with the lab after that function.
For example, the next function, list_longest_path, I managed to get down the base cases, which is
1. if the root node is None, return [].
2. I knew I had to check the length of the left nodes and compare it to the right nodes, but had no idea how to implement. The TA told me my base case was correct, and whatever I had for the following elif statement containing the recursive statement was missing something to compare the length of the list of the left and right nodes.
Actually, I had trouble implementing the functions after parenthesize...
I felt like I was asking the TA way too many questions and I still didn't know how to do it. I didn't want him to get too frustrated with me...
Hopefully there will be sample solutions soon!
No comments:
Post a Comment