Was doing some more trees. I felt like it was better. I'm starting to fall in love with them. But I am NOT head over heels. The power of float("inf") and float("-inf").
No-No-No-Notes:
- I finished up trees
- Being good with trees is the versatility of using iterative and recursive solutions. Sometimes the recursive solution makes it a lot easier like inorder recursive or postorder traversals
- It is possible to do these traversals with iteration, but it takes a lot more logic
- One problem i encountered was checking valid BST. It sounds easy, but you have to compare with the root value no matter what. To check that a value is correct and in the right spot you can pass a range of values as a tuple. Ex. (root, float("-inf"), float("inf"))
- Recursion can get really hard to code if you get confused. So take a step back, think about the base case, and think about the simplest, basic approach first before adding any add ons. The add-ons can confuse someone really easy.
No comments:
Post a Comment