hashtables 17 - Hash Tables A Dictionary The concept of a...

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

View Full Document Right Arrow Icon
Hash Tables
Image of page 1

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

View Full Document Right 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.
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.
Image of page 3

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

View Full Document Right 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
Image of page 4
Hash Tables 5 Let’s analyze the performance of the ideal situation. Searching = Θ (1).
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern