This week focused on Binary Search Trees, which is a Tree ADT that uses only 2 child nodes per parent node so as to speed up searching through large amounts of data. Every node has a 'left' child and a 'right' child, and it is assumed that there is a distinction between what goes left and what goes right. The most common use for a BST was searching for a specific integer. In an integer BST, an initial integer is chosen to be the initial node. Smaller integers are placed to the left of it, and larger ones are placed to the right of it. This pattern holds for all nodes in the BST, and what you're left with is a tree that is organized from smallest to largest. This structure is helpful in speeding up searches for specific integers, since it eliminates either the entire left or right portion of the tree right at the beginning, and it cuts the search time by a hefty amount.
In fact, searching through an organized binary search tree is so effective that it uses logarithmic runtime, which means that the runtime of the search algorithm increases logarithmically as the number of elements in the tree increases.
There are, of course limitations. The BST has to be organized before you can use such an algorithm, so the data type isn't intrinsically efficient. Still, if we were to keep this in mind while creating a BST, we'd find that it is one of the most efficient algorithms we've learned thus far.
No comments:
Post a Comment