Data Structures & File Management

Size: px
Start display at page:

Download "Data Structures & File Management"

Transcription

1 The Cost of Searching 1 Given a collection of N equally-likely data values, any search algorithm that proceeds by comparing data values to each other must, on average, perform at least Θ(log N) comparisons in carrying out a search. There are several simple ways to achieve Θ(log N) in the worst case as well, including: - binary search on a sorted array - search in a balanced binary search tree - search in a skip list But, is there some way to beat the limit in the theoretical statement above? There seem to be two possible openings: - what if the data values are not equally-likely to be the target of a random search? - what if the search process does not compare data elements? In either case, the theorem would not apply Searching without Comparisons 2 How could a search algorithm proceed without comparing data elements? What if we had some sort of oracle that could take the key for a data value and compute, in constant-bounded time, the location at which that key would occur within the data collection? data key K Θ(1) oracle L, location of matching record within the collection If the container storing the collection supports random access with Θ(1) cost, as an array does, then we would have a total search cost of Θ(1). Data Collection

2 Hash Functions and Hash Tables 3 hash function a function that can take a key value and compute an integer value (or an index in a table) from it A hash table employs a hash function, H, that maps key values to non-negative integers (or to table index values). When a record is added to the table, its key is processed by the hash function to produce a location within the table, and the record will be stored at that location. For example, student records for a class could be stored in an array C of dimension by truncating the student s ID number to its last four digits: H(IDNum) = IDNum % Given an ID number X, the corresponding record would be inserted at C[H(X)]. Of course, there s a problem what if the function produces the same location in the table for two different key values? A collision. Ideally, we can find a perfect hash function, one which never does that. Hash Table Insertion Simple insertion of an entry to a hash table involves two phases: 4 Name LocalAddress HomeAddress IDNumber Major Level IDNumber H() K Vacant??... Record Table Index The appropriate record key value must be hashed to yield a table index. If that slot is vacant, the record is inserted there. If not, we have a collision

3 Collisions 5 The table slot that is produced by the hash function (and subsequent mod operation) is usually referred to as the home slot for the key value. When two different key values are mapped to the same home slot in the hash table, we say that a collision has occurred. - type I: H(K1) == H(K2) but K1!= K2 - type II: H(K1)!= H(K2) but H(K1) % N == H(K2) % N Whether collisions occur depends both on the way in which the key values are hashed, and on the table size. In general-purpose hash situations, it is often impractical (or impossible) to choose the hash function and the table size so that collisions are logically impossible. Basic Issues 6 How can a good hash function be found? - clearly the logic of the function must depend upon the type of the key - but, it should also depend upon the set of key values that will actually be hashed, not just on the set of all possible key values - it would seem to be good if the function was one-to-one - it must be possible to compute the function efficiently How should we choose the size of the table? - if we know (in advance) how many records will be stored, is that sufficient? - if we have no idea how many records will be stored, what do we do? - there may be too many logically-possible key values to make the table large enough to handle all of them at once (e.g., social security numbers, alpha-numeric strings of length 10) - should each slot in the table store a single element, or more than one?

4 Hash Functions 7 Suppose we have N records, and a table of M slots, where N M. - there are M N different ways to map the records into the table, if we don t worry about mapping two records to the same slot - the number of different perfect mappings of the records into different slots in the table would be M! P( M, N) = ( M N)! - for instance, if N = 50 and M = 100, there are different possible hash mappings, only of which are perfect (1 in 1,000,000) - so, there is no shortage of potential perfect hash functions (in theory) - however, we need one that is effectively computable, that is, it must be possible to compute it (so we need a formula for it) and it must be efficiently computable - there are a number of common approaches, but the design of good, practical hash functions must still be considered a topic of research and experiment Simple Hash Example 8 It is usually desirable to have the entire key value affect the hash result (so simply chopping off the last k digits of an integer key is NOT a good idea in most cases). Consider the following function to hash a string value into an integer range: unsigned int strhash(string tohash) { } unsigned int hashvalue = 0; for (int Pos = 0; Pos < tohash.length(); Pos++) { hashvalue = hashvalue + int(tohash.at(pos)); } return hashval; : hash h: 104 a: 97 s: 115 h: 104 Sum: 420 Mod by table size to get the index This takes every element of the string into account a string hash function that truncated to the last three characters would compute the same integer for "hash", "stash", "mash", "trash.

5 Hash Function Techniques 9 Division - the first order of business for a hash function is to compute an integer value - if we expect the hash function to produce a valid index for our chosen table size, that integer will probably be out of range - that is easily remedied by modding the integer by the table size - there is some reason to believe that it is better if the table size is a prime, or at least has no small prime factors Folding - portions of the key are often recombined, or folded together - shift folding: boundary folding: can be efficiently performed using bitwise operations - the characters of a string can be xor d together, but small numbers result - chunks of characters can be xor d instead, say in integer-sized chunks Hash Function Techniques 10 Mid-square function - square the key, then use the middle part as the result - e.g., (with a table size of 1000) - a string would first be transformed into a number, say by folding - idea is to let all of the key influence the result - if table size is a power of 2, this can be done efficiently at the bit level: (with a table size of 1024) Extraction - use only part of the key to compute the result - motivation may be related to the distribution of the actual key values, e.g., VT student IDs almost all begin with 904, so it would contribute no useful separation Radix transformation - change the base-of-representation of the numeric key, mod by table size - not much of a rationale for it

