{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 Records & Keys box4 Suppose we have a Record class that stores information for a student at Jedi Academy. box4 We wish to file this data according to some pre- determined key value. box4 The key could be the name, ID#, GPA, or any of the other fields of the class. box4 The rest of the record is called the satellite data. box4 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 Records & Keys box4 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 box4 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 box4 Suppose we know ahead of time that there are less than 500 students at Jedi Academy. box4 Let's create a vector of size 500 for the Records. vector<Record> v(500); box4 Now let's put the student with key (class rank) i into spot v[i]. So the index = key. box4 Many records are blank, so it wastes memory. box4 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 box4 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.

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.

{[ snackBarMessage ]}

### 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