Hash Tables- Concept

# Hash Tables- Concept - Lecture 22: Hash Tables PIC 10B Todd...

This preview shows pages 1–4. Sign up to view the full content.

1 Lecture 22: Hash Tables PIC 10B Todd Wittman b Suppose we have a Record class that stores information for a student at Jedi Academy. b We wish to file this data according to some pre- determined key value. b The key could be the name, ID#, GPA, or any of the other fields of the class. b The rest of the record is called the satellite data. b For simplicity, let's first look at the case of organizing data where the key is the class rank. Name: Luke Skywalker ID: 002-345-285 Class Rank: 357 GPA: 2.85 Major: History Name: Leia Organa ID: 321-498-423 Class Rank: 1 GPA: 3.92 Major: Political Science Name: Darth Vader ID: 666-666-666 Class Rank: 2 GPA: 3.85 Major: Evil

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

View Full Document
2 b So when we write down a list of integers, it's understood that it's really a list of student records. Key (class rank) : 357 1 2 359 360 4 6 Satellite Data : Luke Leia Darth Han Chewie C3PO Yoda b We want to store the database of records so that we can quickly look up the information by key. O(logN) O(logN) on average O(N) worst case Binary Tree O(1) O(N) Linked List O(N) O(N) if unsorted O(logN) if sorted Vector/Array Insert/Erase Search by Key Indexing By Key b Suppose we know ahead of time that there are less than 500 students at Jedi Academy. b Let's create a vector of size 500 for the Records. vector<Record> v(500); b Now let's put the student with key (class rank) i into spot v[i]. So the index = key. b Many records are blank, so it wastes memory. b But looking up the record with a given key is fast. O(1) O(1) Insert/Erase Search by Key 2 Darth 1 Leia 4 C3PO 6 Yoda 357 Luke 359 Han 360 Chewie 0 1 2 3 4 5 6 357 358 359 360 361 499 ... ...
3 Hash Tables b A hash table (also called a map) is a list of records such that the key for the record is mapped to some index in the list. b

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/27/2010 for the course PIC 157-051-20 taught by Professor Wittman during the Winter '10 term at UCLA.

### Page1 / 8

Hash Tables- Concept - Lecture 22: Hash Tables PIC 10B Todd...

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

View Full Document
Ask a homework question - tutors are online