CSS 343: Notes from Lecture 6 (DRAFT)
Red Black Trees Again
-
Standard template libary
std::map
container is typically implemented using a red-black tree
-
SGI STL implementation is available for
download
-
reading the code may hurt your brain
B Trees Again
-
Some confusion about putting the overflow key into the parent
node: it doesn't
really
work this way
-
it's an idea for exposition, but it appears to be hindering
rather than helping understanding
-
the algorithm is
recursive
and does not require a parent pointer
-
Sample B Tree animation:
btree-animation.zip
Hashing
Coming RSN...
Priority Queues
-
a binary search tree is geared toward random insert and removal
-
a special case is random insert, remove minimum element
-
a binary heap is a complete binary tree with the minimum element
at the root
-
a heap is
not
a binary search tree
-
the heap invariant is that each node is less than its children
-
by "less than", we could easily mean "greater than"
-
in fact, any ordering predicate will work:
-
sort strings by ASCII value
-
sort lexically
-
convert string to number and sort numerically
-
sort points in plane by distance from origin
-
etc.
-
new entries are inserted at bottom-most left-most leaf position,
breaking the invariant
-
the invariant is restored by sifting up (iteratively swaping
with parent)
-
removing minimum element: remove root and replace with
bottom-most rightmost leaf.
-
heap invariant is restored by sifting down (swaping with the
smaller of the child nodes)
-
animation (click for larger image):