Balanced Trees
Binary Search Trees (BST's) are great for storing data and
give us great speed...or do they?
- Trees offer much faster access than lists, but only if the tree so long as all the branches are nearly the same length, i.e.
"balanced".
- A balanced tree gives O(log n) behavior, while lists give O(n) behavior.
(See the quick refresher on "Big-O" analysis of
programs.)
- Worst case scenario for an unbalanced tree is O(n) behavior.
One really wants BSTs and other trees to be balanced for
optimal performance!
Kind of like an n-ary tree but with multiple pieces of data on
each tree root (node).
An extension of the idea of a BST where the ordering of the
data in the child trees depends on the data in the parent node.
Additional materials:
Take-away
The main points of this discussion, besides teaching you
about 2-3-4 and B-trees, is for you to see the following in action:
- How stepping back and re-assessing a traditional and "well understood"
model leads to greater understanding of the system plus a simplified
solution.
- How having a large number of cases does not
imply that there are a large number of distinguishable cases.
- How extended visitors can make short work of complex problems by easily
handling large numbers of cases.
- How commands can be used to dynamically capture a situation
(environment) whose information is to be used at a later time.
- How the technique of "candidate data" can be used to abstract a search
into process that minimizes the amount of calculations at any given step.
© 2020 by Stephen Wong