Announcements Exam 2: 03/11, PA2______,HW3______. Today: Loose - - PowerPoint PPT Presentation

announcements exam 2 03 11 pa2 hw3 today loose ends
SMART_READER_LITE
LIVE PREVIEW

Announcements Exam 2: 03/11, PA2______,HW3______. Today: Loose - - PowerPoint PPT Presentation

Announcements Exam 2: 03/11, PA2______,HW3______. Today: Loose ends Associative Arrays Hash Tables Intro to Hash Functions Loose ends Classic balanced BST structures: Red-Black trees max ht 2log 2 n. Constant # of rotations


slide-1
SLIDE 1

Announcements – Exam 2: 03/11, PA2______,HW3______. Today: Loose ends Associative Arrays Hash Tables Intro to Hash Functions

slide-2
SLIDE 2

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-3
SLIDE 3

Hashing - using “hash tables” to implement _________

Structure of a dictionary:

Key -> Value Locker # -> student Course Number -> Schedule info Color -> BMP Vertex -> Set of incident edges Flight number -> arrival information 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”];

Hash Table:

One way of implementing dictionaries Commonly appears as an associative array

slide-4
SLIDE 4

Hashing:

(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?