hashtables 17

Hashtables 17 - Hash Tables A Dictionary The concept of a dictionary is present in tons of software applications Like what A dictionary is a

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

View Full Document Right Arrow Icon
Hash Tables
Background image of page 1

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

View Full DocumentRight Arrow Icon
Hash Tables 2 A Dictionary The concept of a dictionary is present in tons of software applications. Like what? A dictionary is a collection of elements, where each element has a unique key, and an element usually has a field called value. The operations performed on a dictionary include: insert an element search for an element delete an element All these operations are dependent on the key value.
Background image of page 2
Hash Tables 3 Access in a dictionary is random…as opposed to sequential. Which other data type uses random access? Sequential access? The STL provides a map as an implementation of a dictionary: template <class Key, class Value, class Compare = less<Key>, class Allocator = allocator> class map; It is also possible for a dictionary to allow duplicates…entries that have the same key, but different values. The STL provides a multimap class for this.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Hash Tables 4 A Hash Table A hash table is another alternative for representing a dictionary. In a hash table, a hash function is used to map keys into positions in a table. This is the act of hashing . Here’s the philosophy of hashing: In the ideal situation, if element e has the key k and f is the hash function, then e is stored in position f(k) of the table. Search: compute f(k) and see if there is an element there Insertion: compute f(k) and place it in that position Deletion: compute f(k) and delete at that position
Background image of page 4
Hash Tables 5 Let’s analyze the performance of the ideal situation. Searching = Θ (1). Before we can hash the key, we must
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/17/2010 for the course CS 162 taught by Professor Fant during the Spring '08 term at Portland State.

Page1 / 14

Hashtables 17 - Hash Tables A Dictionary The concept of a dictionary is present in tons of software applications Like what A dictionary is a

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

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