cst370 week 6

This week we reviewed four different structures for fast search and updates. We started from learning that a binary search tree that is built from sorted inputs is skewed and is effectively a linked list, so search becomes O(n) instead of O(n log n). AVL trees were introduced that keep a measure of the balance of its subtrees. When a subtree is imbalanced as the result of an insert, we rotate at the imbalanced node closest to the new leaf. The direction of rotation depends on the skew of the new leaf. A 2-3 tree lets a node hold two sorted values and promotes the middle value of an overfull node that comes as a result of an insert. The tree grows at the root and all leaves stay level. Heaps are my favorite binary tree. We studied max heaps, where each parent's value is greater than its children. Getting the max value is O(1) because it's stored at the front of the array (when using array representation). Inserting and removing the max is O(log n). Heapsort is deleting the max node n-1 times. Hash tables were the last structure we looked at, both using separate chaining to store multiple values in a single table entry or by using linear probing to insert into the hashed entry or the next empty slot. Once a load factor of a hash table is reached we need to grow the table and rehash. In all of these there are tradeoffs for how speed and space are managed. The tree solutions maintain O(log n) time, but hash tables have O(1) lookups but there is a O(n) cost to rehashing when the table grows.

Comments

Popular posts from this blog

week 15-16/100

week 8/100

CST 334 Week 3 (27/100)