Unit 8 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Established a set (2-3) of test cases to verify their own solution later.
- Established a set (1-2) of edge cases to verify their solution handles complexities.
- Have fully understood the problem and have no clarifying questions.
- Have you verified any Time/Space Constraints for this problem?
HAPPY CASE
Input: Binary Tree as described in the problem
Output: Poseidon, Atlantis, Oceania, Coral, Pearl, Kelp, Reef
Explanation: The binary tree has been constructed according to the given structure.
EDGE CASE
Input: A binary tree with no children
Output: Just the root node "Poseidon"
Explanation: The binary tree consists only of the root node, with no children or grandchildren.
Match what this problem looks like to known categories of problems, e.g. Linked List or Dynamic Programming, and strategies or patterns in those categories.
For Tree Construction problems, we want to consider the following approaches:
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Construct the binary tree by assigning children to each node according to the diagram provided.
1) Start with the root node "Poseidon".
2) Assign "Atlantis" as the left child of "Poseidon".
3) Assign "Oceania" as the right child of "Poseidon".
4) Assign "Coral" and "Pearl" as the left and right children of "Atlantis", respectively.
5) Assign "Kelp" and "Reef" as the left and right children of "Oceania", respectively.
6) The binary tree is now constructed as depicted in the problem.
⚠️ Common Mistakes
Implement the code to solve the algorithm.
root = TreeNode("Poseidon")
root.left = TreeNode("Atlantis")
root.right = TreeNode("Oceania")
root.left.left = TreeNode("Coral")
root.left.right = TreeNode("Pearl")
root.right.left = TreeNode("Kelp")
root.right.right = TreeNode("Reef")
Review the code by running specific example(s) and recording values (watchlist) of your code's variables along the way.
Evaluate the performance of your algorithm and state any strong/weak or future potential work.
Assume N
represents the number of nodes in the binary tree.
O(1)
because we are simply assigning references to the nodes.O(1)
as we are not using any additional data structures, just creating the nodes.