Friday, 18 March 2016

Week 9 - Binary Trees and Binary Search Trees

This week, we learned Binary Trees (BT)  and Binary Search Trees (BST).

A Binary tree is a tree with only two children. Binary Search tree is a special kind of Binary Tree in that it has an order in which it arranges data which makes it easy to perform search operations. The BST is arranged in a way that there is a root node with a comparable object and all the values that are less than this object are placed in the left subtree and all the values greater than it are placed in the right subtree. This is also true of all the subtrees in the BST. A comparable type is a type in which the objects can be compared. For example, int, float and string. BST is useful for search operations because it is ordered. So if we want to find a value in a tree, we don't have to search the whole tree because a value smaller than the root node will be searched only on the left subtree and a value larger than the root node will only be searched for in the right subtree. This way, I think that the worst case will have to do as many steps as the longest path in the tree, which is certainly better than searching the entire tree.

In the coming weeks, I hope to see applications of trees and binary trees. I think their unique structure sets them apart from structures like stacks and queues and would really like to know how they are used in practical situations. I especially wonder if, in practice, data that is prone to be searched often is placed inside Binary Search Trees instead of lists. That would be a very interesting topic to explore.

No comments:

Post a Comment