Hash tables in C.

Slides:



Advertisements
Similar presentations
Data Structures: A Pseudocode Approach with C
Advertisements

Nov 12, 2009IAT 8001 Hash Table Bucket Sort. Nov 12, 2009IAT 8002  An array in which items are not stored consecutively - their place of storage is calculated.
Hashing Techniques.
Hash Tables and Associative Containers CS-212 Dick Steflik.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
Hashing General idea: Get a large array
Data Structures Hashing Uri Zwick January 2014.
1 Lecture 7: Data structures for databases I Jose M. Peña
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Comp 335 File Structures Hashing.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
CS 61B Data Structures and Programming Methodology July 17, 2008 David Sun.
HASHING PROJECT 1. SEARCHING DATA STRUCTURES Consider a set of data with N data items stored in some data structure We must be able to insert, delete.
HASH TABLES -Paritosh Gupta. Problem. Required Search for The Precious One way would be to map all the data. And get key-value pairs. This means providing.
March 23 & 28, Hashing. 2 What is Hashing? A Hash function is a function h(K) which transforms a key K into an address. Hashing is like indexing.
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Hashing TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA Course: Data Structures Lecturer: Haim Kaplan and Uri Zwick.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 11 (Lafore’s Book) Hash Tables Hwajung Lee.
DS.H.1 Hashing Chapter 5 Overview The General Idea Hash Functions Separate Chaining Open Addressing Rehashing Extendible Hashing Application Example: Geometric.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing.
Course Developer/Writer: A. J. Ikuomola
Data Structures Using C++ 2E
Lecture 10 Hashing.
CSCI 210 Data Structures and Algorithms
Hashing Alexandra Stefan.
LEARNING OBJECTIVES O(1), O(N) and O(LogN) access times. Hashing:
School of Computer Science and Engineering
Slides by Steve Armstrong LeTourneau University Longview, TX
Lecture No.43 Data Structures Dr. Sohail Aslam.
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Hashing Alexandra Stefan.
School of Computing Clemson University Fall, 2012
Subject Name: File Structures
Data Structures Using C++ 2E
Hashing Course: Data Structures Lecturer: Uri Zwick March 2008
Hash Tables in C James Goerke.
Hashing CS2110 Spring 2018.
Design and Analysis of Algorithms
Hash Tables in C Louis Manco.
Chapter 28 Hashing.
CSE 2331/5331 Topic 8: Hash Tables CSE 2331/5331.
Hash Tables.
Hashing CS2110.
Teach A level Computing: Algorithms and Data Structures
Chapter 21 Hashing: Implementing Dictionaries and Sets
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Hash Tables and Associative Containers
Algorithms and Data Structures Lecture VI
Sparse matrices, hash tables, cell arrays
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Advance Database System
CSE 373, Copyright S. Tanimoto, 2002 Hashing -
CS202 - Fundamental Structures of Computer Science II
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
EE 312 Software Design and Implementation I
How to use hash tables to solve olympiad problems
CS 5243: Algorithms Hash Tables.
Hash Tables By JJ Shepherd.
Algorithms: Design and Analysis
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS 3343: Analysis of Algorithms
Hashing Course: Data Structures Lecturer: Uri Zwick March 2008
EE 312 Software Design and Implementation I
Presentation transcript:

Hash tables in C

Outline Data storage problems Hash Table Design Hash function terminology “Good” hash functions Example in C Acknowledgements

Data Storage Limitations with data structures we have learned so far: Suppose we have two entities e.g. word and definition {we are probably making a dictionary} Limitations with data structures we have learned so far: Arrays: Have to form two ‘parallel’ arrays-> search one containing the words-> retrieve same key from second array Linked list: Go through list elements one by one ->find cell containing word -> retrieve definition

Problems: Ar[..] Arrays : Have to follow two structures Double operations Linked Lists: Too slow, dangling pointers

Solution: Combine fast retrieval power of arrays and linear characteristic of linked lists. Symtab[NHASH] NULL Name 1 Value 1 NULL Name 2 Value 2 NULL Name 3 Value 3

Design Analyze data Storing: Come up with “good” hash function Hash key to find “bucket” Store Retrieving: Hash key Lookup table Get data Other possible facilitators: Deletion Replacement

Terminology Using our dictionary program application example: Key => word Hash function (convert key to hash) Hash => encoded word Hash table => ‘table’ of hashed values Bucket => ‘cell’ in a hash table Value => word definitions Chaining => technique of linking definitions

Overcoming Same Hash Problems Two main ways: Overwriting Chaining Picked according to programming challenge being tackled

Chaining! Symtab[NHASH] NULL Name 1 Value 1 Name 3 Value 3

Good hash functions Good function: Perfect function: One that randomly spreads out all keys into buckets perfectly randomly Symtab[NHASH] NULL -+=-+=-+=-+=-+=-+= Symtab[NHASH] -+=-+=-+=-+=-+=-+= Good function: Very close to perfect if not perfect

Bad hash functions Multiple chains Doesn’t consider data e.g. common multiples Different hashes for the same key Simply: bad algorithm Symtab[NHASH] NULL -+=-+=-+=-+=-+=-+=

C example C-ing is believing

for words in our dictionary Hash Function for words in our dictionary

Bad hash function example: Bad modulation Not accounting for multiples Not accounting for constants in names e.g. java using constants in names .class In urls (^http://*, *.htm$, *.html$) Using a random number generator to spread out data

Uses of hash tables in real world IP and DNS tables Memory allocation Almost any two-part data More parts with custom data types

? ? Questions

Acknowledgements