announcements pa2 hw3 avl tree analysis
play

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


  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)

  2. AVL tree analysis: prove your guess is correct. Thm: An AVL tree of height h has at least 2 h/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:

  3. Loose ends… Classic balanced BST structures: • Red-Black trees – max ht 2log 2 n. Constant # of rotations for insert, remove, find. • AVL trees – max ht 1.44log 2 n. 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.

  4. Hashing - using “hash tables” to implement _________ Structure of a dictionary: Associative Array: Key -> Value Dictionary with a particular interface Locker # -> student Overloads operator[] for insert and find Course Number -> Schedule info myDict[“Miguel”] = 22; Vertex -> Set of incident edges int d = myDict[“Miguel”]; URL -> html page dice roll -> payoff amt (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…

  5. Overview: class dict client code (implemented with a hash table) declares an object of ADT dictionary array dict<ktype, vtype> d; ex: insert is d[k] = v; hash function k A Hash Table consists of: • • •

  6. A perfect hash function: (Ann, black cat) 0 (Ben, HP) 1 (Cory, spy) 2 (David, bball player) 3 (Ellen, butterfly) 4 (Finn, cereal killer) 5 (Gus, ghost) 6 (Harmony, bee) 7 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

  7. 0 A perfect hash function? 1 2 3 Roll 5 dice: 4 5 6 7 8 9 10 11 12 13 14 15 Is this a good hash function? 16 17 18 19

  8. What characterizes a good hash function? • • • General Purpose Hash Functions KeySpace Easy, if N-1 0 1 … |KeySpace| ~ N KeySpace keys used: N-1 0 1 …

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend