Wednesday, 1 April 2015

Binary Search Trees!

Binary search trees are different from regular binary trees in that they are already sorted - everything thing to the left of a node is smaller than the node and everything to the right of the node is larger than the node. This makes searching through a binary search tree much more efficient since the maximum number of checks the program would have to go through is the height of the tree. This would occur if the program reaches the bottom of the tree and still hasn't found the value it's looking for.

Also, different tree traversals were discussed in class: pre order, post order and in order.

Pre order visits the node itself before visiting the left node in pre order and then finally visiting the right node pre order.

Post order visits the left and right nodes in post order first (in that order - left then right) before visiting the node itself last.

In order visits the left node in order first and then visits the node itself before finally visiting the right node in order.

It was quite confusing at first transversing trees in a particular pattern but after some practice it proved to be quite simple in actuality!

No comments:

Post a Comment