Hash Tables in C Louis Manco.

Slides:



Advertisements
Similar presentations
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Advertisements

Programming and Data Structure
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
An Introduction to Hashing. By: Sara Kennedy Presented: November 1, 2002.
Hashing as a Dictionary Implementation
Data Management and File Organization
1 Hash Tables Gordon College CS Hash Tables Recall order of magnitude of searches –Linear search O(n) –Binary search O(log 2 n) –Balanced binary.
CS 206 Introduction to Computer Science II 11 / 17 / 2008 Instructor: Michael Eckmann.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CS 206 Introduction to Computer Science II 04 / 06 / 2009 Instructor: Michael Eckmann.
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
Attribute Grammar Examples and Symbol Tables Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
Hash Tables1   © 2010 Goodrich, Tamassia.
© 2004 Goodrich, Tamassia Hash Tables1  
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
DS.H.1 Hashing Chapter 5 Overview The General Idea Hash Functions Separate Chaining Open Addressing Rehashing Extendible Hashing Application Example: Geometric.
CS203 Lecture 14. Hashing An object may contain an arbitrary amount of data, and searching a data structure that contains many large objects is expensive.
Hash Tables 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing.
COMP 53 – Week Eleven Hashtables.
Data Abstraction & Problem Solving with C++
School of Computer Science and Engineering
Slides by Steve Armstrong LeTourneau University Longview, TX
Maps, Hash tables, Skip Lists– Interesting problems
School of Computing Clemson University Fall, 2012
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Student Book An Introduction
Introduction to Hashing - Hash Functions
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
© 2013 Goodrich, Tamassia, Goldwasser
Dictionaries 9/14/ :35 AM Hash Tables   4
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
CSCE 210 Data Structures and Algorithms
Hash Functions Sections 5.1 and 5.2
Hash Tables Part II: Using Buckets
Hash Tables in C James Goerke.
Hash table another data structure for implementing a map or a set
Advanced Associative Structures
Hash Table.
Chapter 28 Hashing.
Data Structures and Algorithms
Chapter 21 Hashing: Implementing Dictionaries and Sets
Data Structures and Algorithms
Growing Arrays in C Russell Stephens.
Chapter 7 Space and Time Tradeoffs
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Hash Tables: A basic O(1)verview
Hash tables in C.
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
MSIS 655 Advanced Business Applications Programming
CS202 - Fundamental Structures of Computer Science II
Advanced Implementation of Tables
2018, Spring Pusan National University Ki-Joune Li
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Space-for-time tradeoffs
Chapter 9: Pointers and String
Podcast Ch21a Title: Hash Functions
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Extendable hashing M.B.Chandak.
Growing Arrays in C Nathan Lee.
Chapter 13 Hashing © 2011 Pearson Addison-Wesley. All rights reserved.
Dictionaries and Hash Tables
Presentation transcript:

Hash Tables in C Louis Manco

Contents Explanation of a Hash Table Uses for Hash Tables Application/Implementation In C

What Is a Hash Table? Data structure Relates values (data) to a dynamic set of strings (keys) “Maps” values Table consists of an array whose elements point to linked lists of information

Example of a Hash Table Image: http://upload.wikimedia.org/wikipedia/commons/7/7d/Hash_table_3_1_1_0_1_0_0_SP.svg

Why Use Hash Tables? Fast and secure data storage Fast data retrieval Contain large amounts of data through one small piece of data Array index

Uses for Hash Tables Web browser history Phone/address book Compiler usage Manage variable information

Application/Implementation in C Part I Uses buckets and linked list chaining Handles collision using linked lists Called the “separate chaining” method Buckets contain pointers to elements Image: http://math.hws.edu/eck/cs124/javanotes4/c12/fig2.jpeg

Application/Implementation in C Part II Element type for buckets Recall element type for a list typedef struct Nameval Nameval; struct Nameval { char *name; int value; Nameval *next; }; Nameval *symtab[NHASH];

Application/Implementation in C Part III Lookup/insert algorithm Takes pointer to the first name char, creation flag integer, and related value as arguments Create flag allows for creation if specified value does not exist Returns a pointer to the bucket (array cell)

Hash Function in C Attempts to uniformly distribute data throughout array Common algorithm decides hash value (array index) by adding each byte of the string to a multiple of the hash so far Bits are spread from the new byte through the value so far, mixing the input bytes to get a hash number that has not likely been used yet

Conclusion/Highlights Hash tables allow for relationships between data values and dynamic sets of strings which are called keys They allow for fast and secure storage and retrieval O(1) retrieval (hopefully) In C, the “separate chain” method is used to handle multiple values landing in one bucket

Source Kernighan, Brian W., and Rob Pike. The Practice of Programming (Addison-Wesley Professional Computing Series). New York: Addison-Wesley Professional, 1999. Print.