Friday, 27 February 2015

Binary Tree

On week 7, professor Denny introduced binary tree. Each node in binary tree has two subtrees (left subtree and right subtree), or no subtree. Moreover, binary tree can represent a binary arithmetic expression because of its property. The definition of binary tree is that data in left subtree are always then than node's data. Similarly, data in the right is bigger than node's data. This gives us a relatively simple way to search. Sometimes we can avoid checking each subtree by comparing data. This saves us a lot of time.
I wrote some functions related to binary tree in this week's lab. All of them required recursion. It was not quite easy to write a recursion line because sometimes the idea was not very clear. It was even harder to express in form of code. To fully understand how to use recursion, I must practise a lot.