More recursion in Binary Tree
- Binary Tree
- Recursion
- Abstract Data Type
"Binary Tree" is distinguish from the ordinary tree that every node has none or no more than 2 children which are also distinct from each other, the left children has the value less than its parent node's value and the right children should has the value greater than its parent node's value.
Although at first sight, I think it is not that good but even troublesome when act as a data type to store data .
Since, it it works as a data type that used to store things, it has many weaknesses for example it could not guarantee the sequence of a series of numbers and I couldn't find a number by calling its index. However, when it function as a dictionary, it will display its powerful latent energy. For example:
For example, in the Binary Search Tree(BST) like above and a list contain [8,4,9,3,5,10]. If I want to find out whether 10 is in it. I only need one step(by the special property of BST, from 8 I could go straight to the right to the 9 and then to the right side get 10, total 2 steps!) but need 5 steps in the list.
Another example, if I want to find 5, I just need 2 steps(from 8 I could go straight to the left side and then go the right side of 4 which is 5, total 2 steps).But need 4 steps for the list.
With the n the elements it need only about log2(n) steps to find it out,which is much faster than any other data type.
More you practice,More you will learn.
