Wednesday, 19 March 2014

Binary Search

A binary search tree is a convenient way to find objects. It has a big-omicron of log2(n), which makes the program more efficient dealing with larger sets of data.

By learning this I had finally realized why a traversal which takes the left branch of a node first, then the symbol of the node it self, then finally the right branch is called an "in-order" traversal... If it were a binary search tree, then its in-order traversal will be just a list of the numbers sorted in ascending order.

Though more efficient in looking for data, the coding part is much more complicated than a linear search method. For different types of input we actually have to use a lot of "if" statements to deal with them separately. Good news is that once I understand what the code should be able to do, the coding part is not that challenging. A problem I always have is understanding the task a function should do in order to reach the goal. When I'm dealing with some seemingly complex tasks I have to keep calm and go through the requirements to be met... ask for help... and finish the coding part quickly. Perhaps I just need to do more practices.

No comments:

Post a Comment