I wanted to write about some of the problems I ran into while doing Exercise 5 earlier this week, but felt like I should wait until the due date of the assignment before posting solutions or anything.
e5a.py was relatively simple. I'm sure there were many different methods to solve the problem, but I worked under the assumption that Danny wanted us to do it recursively. The "base case" in this case would just be setting the depth attribute of the node as "depth", and then we would reuse the function with a value of depth + 1.
e5b.py was surprisingly difficult, but after having solved it, I don't know why I had so much trouble with it. I think the problem I had was that I tried to go in without a plan. But breaking down the problem makes it seem very straightforward:
-Is the cargo of the node a leaf? If so, append it to a list.
-What properties does a node have to have to be considered a leaf?
-Is the cargo of the node an internal node? If so, append it to a separate list.
-What properties does a node have to have to be considered an internal node?
The main issue I had was actually implementing the code. The lists I created kept reinitializing every time the function was being run. I fixed this by messing around on my own and looking up sample list functions on StackOverflow.
It is a good idea that you rethink about how you could analyse a problem more efficiently. This is a good practice.
ReplyDeleteYeah, I definitely agree with you. Planning the code before execution let me finish much earlier than just taking random shots in the dark.
Delete