First we need to make sure the input, the given arguments for our function, that is two binary trees. And the output is a merged tree.
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.
For our last She’s coding data structure and algorithm event I chose minimum depth of binary tree problem to practice tree traversing with our participants. It can be challenging at first, with the help of depth first search and breadth first search we can solve it easily.
Binary search tree, as shown in its name, is a ordered tree data structure. Every parent nodes has at most two children, every node to the left of a parent node is always less than the parent and every node to the right of the parent node is always greater than the parent.