Write an **iterative** function that checks if a binary tree is balanced, i.e. the difference between the heights of the left and right subtrees is at most 1.
Tips:
- Use af dfs traversal approach (using a stack) using a post-order approach (left, right, and root node)
- For each node, calculate and memorize the current height in a dictionnary
- Check if the current node is balanced, if not return `False`
- Mark the node as visited and store its height
- Return `True` if all the nodes are visited (without an un-balanced situation)
Now write the corresponding tree for the 2 other traversal functions to return values in ascending order (i.e. provide a new tree but do not change the functions)
## Exercise 5: Check if a binary tree is connected
Write a function to determine if a binary is connected to all the nodes of the tree. Warning: will now use a dictionnary data structure to store the tree.
## Exercise 6: Calculate the diameter of a binary tree
To find the diameter of a binary tree, you need to compute the longest path between any two nodes in the tree. This path may or may not pass through the root. Here is a way to calculate the diameter:
1. Calculate the height of the left and right subtrees for each node
2. Calculate the diameter at each node as the height of left subtree + right subtree
3. Traverse the tree and keep track of the max diameter encountered