6 Hash Function Design 11 A good hash function should: - be easy and quick to compute - achieve an even distribution of the key values that actually occur across the index range supported by the table - ideally be mathematically one-to-one on the set of relevant key values Note: hash functions are NOT random in any sense. Reducing Collisions A simple hash function is likely to map two or more key values to the same integer value, in at least some cases. A little bit of design forethought can often reduce this: 12 unsigned int strhash(string tohash) { } unsigned int hashvalue = 0; for (int Pos = 0; Pos < tohash.length(); Pos++) { hashvalue = (hashvalue << 2) + int(tohash.at(pos)); } return hashval; : hash h: 104 a: 97 s: 115 h: 104 Sum: 8772 The original version would have hashed both of these strings to the same table index. Flaw: it didn't take element position into account. : shah s: 115 h: 104 a: 97 h: 104 Sum: 9516

7 A Classic Hash Function for Strings Consider the following function to hash a string value into an integer: 13 unsigned int elfhash(const string& tohash) { unsigned int hashval = 0; for (int Pos = 0; Pos < tohash.length(); Pos++) { // use all elements hashval = (hashval << 4) + int(tohash.at(pos)); // shift/mix unsigned int hibits = hashval & 0xF ; // get high "nibble" if (hibits!= 0) { hashval ^= hibits >> 24; // xor high nibble with second nibble } } hashval &= ~hibits; // clear high nibble } return hashval; This was developed originally during the design of the UNIX operating system, for use in building system-level hash tables. Details Here's a trace: 14 Character hashval d: i: a9 s: b03 t: b0a4 r: b0ab2 i: 69 06b0ab89 b: 62 0b0ab892 u: 75 00ab8925 t: 74 0ab892c4 i: 69 0b892c09 o: 6f 0892c04f n: 6e 092c05de distribution: hashval : 06b0ab89 hashval << 4: 6b0ab890 add 62 : 6b0ab8f2 hibits : hibits >> 24: hashval ^ 6b0ab8f2 hibits : 6b0ab892 f: : 0110 ^: 1001 hashval & ~hibits : 0b0ab892

8 Perfect Hash Functions In most general applications, we cannot know exactly what set of key values will need to be hashed until the hash function and table have been designed and put to use. At that point, changing the hash function or changing the size of the table will be extremely expensive since either would require re-hashing every key. 15 A perfect hash function is one that maps every key value to a different table cell than any other key value. A minimal perfect hash function does so using a table that has only as many slots as there are key values to be hashed. If the set of keys IS known in advance, it is possible to construct a specialized hash function that is perfect, perhaps even minimal perfect. Algorithms for constructing perfect hash functions tend to be tedious, but a number are known. Cichelli s Method This is used primarily when it is necessary to hash a relatively small collection of keys, such as the set of reserved words for a programming language. The basic formula is: 16 h(s) = S.length() + g(s[0]) + g(s[s.length()-1]) where g() is constructed using Cichelli s algorithm so that h() will return a different hash value for each word in the set. The algorithm has three phases: - computation of the letter sequences in the words - ordering the words - searching

9 Cichelli s Method Suppose we need to hash the words in the list below: 17 calliope clio erato euterpe melpomene polyhymnia terpsichore thalia urania Determine the frequency with which each first and last letter occurs: letter: e a c o t m p u freq: Score the words by summing the frequencies of their first and last letters, and then sort them in that order: calliope 8 euterpe clio 4 calliope erato 8 erato euterpe 12 terpsichore melpomene 7 melpomene polyhymnia 4 thalia terpsichore 8 clio thalia 5 polyhymnia urania 4 urania Cichelli s Method Finally, consider the words in order and define g(x) for each possible first and last letter in such a way that each of the words will have a distinct hash value: word g_value assigned h(word) table slot euterpe e-->0 7 7 ok calliope c-->0 8 8 ok erato o-->0 5 5 ok terpsichore t--> ok melpomene m-->0 9 0 ok thalia a-->0 6 6 ok clio none 4 4 ok polyhymnia p--> ok urania u-->0 6 6 reject u-->1 7 7 reject u-->2 8 8 reject u-->3 9 0 reject u--> reject 18

10 Cichelli s Method Cichelli s method imposes a limit on the search at this point (we re assuming it s 5 steps), and so we back up to the previous word and redefine the mapping there: 19 word g_value assigned h(word) table slot polyhymnia p--> reject p--> reject p--> urania u-->0 6 6 reject u-->1 7 7 reject u-->2 8 8 reject u-->3 9 0 reject u--> ok So, if we define g() as determined above, then h() will be a minimal perfect hash function on the given set of words. The primary difficulty is the cost, because the search phase can degenerate to exponential performance, and so it is only practical for small sets of words. Table Size 20 There is some reason to believe that making the table size a prime integer produces better results by reducing the probability of "clustering" of index values. - if gcd(a,m) = d and r = a % m, then d r - so, if two hash values have a common divisor with the table size, the corresponding table index values will both be multiples of that common divisor There is also some empirical evidence that it is better if the table size not be close to any power of 2. So, there are commonly available tables of prime numbers that are considered suitable candidates to be used as hash table sizes. On the other hand, there are also performance advantages if the table size is chosen to be a power of 2 (see the mid-square method, for example).

11 Resolving Collisions When collisions occur, the hash table implementation must provide some mechanism to resolve the collision: - no strategy: just reject the insertion. Unacceptable. - open hashing: place the record somewhere other than its home slot - requires some method for finding the alternate location - method must be reproducible - method must be efficient - chaining: view each slot as a container, storing all records that collide there - requires an appropriate, efficient container for each table slot - overhead is a concern (e.g., pointers needed by container) 21 Open If the home slot for the record that is being inserted is already occupied, then simply chose a different location within the table: 22 F record hash fn Home slot K linear probing: start with the original hash index, say K, and search the table sequentially from there until an empty slot is found. If no empty slot is found quadratic probing: search from the original hash index by considering indices K + 1, K + 4, K + 9, etc., until an empty slot is found (or not ). other: apply some other strategy for computing a sequence of alternative table index values.

12 Linear Probing If the hash location is not vacant, then: 23 Name LocalAddress HomeAddress IDNumber Major Level IDNumber H() K Vacant... K+1 Record K+2 K+3 Vacant Table Index If the hash location is filled, then we must find another location for the record Quadratic Probing 24 Quadratic probing is an attempt to scatter the effect of collisions across the table in a more distributed way: K K+1 K+4 K+9 K MM+1 M+4 M+9 M+16 Now, the probe sequences from near misses don't overlap completely. Problem: will this eventually try every slot in the hash table? No. If the table size is prime, this will try approximately half the table slots.

13 General Increment Probing Quadratic probing can be generalized by picking some function, say S(i), to generate the step sizes during the probe. Then we have the index sequence: 25 K, K + S(1), K + S(2), K + S(3), K + S(4), etc. Letting S(i) = i 2 yields quadratic probing. The primary concern is that the probe sequence not cycle back to K too soon, because once that happens the same sequence of index values will be generated a second time. Key Dependent Probing It also seems reasonable to use a probe function that takes into account the original key value: 26 K, S(1, K), S(2, K), S(3, K), S(4, K), etc. If done well, this could prevent the adjacencies that increment probing creates in the probe sequences for adjacent slots (see slide 14 again). One must be careful to make sure that the calculation of the probe indices is relatively cheap, and that the probe sequence covers a reasonable fraction of the table slots. The more complex the function used becomes, the harder it is to satisfy those concerns.

14 Clustering 27 Linear probing is guaranteed to find a slot for the insertion if there still an empty slot in the table. However, linear probing also tends to promote clustering within the table: a b c d Suppose we now inserted some records that collided with records c and d: a b c c 2 c 3 d c 4 d 2 c 5 d 3 The problem here is that the probabilities that a slot will be hit are no longer uniform. If there are 20 slots in the table, the probability that the slot just after the last d will be hit next is 9/20 instead of the ideal 1/20. In other words, the slot that is most likely to be filled is one that s at the end of a cluster of filled cells, which will make the cluster even longer, and make it even more likely that the cluster will grow in the future. Deletions Deleting a record poses a special problem: what if there has been a collision with the record being deleted? In that case, we must be careful to ensure that future searches will not be disrupted. 28 Solution: replace the deleted record with a "tombstone" entry that indicates the cell is available for an insertion, but that it was once filled so that a search will proceed past it if necessary. a b f r d h m t Problem: this increases the average search cost since probe sequences will be longer that strictly necessary. We could periodically re-hash the table or use some other reorganization scheme. Question: how to tombstones affect the logic of hash table searching. Question: can tombstones be "recycled" when new elements are inserted?

15 Chaining Design the table so that each slot is actually a container that can hold multiple records. 29 Here, the chains" are linked lists which could hold any number of colliding records. Alternatively each table slot could be large enough to store several records directly in that case the slot may overflow, requiring a fallback Design Considerations 30 Aside from the theoretical issues already presented, there are practical considerations that will influence the design of a hash table implementation. - The table should, of course, be encapsulated as a template. - The size of the table should be configurable via a constructor. - The hash function does NOT, perhaps surprisingly, logically belong as a member function of the hash table template. The table implementation should be as general as possible, but the choice of a particular hash function should take into account both the type and the expected range of the key values. Hence, it is natural to make the choice of hash function the responsibility of the designer of the data element (key) being hashed. From this perspective, the table simply asks a data element to hash itself. The hash function may either return an integer, which the table then mods by its size, or it may take the table size as a parameter. - The probing strategy, if appropriate, IS the responsibility of the hash table, since it requires knowing the internal table configuration.

16 A HashTable Class Here is a sample interface for a hash table class using open hashing: enum probeoption {LINEAR, QUADRATIC}; template <typename T, typename H> class HashTableT { private: enum slotstate {EMPTY, FULL, TOMBSTONE}; T* Table; slotstate* Status; int Size; int Usage; probeoption Opt; unsigned int Probe(int Step); // continues Naturally the table is allocated dynamically. The hash table does not provide a hash function; the second template parameter is required to implement a public function with the interface: unsigned int H::Hash(T); Two client-selectable probe strategy options are provided. A HashTable Class The public interface provides the expected functions, as well as table resizing: 32 //...continued... public: HashTableT(unsigned int Sz = 97, probeoption O = LINEAR); HashTableT(const HashTableT<T, H>& Source); HashTableT<T, H> operator=(const HashTableT<T, H>& RHS); ~HashTableT(); T* Insert(const T& Elem); T* Find(const T& Elem); T* Delete(const T& Elem); void Clear(); bool Resize(unsigned int Sz); unsigned int tablesize() const; void Display(ostream& Out); }; For testing purposes it would also be natural to provide instrumentation.

17 Hash Table as an Index The entries in the hash table do not have to be data records. 33 For example, if we have a large disk file of data records we could use a hash table to store an index for the file. Each hash table entry might store a key value and the byte offset within the file to the beginning of the corresponding record. Or, the hash table entries could be pointers to data records allocated dynamically on the system heap.

5. Hashing. 5.1 General Idea. 5.2 Hash Function. 5.3 Separate Chaining. 5.4 Open Addressing. 5.5 Rehashing. 5.6 Extendible Hashing. 5.

5. Hashing. 5.1 General Idea. 5.2 Hash Function. 5.3 Separate Chaining. 5.4 Open Addressing. 5.5 Rehashing. 5.6 Extendible Hashing. 5. 5. Hashing 5.1 General Idea 5.2 Hash Function 5.3 Separate Chaining 5.4 Open Addressing 5.5 Rehashing 5.6 Extendible Hashing Malek Mouhoub, CS340 Fall 2004 1 5. Hashing Sequential access : O(n). Binary

More information

TABLES AND HASHING. Chapter 13

TABLES AND HASHING. Chapter 13 Data Structures Dr Ahmed Rafat Abas Computer Science Dept, Faculty of Computer and Information, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ TABLES AND HASHING Chapter 13

More information

COSC160: Data Structures Hashing Structures. Jeremy Bolton, PhD Assistant Teaching Professor

COSC160: Data Structures Hashing Structures. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures Hashing Structures Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Hashing Structures I. Motivation and Review II. Hash Functions III. HashTables I. Implementations

More information

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course Today s Topics Review Uses and motivations of hash tables Major concerns with hash tables Properties Hash function Hash

More information

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 Prof. John Park Based on slides from previous iterations of this course Today s Topics Overview Uses and motivations of hash tables Major concerns with hash

More information

! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function.

! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function. Hash Tables Chapter 20 CS 3358 Summer II 2013 Jill Seaman Sections 201, 202, 203, 204 (not 2042), 205 1 What are hash tables?! A Hash Table is used to implement a set, providing basic operations in constant

More information

Data and File Structures Chapter 11. Hashing

Data and File Structures Chapter 11. Hashing Data and File Structures Chapter 11 Hashing 1 Motivation Sequential Searching can be done in O(N) access time, meaning that the number of seeks grows in proportion to the size of the file. B-Trees improve

More information

Successful vs. Unsuccessful

Successful vs. Unsuccessful Hashing Search Given: Distinct keys k 1, k 2,, k n and collection T of n records of the form (k 1, I 1 ), (k 2, I 2 ),, (k n, I n ) where I j is the information associated with key k j for 1

More information

Topic HashTable and Table ADT

Topic HashTable and Table ADT Topic HashTable and Table ADT Hashing, Hash Function & Hashtable Search, Insertion & Deletion of elements based on Keys So far, By comparing keys! Linear data structures Non-linear data structures Time

More information

Hashing Techniques. Material based on slides by George Bebis

Hashing Techniques. Material based on slides by George Bebis Hashing Techniques Material based on slides by George Bebis https://www.cse.unr.edu/~bebis/cs477/lect/hashing.ppt The Search Problem Find items with keys matching a given search key Given an array A, containing

More information

Data Structures And Algorithms

Data Structures And Algorithms Data Structures And Algorithms Hashing Eng. Anis Nazer First Semester 2017-2018 Searching Search: find if a key exists in a given set Searching algorithms: linear (sequential) search binary search Search

More information

COMP171. Hashing.

COMP171. Hashing. COMP171 Hashing Hashing 2 Hashing Again, a (dynamic) set of elements in which we do search, insert, and delete Linear ones: lists, stacks, queues, Nonlinear ones: trees, graphs (relations between elements

More information

General Idea. Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure

General Idea. Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure Hashing 1 Hash Tables We ll discuss the hash table ADT which supports only a subset of the operations allowed by binary search trees. The implementation of hash tables is called hashing. Hashing is a technique

More information

Introduction hashing: a technique used for storing and retrieving information as quickly as possible.

Introduction hashing: a technique used for storing and retrieving information as quickly as possible. Lecture IX: Hashing Introduction hashing: a technique used for storing and retrieving information as quickly as possible. used to perform optimal searches and is useful in implementing symbol tables. Why

More information

Hashing. October 19, CMPE 250 Hashing October 19, / 25

Hashing. October 19, CMPE 250 Hashing October 19, / 25 Hashing October 19, 2016 CMPE 250 Hashing October 19, 2016 1 / 25 Dictionary ADT Data structure with just three basic operations: finditem (i): find item with key (identifier) i insert (i): insert i into

More information

Comp 335 File Structures. Hashing

Comp 335 File Structures. Hashing Comp 335 File Structures Hashing What is Hashing? A process used with record files that will try to achieve O(1) (i.e. constant) access to a record s location in the file. An algorithm, called a hash function

More information

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file.

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Large Trees 1 Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Trees can also be used to store indices of the collection

More information

HASH TABLES. Hash Tables Page 1

HASH TABLES. Hash Tables Page 1 HASH TABLES TABLE OF CONTENTS 1. Introduction to Hashing 2. Java Implementation of Linear Probing 3. Maurer s Quadratic Probing 4. Double Hashing 5. Separate Chaining 6. Hash Functions 7. Alphanumeric

More information

AAL 217: DATA STRUCTURES

AAL 217: DATA STRUCTURES Chapter # 4: Hashing AAL 217: DATA STRUCTURES The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions, and finds in constant average

More information

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management

Symbol Table. Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management Hashing Symbol Table Symbol table is used widely in many applications. dictionary is a kind of symbol table data dictionary is database management In general, the following operations are performed on

More information

CSE 214 Computer Science II Searching

CSE 214 Computer Science II Searching CSE 214 Computer Science II Searching Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction Searching in a

More information

CS 310 Hash Tables, Page 1. Hash Tables. CS 310 Hash Tables, Page 2

CS 310 Hash Tables, Page 1. Hash Tables. CS 310 Hash Tables, Page 2 CS 310 Hash Tables, Page 1 Hash Tables key value key value Hashing Function CS 310 Hash Tables, Page 2 The hash-table data structure achieves (near) constant time searching by wasting memory space. the

More information

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far

Introduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far Chapter 5 Hashing 2 Introduction hashing performs basic operations, such as insertion, deletion, and finds in average time better than other ADTs we ve seen so far 3 Hashing a hash table is merely an hashing

More information

Chapter 20 Hash Tables

Chapter 20 Hash Tables Chapter 20 Hash Tables Dictionary All elements have a unique key. Operations: o Insert element with a specified key. o Search for element by key. o Delete element by key. Random vs. sequential access.

More information

Hashing for searching

Hashing for searching Hashing for searching Consider searching a database of records on a given key. There are three standard techniques: Searching sequentially start at the first record and look at each record in turn until

More information

Hash Tables Outline. Definition Hash functions Open hashing Closed hashing. Efficiency. collision resolution techniques. EECS 268 Programming II 1

Hash Tables Outline. Definition Hash functions Open hashing Closed hashing. Efficiency. collision resolution techniques. EECS 268 Programming II 1 Hash Tables Outline Definition Hash functions Open hashing Closed hashing collision resolution techniques Efficiency EECS 268 Programming II 1 Overview Implementation style for the Table ADT that is good

More information

Tables. The Table ADT is used when information needs to be stored and acessed via a key usually, but not always, a string. For example: Dictionaries

Tables. The Table ADT is used when information needs to be stored and acessed via a key usually, but not always, a string. For example: Dictionaries 1: Tables Tables The Table ADT is used when information needs to be stored and acessed via a key usually, but not always, a string. For example: Dictionaries Symbol Tables Associative Arrays (eg in awk,

More information

Hashing. Hashing Procedures

Hashing. Hashing Procedures Hashing Hashing Procedures Let us denote the set of all possible key values (i.e., the universe of keys) used in a dictionary application by U. Suppose an application requires a dictionary in which elements

More information

The dictionary problem

The dictionary problem 6 Hashing The dictionary problem Different approaches to the dictionary problem: previously: Structuring the set of currently stored keys: lists, trees, graphs,... structuring the complete universe of

More information

Worst-case running time for RANDOMIZED-SELECT

Worst-case running time for RANDOMIZED-SELECT Worst-case running time for RANDOMIZED-SELECT is ), even to nd the minimum The algorithm has a linear expected running time, though, and because it is randomized, no particular input elicits the worst-case

More information

Dictionary. Dictionary. stores key-value pairs. Find(k) Insert(k, v) Delete(k) List O(n) O(1) O(n) Sorted Array O(log n) O(n) O(n)

Dictionary. Dictionary. stores key-value pairs. Find(k) Insert(k, v) Delete(k) List O(n) O(1) O(n) Sorted Array O(log n) O(n) O(n) Hash-Tables Introduction Dictionary Dictionary stores key-value pairs Find(k) Insert(k, v) Delete(k) List O(n) O(1) O(n) Sorted Array O(log n) O(n) O(n) Balanced BST O(log n) O(log n) O(log n) Dictionary

More information

HASH TABLES.

HASH TABLES. 1 HASH TABLES http://en.wikipedia.org/wiki/hash_table 2 Hash Table A hash table (or hash map) is a data structure that maps keys (identifiers) into a certain location (bucket) A hash function changes the

More information

Question Bank Subject: Advanced Data Structures Class: SE Computer

Question Bank Subject: Advanced Data Structures Class: SE Computer Question Bank Subject: Advanced Data Structures Class: SE Computer Question1: Write a non recursive pseudo code for post order traversal of binary tree Answer: Pseudo Code: 1. Push root into Stack_One.

More information

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file.

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Large Trees 1 Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file. Trees can also be used to store indices of the collection

More information

Lecture 10 March 4. Goals: hashing. hash functions. closed hashing. application of hashing

Lecture 10 March 4. Goals: hashing. hash functions. closed hashing. application of hashing Lecture 10 March 4 Goals: hashing hash functions chaining closed hashing application of hashing Computing hash function for a string Horner s rule: (( (a 0 x + a 1 ) x + a 2 ) x + + a n-2 )x + a n-1 )

More information

HO #13 Fall 2015 Gary Chan. Hashing (N:12)

HO #13 Fall 2015 Gary Chan. Hashing (N:12) HO #13 Fall 2015 Gary Chan Hashing (N:12) Outline Motivation Hashing Algorithms and Improving the Hash Functions Collisions Strategies Open addressing and linear probing Separate chaining COMP2012H (Hashing)

More information

DATA STRUCTURES/UNIT 3

DATA STRUCTURES/UNIT 3 UNIT III SORTING AND SEARCHING 9 General Background Exchange sorts Selection and Tree Sorting Insertion Sorts Merge and Radix Sorts Basic Search Techniques Tree Searching General Search Trees- Hashing.

More information

Algorithms in Systems Engineering ISE 172. Lecture 12. Dr. Ted Ralphs

Algorithms in Systems Engineering ISE 172. Lecture 12. Dr. Ted Ralphs Algorithms in Systems Engineering ISE 172 Lecture 12 Dr. Ted Ralphs ISE 172 Lecture 12 1 References for Today s Lecture Required reading Chapter 5 References CLRS Chapter 11 D.E. Knuth, The Art of Computer

More information

Adapted By Manik Hosen

Adapted By Manik Hosen Adapted By Manik Hosen Basic Terminology Question: Define Hashing. Ans: Concept of building a data structure that can be searched in O(l) time is called Hashing. Question: Define Hash Table with example.

More information

Chapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion,

Chapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion, Introduction Chapter 5 Hashing hashing performs basic operations, such as insertion, deletion, and finds in average time 2 Hashing a hash table is merely an of some fixed size hashing converts into locations

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Hashing & Hash Tables 1 Overview Hash Table Data Structure : Purpose To support insertion, deletion and search in average-case constant t time Assumption: Order of elements irrelevant ==> data structure

More information

Hash Tables. Hashing Probing Separate Chaining Hash Function

Hash Tables. Hashing Probing Separate Chaining Hash Function Hash Tables Hashing Probing Separate Chaining Hash Function Introduction In Chapter 4 we saw: linear search O( n ) binary search O( log n ) Can we improve the search operation to achieve better than O(

More information

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018

CSE 332: Data Structures & Parallelism Lecture 10:Hashing. Ruth Anderson Autumn 2018 CSE 332: Data Structures & Parallelism Lecture 10:Hashing Ruth Anderson Autumn 2018 Today Dictionaries Hashing 10/19/2018 2 Motivating Hash Tables For dictionary with n key/value pairs insert find delete

More information

Introduction to Hashing

Introduction to Hashing Lecture 11 Hashing Introduction to Hashing We have learned that the run-time of the most efficient search in a sorted list can be performed in order O(lg 2 n) and that the most efficient sort by key comparison

More information

Unit #5: Hash Functions and the Pigeonhole Principle

Unit #5: Hash Functions and the Pigeonhole Principle Unit #5: Hash Functions and the Pigeonhole Principle CPSC 221: Basic Algorithms and Data Structures Jan Manuch 217S1: May June 217 Unit Outline Constant-Time Dictionaries? Hash Table Outline Hash Functions

More information

Hashing. 1. Introduction. 2. Direct-address tables. CmSc 250 Introduction to Algorithms

Hashing. 1. Introduction. 2. Direct-address tables. CmSc 250 Introduction to Algorithms Hashing CmSc 250 Introduction to Algorithms 1. Introduction Hashing is a method of storing elements in a table in a way that reduces the time for search. Elements are assumed to be records with several

More information

Open Addressing: Linear Probing (cont.)

Open Addressing: Linear Probing (cont.) Open Addressing: Linear Probing (cont.) Cons of Linear Probing () more complex insert, find, remove methods () primary clustering phenomenon items tend to cluster together in the bucket array, as clustering

More information

Hash Table and Hashing

Hash Table and Hashing Hash Table and Hashing The tree structures discussed so far assume that we can only work with the input keys by comparing them. No other operation is considered. In practice, it is often true that an input

More information

Hashing. Dr. Ronaldo Menezes Hugo Serrano. Ronaldo Menezes, Florida Tech

Hashing. Dr. Ronaldo Menezes Hugo Serrano. Ronaldo Menezes, Florida Tech Hashing Dr. Ronaldo Menezes Hugo Serrano Agenda Motivation Prehash Hashing Hash Functions Collisions Separate Chaining Open Addressing Motivation Hash Table Its one of the most important data structures

More information

CS 3114 Data Structures and Algorithms READ THIS NOW!

CS 3114 Data Structures and Algorithms READ THIS NOW! READ THIS NOW! Print your name in the space provided below. There are 9 short-answer questions, priced as marked. The maximum score is 100. When you have finished, sign the pledge at the bottom of this

More information

Hash[ string key ] ==> integer value

Hash[ string key ] ==> integer value Hashing 1 Overview Hash[ string key ] ==> integer value Hash Table Data Structure : Use-case To support insertion, deletion and search in average-case constant time Assumption: Order of elements irrelevant

More information

Understand how to deal with collisions

Understand how to deal with collisions Understand the basic structure of a hash table and its associated hash function Understand what makes a good (and a bad) hash function Understand how to deal with collisions Open addressing Separate chaining

More information

1. Attempt any three of the following: 15

1. Attempt any three of the following: 15 (Time: 2½ hours) Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Make suitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written

More information

stacks operation array/vector linked list push amortized O(1) Θ(1) pop Θ(1) Θ(1) top Θ(1) Θ(1) isempty Θ(1) Θ(1)

stacks operation array/vector linked list push amortized O(1) Θ(1) pop Θ(1) Θ(1) top Θ(1) Θ(1) isempty Θ(1) Θ(1) Hashes 1 lists 2 operation array/vector linked list find (by value) Θ(n) Θ(n) insert (end) amortized O(1) Θ(1) insert (beginning/middle) Θ(n) Θ(1) remove (by value) Θ(n) Θ(n) find (by index) Θ(1) Θ(1)

More information

Hashing. Introduction to Data Structures Kyuseok Shim SoEECS, SNU.

Hashing. Introduction to Data Structures Kyuseok Shim SoEECS, SNU. Hashing Introduction to Data Structures Kyuseok Shim SoEECS, SNU. 1 8.1 INTRODUCTION Binary search tree (Chapter 5) GET, INSERT, DELETE O(n) Balanced binary search tree (Chapter 10) GET, INSERT, DELETE

More information

Hashing. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Hashing. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Hashing CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Overview Hashing Technique supporting insertion, deletion and

More information

CPSC 259 admin notes

CPSC 259 admin notes CPSC 9 admin notes! TAs Office hours next week! Monday during LA 9 - Pearl! Monday during LB Andrew! Monday during LF Marika! Monday during LE Angad! Tuesday during LH 9 Giorgio! Tuesday during LG - Pearl!

More information

HASH TABLES. Goal is to store elements k,v at index i = h k

HASH TABLES. Goal is to store elements k,v at index i = h k CH 9.2 : HASH TABLES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM JORY DENNY AND

More information

Hashing. Manolis Koubarakis. Data Structures and Programming Techniques

Hashing. Manolis Koubarakis. Data Structures and Programming Techniques Hashing Manolis Koubarakis 1 The Symbol Table ADT A symbol table T is an abstract storage that contains table entries that are either empty or are pairs of the form (K, I) where K is a key and I is some

More information

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40 Lecture 16 Hashing Hash table and hash function design Hash functions for integers and strings Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table

More information

Priority Queues and Heaps (continues) Chapter 13: Heaps, Balances Trees and Hash Tables Hash Tables In-class Work / Suggested homework.

Priority Queues and Heaps (continues) Chapter 13: Heaps, Balances Trees and Hash Tables Hash Tables In-class Work / Suggested homework. Outline 1 Chapter 13: Heaps, Balances Trees and Hash Tables Priority Queues and Heaps (continues) Hash Tables Binary Heaps Binary Heap is a complete binary tree, whose nodes are labeled with integer values

More information

CSCD 326 Data Structures I Hashing

CSCD 326 Data Structures I Hashing 1 CSCD 326 Data Structures I Hashing Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional searching time complexity available is O(log2n)

More information

UNIT III BALANCED SEARCH TREES AND INDEXING

UNIT III BALANCED SEARCH TREES AND INDEXING UNIT III BALANCED SEARCH TREES AND INDEXING OBJECTIVE The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions and finds in constant

More information

Fundamental Algorithms

Fundamental Algorithms Fundamental Algorithms Chapter 7: Hash Tables Michael Bader Winter 2011/12 Chapter 7: Hash Tables, Winter 2011/12 1 Generalised Search Problem Definition (Search Problem) Input: a sequence or set A of

More information

HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018

HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018 HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018 Acknowledgement The set of slides have used materials from the following resources Slides for textbook by Dr. Y.

More information

Lecture 7: Efficient Collections via Hashing

Lecture 7: Efficient Collections via Hashing Lecture 7: Efficient Collections via Hashing These slides include material originally prepared by Dr. Ron Cytron, Dr. Jeremy Buhler, and Dr. Steve Cole. 1 Announcements Lab 6 due Friday Lab 7 out tomorrow

More information

More on Hashing: Collisions. See Chapter 20 of the text.

More on Hashing: Collisions. See Chapter 20 of the text. More on Hashing: Collisions See Chapter 20 of the text. Collisions Let's do an example -- add some people to a hash table of size 7. Name h = hash(name) h%7 Ben 66667 6 Bob 66965 3 Steven -1808493797-5

More information

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved Introducing Hashing Chapter 21 Contents What Is Hashing? Hash Functions Computing Hash Codes Compressing a Hash Code into an Index for the Hash Table A demo of hashing (after) ARRAY insert hash index =

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS LECTURE 11 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 In Lecture 9-10... Hash tables ADT Stack ADT Queue ADT Deque ADT Priority Queue Hash tables Today Hash tables 1 Hash

More information

CS 2412 Data Structures. Chapter 10 Sorting and Searching

CS 2412 Data Structures. Chapter 10 Sorting and Searching CS 2412 Data Structures Chapter 10 Sorting and Searching Some concepts Sorting is one of the most common data-processing applications. Sorting algorithms are classed as either internal or external. Sorting

More information

Fast Lookup: Hash tables

Fast Lookup: Hash tables CSE 100: HASHING Operations: Find (key based look up) Insert Delete Fast Lookup: Hash tables Consider the 2-sum problem: Given an unsorted array of N integers, find all pairs of elements that sum to a

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 30, 2016 Outline Outline 1 Chapter 13: Heaps, Balances Trees and Hash Tables Hash Tables Outline 1 Chapter 13: Heaps,

More information

Hashing. It s not just for breakfast anymore! hashing 1

Hashing. It s not just for breakfast anymore! hashing 1 Hashing It s not just for breakfast anymore! hashing 1 Hashing: the facts Approach that involves both storing and searching for values (search/sort combination) Behavior is linear in the worst case, but

More information

CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II

CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II Review from Lecture 19 CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II Operators as non-member functions, as member functions, and as friend functions. A hash table is a table implementation

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information

Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ.! Instructor: X. Zhang Spring 2017

Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ.! Instructor: X. Zhang Spring 2017 Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ.! Instructor: X. Zhang Spring 2017 Acknowledgement The set of slides have used materials from the following resources Slides

More information

Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ. Acknowledgement. Support for Dictionary

Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ. Acknowledgement. Support for Dictionary Algorithms with numbers (2) CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Spring 2017 Acknowledgement The set of slides have used materials from the following resources Slides for

More information

Data Structures and Algorithms(10)

Data Structures and Algorithms(10) Ming Zhang "Data Structures and Algorithms" Data Structures and Algorithms(10) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh

More information

Hash Tables and Hash Functions

Hash Tables and Hash Functions Hash Tables and Hash Functions We have seen that with a balanced binary tree we can guarantee worst-case time for insert, search and delete operations. Our challenge now is to try to improve on that...

More information

Design Patterns for Data Structures. Chapter 9.5. Hash Tables

Design Patterns for Data Structures. Chapter 9.5. Hash Tables Hash Tables Binary information representation 0 0000 8 1000 1 0001 9 1001 2 0010 A 1010 3 0011 B 1011 4 0100 C 1100 5 0101 D 1101 6 0110 E 1110 7 0111 F 1111 (a) Hexadecimal abbreviation for binary values.

More information

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) ASSIGNMENTS Chapter Q. No. Questions Course Outcom e (CO) Progra m Outcom e I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n)) 2 3. What is the time complexity of the algorithm? 4

More information

9/24/ Hash functions

9/24/ Hash functions 11.3 Hash functions A good hash function satis es (approximately) the assumption of SUH: each key is equally likely to hash to any of the slots, independently of the other keys We typically have no way

More information

CITS2200 Data Structures and Algorithms. Topic 15. Hash Tables

CITS2200 Data Structures and Algorithms. Topic 15. Hash Tables CITS2200 Data Structures and Algorithms Topic 15 Hash Tables Introduction to hashing basic ideas Hash functions properties, 2-universal functions, hashing non-integers Collision resolution bucketing and

More information

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada CS102 Hash Tables Prof. Tejada 1 Vectors, Linked Lists, Stack, Queues, Deques Can t provide fast insertion/removal and fast lookup at the same time The Limitations of Data Structure Binary Search Trees,

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Hash Table. A hash function h maps keys of a given type into integers in a fixed interval [0,m-1]

Hash Table. A hash function h maps keys of a given type into integers in a fixed interval [0,m-1] Exercise # 8- Hash Tables Hash Tables Hash Function Uniform Hash Hash Table Direct Addressing A hash function h maps keys of a given type into integers in a fixed interval [0,m-1] 1 Pr h( key) i, where

More information

Algorithms and Data Structures

Algorithms and Data Structures Lesson 4: Sets, Dictionaries and Hash Tables Luciano Bononi http://www.cs.unibo.it/~bononi/ (slide credits: these slides are a revised version of slides created by Dr. Gabriele D Angelo)

More information

CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS

CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS 0 1 2 025-612-0001 981-101-0002 3 4 451-229-0004 CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,

More information

Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University

Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University U Kang 1 In This Lecture Motivation of collision resolution policy Open hashing for collision resolution Closed hashing

More information

BBM371& Data*Management. Lecture 6: Hash Tables

BBM371& Data*Management. Lecture 6: Hash Tables BBM371& Data*Management Lecture 6: Hash Tables 8.11.2018 Purpose of using hashes A generalization of ordinary arrays: Direct access to an array index is O(1), can we generalize direct access to any key

More information

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Hash Open Indexing Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Consider a StringDictionary using separate chaining with an internal capacity of 10. Assume our buckets are implemented

More information

CS 261 Data Structures

CS 261 Data Structures CS 261 Data Structures Hash Tables Open Address Hashing ADT Dictionaries computer kəәmˈpyoōtəәr noun an electronic device for storing and processing data... a person who makes calculations, esp. with a

More information

III Data Structures. Dynamic sets

III Data Structures. Dynamic sets III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations

More information

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell Hash Tables CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 22, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005

More information

Hashing. mapping data to tables hashing integers and strings. aclasshash_table inserting and locating strings. inserting and locating strings

Hashing. mapping data to tables hashing integers and strings. aclasshash_table inserting and locating strings. inserting and locating strings Hashing 1 Hash Functions mapping data to tables hashing integers and strings 2 Open Addressing aclasshash_table inserting and locating strings 3 Chaining aclasshash_table inserting and locating strings

More information

ECE 242 Data Structures and Algorithms. Hash Tables I. Lecture 24. Prof.

ECE 242 Data Structures and Algorithms.  Hash Tables I. Lecture 24. Prof. ECE 242 Data Structures and Algorithms http//www.ecs.umass.edu/~polizzi/teaching/ece242/ Hash Tables I Lecture 24 Prof. Eric Polizzi Motivations We have to store some records and perform the following

More information

Hashing 1. Searching Lists

Hashing 1. Searching Lists Hashing 1 Searching Lists There are many instances when one is interested in storing and searching a list: A phone company wants to provide caller ID: Given a phone number a name is returned. Somebody

More information

CS 3410 Ch 20 Hash Tables

CS 3410 Ch 20 Hash Tables CS 341 Ch 2 Hash Tables Sections 2.1-2.7 Pages 773-82 2.1 Basic Ideas 1. A hash table is a data structure that supports insert, remove, and find in constant time, but there is no order to the items stored.

More information

THINGS WE DID LAST TIME IN SECTION

THINGS WE DID LAST TIME IN SECTION MA/CSSE 473 Day 24 Student questions Space-time tradeoffs Hash tables review String search algorithms intro We did not get to them in other sections THINGS WE DID LAST TIME IN SECTION 1 1 Horner's Rule

More information

CMSC 341 Hashing. Based on slides from previous iterations of this course

CMSC 341 Hashing. Based on slides from previous iterations of this course CMSC 341 Hashing Based on slides from previous iterations of this course Hashing Searching n Consider the problem of searching an array for a given value q If the array is not sorted, the search requires

More information