07-hashes

07-hashes - Spring 2009 CS216: Program and Data...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Hashing and Hash Tables CS216: Program and Data Representation University of Virginia Computer Science Spring 2009 Aaron Bloomfield (not surprisingly, when I did a Google image search for “hash”, nothing appropriate came up…)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Main Topics • ADTs we’ve seen so far • Hash Table ADT – What is it? – Methods of implementing – Applications of hash tables
Background image of page 2
ADTs So Far
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Lists • Operations – find – insert – remove – findKth • Implementations – Array – Linked list
Background image of page 4
5 List Array Linked List find Θ (n) Θ (n) insert Worst: Θ (n) But often Θ (1) Θ (1) remove Θ (n) Θ (n) findKth (by index) Θ (1) Θ (n)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Stacks • List with data handled Last-In First-Out – Operations: • push • pop • top – Implementations • array • linked list
Background image of page 6
7 Stacks Array Linked List push Worst: Θ (n) But often Θ (1) Θ (1) pop Θ (1) Θ (1) top Θ (1) Θ (1)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Queues • First-In First-Out list • Operations – enqueue – dequeue • Implementations – Arrays – Linked Lists
Background image of page 8
9 Queues Array Linked List enqueue Worst: Θ (n) But often Θ (1) Θ (1) dequeue Θ (1) Θ (1)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Trees • Goal – Θ (log n) runtime for most operations – Binary search trees – AVL Trees – Splay trees – Red-black trees
Background image of page 10
11 Trees BST AVL Splay Red-black find Θ (h) log n < h <= n-1 Worst: Θ (n) Θ (log n) Θ (log n) amortized Θ (log n) insert Θ (h) log n < h <= n-1 Worst: Θ (n) Θ (log n) Θ (log n) amortized Θ (log n) remove Θ (h) log n < h <= n-1 Worst: Θ (n) Θ (log n) Θ (log n) amortized Θ (log n)
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 Is There Anything Faster? • Fastest possible search using binary comparison: Θ (log n) • Yes: (almost) constant time is possible: Θ (1) – Hash tables (lookup table) • Operations – find – insert – delete • No ordering property – no findMin or findMax
Background image of page 12
Hash Tables
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 Important Terms • Hash table – Key – Hash function • Collision – Collision resolution approaches • Separate chaining • Open addressing – Linear probing » Primary clustering – Quadratic probing » Secondary clustering – Double hashing – Rehashing • Load factor
Background image of page 14
15 Key-value pairs • Hash tables store key-value pairs – Each value has a specific key associated with it – Keys and values need not be the same type! • Examples – Definitions: “set”, “ v.tr. 1. To put in a specified position…” – Uva e-mail redirects: “aaron@”, “asb@cms .virginia.edu” – Anything that can be stored in a tree • Userid/IDnum pairs • Userid/lots_of_info_about_them_in_an_object pairs
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Hash Tables Hash table – fixed size array of some size, usually a prime number – Should be larger than the # of
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 52

07-hashes - Spring 2009 CS216: Program and Data...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online