CSE 214 Computer Science II Searching

Size: px
Start display at page:

Download "CSE 214 Computer Science II Searching"

Transcription

1 CSE 214 Computer Science II Searching Fall 2017 Stony Brook University Instructor: Shebuti Rayana

2 Introduction Searching in a list of values is a common computational task Some real-world applications: Retrieve a student record, bank account record, credit record etc. Searching words in a dictionary Searching algorithms that we will cover: Ø Serial Search Ø Binary Search Ø Search by Hashing Shebuti Rayana (CS, Stony Brook University) 2

3 Problem: Searching We are given a array/list of records. Each record has an associated key. Give efficient algorithm for searching for a record containing a particular key. Efficiency is quantified in terms of time analysis (number of comparisons) to retrieve an item. Shebuti Rayana (CS, Stony Brook University) 3

4 Searching: Example [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 700 ] Number Number Number Number Number Number Each record in list has an associated key. In this example, the keys are ID numbers. Number Given a particular key, how can we efficiently retrieve the record from the list? Shebuti Rayana (CS, Stony Brook University) 4

5 Tables A table, or dictionary, is an abstract data type whose data items are stored and retrieved according to a key value. The items are called records. Each record can have a number of data fields. The records are ordered based on one of the data fields, named the key field. The record we are searching for has a key value that is called the target. The table may be implemented using a variety of data structures: array, tree, heap etc. Shebuti Rayana (CS, Stony Brook University) 5

6 Serial Search Also called Linear or sequential search 1. Step through array/list of records, one at a time. 2. Look for record with matching key. 3. Search stops when record with matching key is found or when search has examined all records without success. Shebuti Rayana (CS, Stony Brook University) 6

7 Serial Search: Implementation Searching key in an Array public static int search(int[] a, int target) { } int i = 0; boolean found = false; while ((i < a.length) &&! found) { } if (a[i] == target) else i++; found = true; if (found) return i; else return 1; Shebuti Rayana (CS, Stony Brook University) 7

8 Serial Search: Implementation Searching key in a Table public static int search(tableclass[] a, int target) { } int i = 0; boolean found = false; while ((i < a.length) &&!found){ } if (a[i].getkey() == target) else i++; found = true; if (found) return i; else return 1; With this code you can do serial search in any sequential data structure Shebuti Rayana (CS, Stony Brook University) 8

9 Complexity Analysis: Serial Search on N elements Best Case: The best case time requires just one comparison: O(1) When the item is in the front of the array Average Case: The average-case time requires (N+1)/2 comparisons: O(N) In average case consider all the possibilities and take the average ( N)/N = (N(N+1)/2)/N = (N+1)/2 Worst Case: The worst-case time requires N comparisons: O(N) When the item is not present or found at the end of the array Shebuti Rayana (CS, Stony Brook University) 9

10 Although serial search is a linear searching algorithm, do you think this is the most efficient algorithm? Shebuti Rayana (CS, Stony Brook University) 10

11 Binary Search A faster algorithm than serial search Can be applied to any random-access data structure where the data elements are sorted. Additional parameters: first: index of the first element to examine size: number of elements to search starting from the first element above Shebuti Rayana (CS, Stony Brook University) 11

12 Some examples where binary search is applicable Searching an array of integers in which the array is sorted from the smallest integer (at the front) to the largest integer (at the end). Searching an array of strings in which the strings are sorted alphabetically. Searching an array of Objects containing information about some item, such as an auto part, and the array is sorted by part numbers from the smallest to largest. Shebuti Rayana (CS, Stony Brook University) 12

13 Binary Search Precondition: If size > 0, then the array has size elements starting with the element at the first index. In addition, these elements are sorted. Postcondition: If target appears, the position of the target is returned (a non-negative integer). Otherwise, -1 is returned. Shebuti Rayana (CS, Stony Brook University) 13

14 Recursive Binary Search [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] Look at the middle element of the array first. If it is the target, you are done If not, it might be in the left half of the array or the right half, but not both! Shebuti Rayana (CS, Stony Brook University) 14

