Announcements PA2______,HW3______. AVL tree analysis: Putting an - - PowerPoint PPT Presentation

announcements pa2 hw3 avl tree analysis
SMART_READER_LITE
LIVE PREVIEW

Announcements PA2______,HW3______. AVL tree analysis: Putting an - - PowerPoint PPT Presentation

Announcements PA2______,HW3______. AVL tree analysis: Putting an upper bound on the height for a tree of n nodes is the same as putting a lower bound on the number of nodes in a tree of height h. Define N(h): Find a recurrence for


slide-1
SLIDE 1

Announcements – PA2______,HW3______. AVL tree analysis:

Putting an upper bound on the height for a tree of n nodes is the same as putting a lower bound on the number of nodes in a tree of height h.

  • Define N(h):
  • Find a recurrence for N(h):
  • We simplify the recurrence:
  • Solve the recurrence: (guess a closed form)
slide-2
SLIDE 2

AVL tree analysis: prove your guess is correct.

Thm: An AVL tree of height h has at least 2h/2 nodes, ________. Consider an arbitrary AVL tree, and let h denote its height. Case 1: _______ _______ _______ _______ _______ _____ Case 2: _______ _______ _______ _______ _______ _____ Case 3: _______ then, by an Inductive Hypothesis that says ________________________________________________________, and since ________________________________________________________, we know that ________________________________________________________. Punchline:

slide-3
SLIDE 3

Loose ends… Classic balanced BST structures:

  • Red-Black trees – max ht 2log2n.

Constant # of rotations for insert, remove, find.

  • AVL trees – max ht 1.44log2n.

O(log n) rotations upon remove.

Balanced BSTs, pros and cons:

  • Insert, Remove, and Find are always O(log n)
  • An improvement over:
  • Range finding & nearest neighbor
  • Possible to search for single keys faster
  • If data is so big that it doesn’t fit in memory it must be stored on disk and we require a

different structure.

slide-4
SLIDE 4

Hashing - using “hash tables” to implement _________

Structure of a dictionary:

Key -> Value Locker # -> student Course Number -> Schedule info Vertex -> Set of incident edges URL -> html page dice roll -> payoff amt

Associative Array:

Dictionary with a particular interface Overloads operator[] for insert and find

myDict[“Miguel”] = 22; int d = myDict[“Miguel”];

(defn) Keyspace – a (math) description of the keys for a set of data. Goal of hashing: use a function to map the keyspace into a small set of integers. What’s fuzzy about this goal? Problem: Keyspaces are often large…

slide-5
SLIDE 5

hash function array

ex: insert is d[k] = v; client code declares an object of ADT dictionary

dict<ktype, vtype> d;

class dict

(implemented with a hash table)

k

A Hash Table consists of:

  • Overview:
slide-6
SLIDE 6

A perfect hash function:

1 2 3 4 5 6 7

(Ann, black cat) (Ben, HP) (Cory, spy) (David, bball player) (Ellen, butterfly) (Finn, cereal killer) (Gus, ghost) (Harmony, bee) A contrived example:

these keys have a fabulous hash fn.

  • a. each key hashes to a different int
  • b. collection of keys hash to a seq of ints
slide-7
SLIDE 7

A perfect hash function?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Is this a good hash function?

Roll 5 dice:

slide-8
SLIDE 8

General Purpose Hash Functions

KeySpace

1 …

N-1

KeySpace

keys used: 1 …

N-1

Easy, if |KeySpace| ~ N

What characterizes a good hash function?