15 Recursive Binary Search public static int search(int[] a, int first, int size, int target) { } int mid; if (size <= 0) return 1; else { mid = first + (size/2); if (target == a[mid]) return mid; else if (target < a[mid]) return search(a, first, size/2, target); else return search(a, mid+1,(size-1)/2, target); } Shebuti Rayana (CS, Stony Brook University) 15

16 Recursive Binary Search : Example a [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Function call: search(a, 0, 10, 42) mid = first + size/2 = /2 = 5 and a[5] = 52 which is greater than 42. So the algorithms makes the next recursive call search(a, 0, 5, 42) a [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Shebuti Rayana (CS, Stony Brook University) 16

17 Recursive Binary Search : Example Each recursive call throws away at least half of the elements. a [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] mid = first + size/2 = 0 + 5/2 = 2 and a[2] = 29 which is smaller than 42. So the algorithms makes the next recursive call search(a, 3, 2, 42) a [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Now, mid = 3 + 2/2 = 4 and a[4] = 42, target is found and index 4 is returned Shebuti Rayana (CS, Stony Brook University) 17

18 Recursive Binary Search in a Table public static int search(tableclass[] a, int first, int size, int target) { int mid; if (size <= 0) return 1; else { mid = first + (size/2); if(target == a[mid].getkey()) return mid; else if (target < a[mid].getkey()) return search(a, first, size/2, target); else return search(a,mid+1,(size-1)/2,target); } } Shebuti Rayana (CS, Stony Brook University) 18

19 Complexity Analysis: Binary Search on N elements Let T(N) = the total number of comparisons for a search on N elements. T(N) = 1 + T(N/2) T(N/2) = 1 + T(N/4)... T(1) = 1 Ø T(N) = = O(log 2 N) [worst-case time] Example: Search 42 a Is Binary Search in a sorted array better than searching in BST? [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] T(10) = 1 + T(5) = T(2) = = 3 ~ log 2 (10) Shebuti Rayana (CS, Stony Brook University) 19

20 What is the limitation of binary search? Shebuti Rayana (CS, Stony Brook University) 20

21 Hashing Data records are stored in a hash table. The position of a data record in the hash table is determined by its key. A hash function maps keys to positions in the hash table. If a hash function maps two keys to the same position in the hash table, then a collision occurs. Shebuti Rayana (CS, Stony Brook University) 21

22 Goals of Hashing An insert without a collision takes O(1) time. A search also takes O(1) time, if the record is stored in its proper location. The hash function can take many forms: If the key k is an integer: k % tablesize If key k is a String : k.hashcode() % tablesize Any function that maps k to a table position! The table size should be a prime number. To guarantee even distribution and minimize collision Shebuti Rayana (CS, Stony Brook University) 22

23 A Simple Hashing: Example Let the hash table be an 11-element array. If k is the key of a data record, let H(k) represent the hash function, where H(k) = k mod 11. Insert the keys 83, 14, 29, 70, 55, 72: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Inserting 72 now would cause a collision! Shebuti Rayana (CS, Stony Brook University) 23

24 Collision Resolution Techniques Open-addressing Linear Probing Quadratic Probing Double Hashing Chained hashing (or Chaining) Shebuti Rayana (CS, Stony Brook University) 24

25 Open-Addressing: Linear Probing During insert of a key k into position p: If position p already contains a different key, then examine positions p + 1, p + 2, etc.* until an empty position is found and insert k there. During a search for key k at position p: If position p already contains a different key, then examine positions p + 1, p + 2, etc.* until either the key is found or an unused position is encountered. *wrap around to beginning of array if p + i > tablesize Shebuti Rayana (CS, Stony Brook University) 25

26 Open-Addressing: Linear Probing Example: Insert additional key 72, 36, 48 using H(k) = k mod 11 and linear probing [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Shebuti Rayana (CS, Stony Brook University) 26

27 Open-Addressing: Quadratic Probing If position p already contains a different key, then examine positions p + 1, p + 4, p + 9, etc. until either the key is found or an empty position is encountered. Example: Insert additional key 22, 66, 77 using H(k) = k mod 11 and quadratic probing [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Quadratic probing over Linear probing? In quadrating probing values are more spread out which reduces collision. Shebuti Rayana (CS, Stony Brook University) 27

28 Problem in Probing If we remove a key from the hash table, can we get into problems? [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Remove 83. Now search for 48. We can t find 48 due to the gap in position 6! Shebuti Rayana (CS, Stony Brook University) 28

29 Problem in Probing: Solution Add another array with boolean values that indicate whether the position is currently used or has been used in the past. If a key is removed, leave the boolean value set at true so we can search past it if necessary [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] T F F T T T T T T T F Shebuti Rayana (CS, Stony Brook University) 29

30 Load Factor A critical influence on performance of an open addressing hash table is the load factor The load factor α of a hash table is given by the following formula: α = (number of elements in table)/(size of table) Thus, 0 < α < 1 for linear probing. (α can be greater than 1 for other collision resolution methods like chained hashing) For linear probing, as α approaches 1, the number of collisions increases Shebuti Rayana (CS, Stony Brook University) 30

31 Hash Table ADT with Linear Probing Invariants for the Hash Table: The number of elements in the table manyitems We try to store an element with a given key k at location hash(k). If a collision occurs, linear probing is used to find a location to store the element and its associated key. When an open address is found at index i, then the element is placed in data[i], and its key is placed in key[i]. If index i has never been used in the table, data[i] and key[i] are set to null. If index i is or has been used in the past, then hasbeenused[i] is true; otherwise it is false. Shebuti Rayana (CS, Stony Brook University) 31

32 Various Hash functions Division hash function convert key to a positive integer return the integer modulo the table size Mid-square hash function convert key to an integer multiply the integer by itself return several digits in the middle of result Multiplicative hash function convert the key to an integer multiply the integer by a constant less than 1 return the first several digits of the fractional part Shebuti Rayana (CS, Stony Brook University) 32

33 Clustering Problem in Probing Linear Probing can cause significant primary clustering problem. Quadratic probing can also cause secondary clustering problem. Shebuti Rayana (CS, Stony Brook University) 33

34 Primary Clustering Primary Clustering is the tendency for a collision resolution scheme such as linear probing to create long runs of filled slots near the hash position of keys. If the primary hash index is x, subsequent probes go to x+1, x+2, x+3 and so on, this results in Primary Clustering. Once the primary cluster forms, the bigger the cluster gets, the faster it grows. And it reduces the performance. Shebuti Rayana (CS, Stony Brook University) 34

35 Secondary Clustering Secondary Clustering is the tendency for a collision resolution scheme such as quadratic probing to create long runs of filled slots away from the hash position of keys. If the primary hash index is x, probes go to x+1, x+4, x+9, x+16, x+25 and so on, this results in Secondary Clustering. Secondary clustering is less severe in terms of performance hit than primary clustering, and is an attempt to keep clusters from forming by using Quadratic Probing. The idea is to probe more widely separated cells, instead of those adjacent to the primary hash site. Shebuti Rayana (CS, Stony Brook University) 35

36 Reducing Clustering: Double Hashing To reduce clustering, use double hashing. Define two hash functions: hash1 and hash2 Use the hash1 function to determine the initial location of the key in the hash table. If a collision occurs, use the hash2 function to determine how far to move ahead to look for a vacant location in the hash table. Shebuti Rayana (CS, Stony Brook University) 36

37 Double Hashing In double hashing, the array index must not leave the range [0, tablesize-1] To keep the index within this range, we do following Suppose that i is the index we have just examined (with a collision) then the next index to examine is (i + hash2(key)) % tablesize As we step through the array, we must mane sure every position is examined. Problem: with double hashing, we could come back to our starting point before we examine all the positions. Shebuti Rayana (CS, Stony Brook University) 37

38 Double Hashing Make sure the tablesize is relatively prime with the value returned by hash2. Choose tablesize as a prime number Have hash2 return values in the range [1, tablesize-1] Double hashing rule by Donald Knuth: 1. Both tablesize and (tablesize 2) should be prime numbers. For example, 1231 is a prime and so is 1229 (two such primes separated by 2 are called twin primes) 2. hash1(key) = key % tablesize 3. hash2(key) = 1 + (key % (tablesize - 2)) Shebuti Rayana (CS, Stony Brook University) 38

39 Example: Double Hashing H1(k) = k % 1231, [tablesize = 1231] H2(k) = 1 + (k % 1229) For key k = 2000, H1(k) = 769 If location 769 is occupied, H2(k) = 772 So we check position ( ) % 1231 = 310 to see if it is occupied. If it is, we check position ( ) % 1231 = 1082, etc. d = gcd(h2(k), tablesize) = 1 The table size is relatively prime to the value returned by the second hash function H2. Shebuti Rayana (CS, Stony Brook University) 39

40 Example: Double Hashing (cont.) H1(k) = k % 100 H2(k) = 2 + (k % 52) For key k = 204, H1(k) = 4 If location 4 is occupied, H2(k) = 50 So we check position (4+50) % 100 = 54 to see if it is occupied. We came back to the starting point If it is, we check position (54+50) % 100 = 4. Table size is not relatively prime to the value returned by the second hash function hash2. d = gcd(h2(k), tablesize) = 50 Shebuti Rayana (CS, Stony Brook University) 40

41 Chained Hashing The maximum number of elements that can be stored in a hash table implemented using an array is the tablesize (α = 1.0). We can have a load factor greater than 1.0 by using chained hashing. Each array position in the hash table is a head reference to a linked list of keys. All colliding keys that hash to an array position are inserted to that linked list. Insertion: O(1), Deletion: O(1), if doubly linked list is used Shebuti Rayana (CS, Stony Brook University) 41

42 Example: Chained Hashing Shebuti Rayana (CS, Stony Brook University) 42

43 Average Search Time The average number of table elements examined in a successful search is approximately: (1 + 1 / (1 - α)) / 2 using linear probing* -ln(1 - α) / α using double hashing* 1 + α / 2 using chained hashing *assuming a non-full hash table Shebuti Rayana (CS, Stony Brook University) 43

44 Average Search Time: Chaining Suppose, Table size = m and number of elements = n Search finds the element x $ Let s call all the elements x %, x ', x (,, x * On the average, how many of the remaining n i elements map to the same list as x $? y = / 1 m 23$4% [Because the probability of each element getting mapped to the same slot is 1 m.] Therefore, on average, the number of elements examined before finding x $ is 1 + y. * Shebuti Rayana (CS, Stony Brook University) 44

45 Average Search Time: Chaining * y = / 1 m 23$4% * = 1 m / 1 23$4% = (*8$) : Therefore, on average, the number of elements examined before finding x $ is 1 + (n i) m. The last step is to take the average of this formula over all x $. Shebuti Rayana (CS, Stony Brook University) 45

46 Average Search Time: Chaining Thus, on average, the number of searches to find any element is the average over all x i. Which is (1 n) X number of examinations to find x i [over all x i ] = % * (1 + *8$ ) * $3% = % (n + * *8$ : * $3% ) : % = 1 + * (n i) :* $3% = 1 + *8% = 1 + % α % ': ' ': Main target is that the load factor stays constant and both m and n keep increasing. That is, find the limit of the above expression as m, n Shebuti Rayana (CS, Stony Brook University) 46

47 Average number of table elements examined during successful search Load factor(a ) Open addressing, linear probing ½ (1+1/(1-a )) Open addressing double hashing -ln(1-a )/a Chained hashing 1+a / Not applicable Not applicable Not applicable Not applicable Not applicable Not applicable 2.50 Shebuti Rayana (CS, Stony Brook University) 47

48 Average number of table elements examined during successful search Shebuti Rayana (CS, Stony Brook University) 48

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

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

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

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 04 / 16 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Shortest weight path (Dijkstra's algorithm) Besides the final shortest weights

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

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

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

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

! 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

CSE 230 Computer Science II (Data Structure) Introduction

CSE 230 Computer Science II (Data Structure) Introduction CSE 230 Computer Science II (Data Structure) Introduction Fall 2017 Stony Brook University Instructor: Shebuti Rayana Basic Terminologies Data types Data structure Phases of S/W development Specification

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

Topics Applications Most Common Methods Serial Search Binary Search Search by Hashing (next lecture) Run-Time Analysis Average-time analysis Time anal

Topics Applications Most Common Methods Serial Search Binary Search Search by Hashing (next lecture) Run-Time Analysis Average-time analysis Time anal CSC212 Data Structure t Lecture 18 Searching Instructor: George Wolberg Department of Computer Science City College of New York @ George Wolberg, 2016 1 Topics Applications Most Common Methods Serial Search

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

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials)

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials) CSE100 Advanced Data Structures Lecture 21 (Based on Paul Kube course materials) CSE 100 Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table cost

More information

CS1020 Data Structures and Algorithms I Lecture Note #15. Hashing. For efficient look-up in a table

CS1020 Data Structures and Algorithms I Lecture Note #15. Hashing. For efficient look-up in a table CS1020 Data Structures and Algorithms I Lecture Note #15 Hashing For efficient look-up in a table Objectives 1 To understand how hashing is used to accelerate table lookup 2 To study the issue of collision

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

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

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

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

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

CSE 214 Computer Science II Heaps and Priority Queues

CSE 214 Computer Science II Heaps and Priority Queues CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction

More information

Hashing. 5/1/2006 Algorithm analysis and Design CS 007 BE CS 5th Semester 2

Hashing. 5/1/2006 Algorithm analysis and Design CS 007 BE CS 5th Semester 2 Hashing Hashing A hash function h maps keys of a given type to integers in a fixed interval [0,N-1]. The goal of a hash function is to uniformly disperse keys in the range [0,N-1] 5/1/2006 Algorithm analysis

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

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

Hash Tables Hash Tables Goodrich, Tamassia

Hash Tables Hash Tables Goodrich, Tamassia Hash Tables 0 1 2 3 4 025-612-0001 981-101-0002 451-229-0004 Hash Tables 1 Hash Functions and Hash Tables A hash function h maps keys of a given type to integers in a fixed interval [0, N 1] Example: h(x)

More information

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable Hashing Dynamic Dictionaries Operations: create insert find remove max/ min write out in sorted order Only defined for object classes that are Comparable Hash tables Operations: create insert find remove

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

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

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

Hash Tables. Johns Hopkins Department of Computer Science Course : Data Structures, Professor: Greg Hager

Hash Tables. Johns Hopkins Department of Computer Science Course : Data Structures, Professor: Greg Hager Hash Tables What is a Dictionary? Container class Stores key-element pairs Allows look-up (find) operation Allows insertion/removal of elements May be unordered or ordered Dictionary Keys Must support

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

Today: Finish up hashing Sorted Dictionary ADT: Binary search, divide-and-conquer Recursive function and recurrence relation

Today: Finish up hashing Sorted Dictionary ADT: Binary search, divide-and-conquer Recursive function and recurrence relation Announcements HW1 PAST DUE HW2 online: 7 questions, 60 points Nat l Inst visit Thu, ok? Last time: Continued PA1 Walk Through Dictionary ADT: Unsorted Hashing Today: Finish up hashing Sorted Dictionary

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

IS 2610: Data Structures

IS 2610: Data Structures IS 2610: Data Structures Searching March 29, 2004 Symbol Table A symbol table is a data structure of items with keys that supports two basic operations: insert a new item, and return an item with a given

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

Chapter 9: Maps, Dictionaries, Hashing

Chapter 9: Maps, Dictionaries, Hashing Chapter 9: 0 1 025-612-0001 2 981-101-0002 3 4 451-229-0004 Maps, Dictionaries, Hashing Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided

More information

Lecture 4. Hashing Methods

Lecture 4. Hashing Methods Lecture 4 Hashing Methods 1 Lecture Content 1. Basics 2. Collision Resolution Methods 2.1 Linear Probing Method 2.2 Quadratic Probing Method 2.3 Double Hashing Method 2.4 Coalesced Chaining Method 2.5

More information

Priority Queue Sorting

Priority Queue Sorting Priority Queue Sorting We can use a priority queue to sort a list of comparable elements 1. Insert the elements one by one with a series of insert operations 2. Remove the elements in sorted order with

More information

Today s Outline. CS 561, Lecture 8. Direct Addressing Problem. Hash Tables. Hash Tables Trees. Jared Saia University of New Mexico

Today s Outline. CS 561, Lecture 8. Direct Addressing Problem. Hash Tables. Hash Tables Trees. Jared Saia University of New Mexico Today s Outline CS 561, Lecture 8 Jared Saia University of New Mexico Hash Tables Trees 1 Direct Addressing Problem Hash Tables If universe U is large, storing the array T may be impractical Also much

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/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

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum Table ADT and Sorting Algorithm topics continuing (or reviewing?) CS 24 curriculum A table ADT (a.k.a. Dictionary, Map) Table public interface: // Put information in the table, and a unique key to identify

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

CSc 110, Spring 2017 Lecture 39: searching

CSc 110, Spring 2017 Lecture 39: searching CSc 110, Spring 2017 Lecture 39: searching 1 Sequential search sequential search: Locates a target value in a list (may not be sorted) by examining each element from start to finish. Also known as linear

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

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

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

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

HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015

HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015 HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 9 is due on Monday -assignment 10 will go out on Thursday -midterm on Thursday 3 last time 4

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

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

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

Dictionaries and Hash Tables

Dictionaries and Hash Tables Dictionaries and Hash Tables 0 1 2 3 025-612-0001 981-101-0002 4 451-229-0004 Dictionaries and Hash Tables 1 Dictionary ADT The dictionary ADT models a searchable collection of keyelement items The main

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

This lecture. Iterators ( 5.4) Maps. Maps. The Map ADT ( 8.1) Comparison to java.util.map

This lecture. Iterators ( 5.4) Maps. Maps. The Map ADT ( 8.1) Comparison to java.util.map This lecture Iterators Hash tables Formal coursework Iterators ( 5.4) An iterator abstracts the process of scanning through a collection of elements Methods of the ObjectIterator ADT: object object() boolean

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

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

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Chapter 27 Hashing. Objectives

Chapter 27 Hashing. Objectives Chapter 27 Hashing 1 Objectives To know what hashing is for ( 27.3). To obtain the hash code for an object and design the hash function to map a key to an index ( 27.4). To handle collisions using open

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

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

Tirgul 7. Hash Tables. In a hash table, we allocate an array of size m, which is much smaller than U (the set of keys).

Tirgul 7. Hash Tables. In a hash table, we allocate an array of size m, which is much smaller than U (the set of keys). Tirgul 7 Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys belong to a universal group of keys, U = {1... M}.

More information

Data Structures and Algorithms. Chapter 7. Hashing

Data Structures and Algorithms. Chapter 7. Hashing 1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Dictionaries-Hashing. Textbook: Dictionaries ( 8.1) Hash Tables ( 8.2)

Dictionaries-Hashing. Textbook: Dictionaries ( 8.1) Hash Tables ( 8.2) Dictionaries-Hashing Textbook: Dictionaries ( 8.1) Hash Tables ( 8.2) Dictionary The dictionary ADT models a searchable collection of key-element entries The main operations of a dictionary are searching,

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers CSE 230 Intermediate Programming in C and C++ Arrays and Pointers Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Definition: Arrays A collection of elements

More information

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015 BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 10 is due on Thursday -midterm grades out tomorrow 3 last time 4 -a hash table is a general storage

More information

Lecture 17. Improving open-addressing hashing. Brent s method. Ordered hashing CSE 100, UCSD: LEC 17. Page 1 of 19

Lecture 17. Improving open-addressing hashing. Brent s method. Ordered hashing CSE 100, UCSD: LEC 17. Page 1 of 19 Lecture 7 Improving open-addressing hashing Brent s method Ordered hashing Page of 9 Improving open addressing hashing Recall the average case unsuccessful and successful find time costs for common openaddressing

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

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

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

Why do we need hashing?

Why do we need hashing? jez oar Hashing Hashing Ananda Gunawardena Many applications deal with lots of data Search engines and web pages There are myriad look ups. The look ups are time critical. Typical data structures like

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

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

Data Structures and Algorithms. Roberto Sebastiani

Data Structures and Algorithms. Roberto Sebastiani Data Structures and Algorithms Roberto Sebastiani roberto.sebastiani@disi.unitn.it http://www.disi.unitn.it/~rseba - Week 07 - B.S. In Applied Computer Science Free University of Bozen/Bolzano academic

More information

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

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

UNIT 5. Sorting and Hashing

UNIT 5. Sorting and Hashing UNIT 5 Sorting and Hashing SORTING METHODS SYLLABUS: 5.1.Sorting Methods a. Bubble Sort, b. Selection Sort, c. Quick Sort, d. Insertion Sort, e. Merge Sort, f. Radix Sort 5.2.Hashing Concepts CONTINUE

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

Data Structures (CS 1520) Lecture 23 Name:

Data Structures (CS 1520) Lecture 23 Name: Data Structures (CS ) Lecture Name: ListDict object _table Python list object.... Consider the following ListDict class implementation. class Entry(object): """A key/value pair.""" def init (self, key,

More information

Priority Queue. 03/09/04 Lecture 17 1

Priority Queue. 03/09/04 Lecture 17 1 Priority Queue public interface PriorityQueue { public interface Position { Comparable getvalue( ); } Position insert( Comparable x ); Comparable findmin( ); Comparable deletemin( ); boolean isempty( );

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

CS 241 Analysis of Algorithms

CS 241 Analysis of Algorithms CS 241 Analysis of Algorithms Professor Eric Aaron Lecture T Th 9:00am Lecture Meeting Location: OLB 205 Business HW5 extended, due November 19 HW6 to be out Nov. 14, due November 26 Make-up lecture: Wed,

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012 1 University of Toronto Department of Electrical and Computer Engineering Midterm Examination ECE 345 Algorithms and Data Structures Fall 2012 Print your name and ID number neatly in the space provided

More information

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

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

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

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

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

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

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

Hash Tables. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited

Hash Tables. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited Unit 9, Part 4 Hash Tables Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Data Dictionary Revisited We've considered several data structures that allow us to store and search for data

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

lecture23: Hash Tables

lecture23: Hash Tables lecture23: Largely based on slides by Cinda Heeren CS 225 UIUC 18th July, 2013 Announcements mp6.1 extra credit due tomorrow tonight (7/19) lab avl due tonight mp6 due Monday (7/22) Hash tables A hash

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

Elementary Data Structures 2

Elementary Data Structures 2 Elementary Data Structures Priority Queues, & Dictionaries Priority Queues Sell 00 IBM $ Sell 300 IBM $0 Buy 00 IBM $9 Buy 400 IBM $8 Priority Queue ADT A priority queue stores a collection of items An

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

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

Hash Tables. Hash functions Open addressing. March 07, 2018 Cinda Heeren / Geoffrey Tien 1

Hash Tables. Hash functions Open addressing. March 07, 2018 Cinda Heeren / Geoffrey Tien 1 Hash Tables Hash functions Open addressing Cinda Heeren / Geoffrey Tien 1 Hash functions A hash function is a function that map key values to array indexes Hash functions are performed in two steps Map

More information