EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The hash coding method described in the text links all the entries having the same
hash code together on a linked list. An alternative method is to have only a single n-
slot table, with each table slot having room for one key and its value (or pointers to
them). If the hashing algorithm generates a slot that is already full, a second hashing
algorithm is used to try again. If that one is also full, another is used, and so on, until
an empty is found. If the fraction of the slots that are full is R, how many probes will
be needed, on the average, to enter a new symbol?
Hash table is a data structure in which keys are mapped to array positions by a hash function. The
process of mapping the keys to appropriate locations in a hash table is called hashing. Hash functions are
used to reduce the number of collisions.
i.
Mention the methods to minimize collision.
ii.
Explain the advantage of using double hashing over linear and quadratic probing techniques.
Load the keys given below in a hash table of size 7 in the same order using chaining with the
hash function h(key)= key % 7. Show graphically how collisions are resolved using chaining
in this particular case.
ii.
12, 101, 3, 21, 14, 13, 16, 7, (last two digits of your reg # + 102)
Why is it giving me an error and what do I have to change?
PYTHON
# Problem 2# Implement a hashtable using an array. Your implementation should include public methods for insertion, deletion, and# search, as well as helper methods for resizing. The hash table is resized when the max chain length becomes greater# than 3 during insertion of a new item. You will be using linear chaining technique for collision resolution. Assume# the key to be an integer and use the hash function h(k) = k mod m where m is the size of the hashtable. You can use# python list methods in your implementation of the chain or you can also use your linked list implementation from# coding assignment 2, problem 1. You can make necessary changes to __hashtable initialization in the __init__ method# if you are using your linked list implementation. The provided code uses python lists for the __hashtable variable.
class HashTableChain: def __init__(self, size=10): # Initialize the hashtable with the given…
Chapter 10 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Similar questions
- Draw a hash table given these numbers and hashing function, build each of the hashing options, and decide if it is efficient, and what function or size might be a better match. Explain why it is efficient or what changes you would make for it to be efficient. a. Scenario 1 a. Hashing function: k mod 4 b. Linear Probing c. Array from 0 to 3 d. Values: 19, 7, 12, 11 b. Scenario 2 a. Hashing function: k mod 10 b. Quadratic Probing c. Array from 0 to 9 d. Values: 20 39 23 56 34 29 55 13 c. Scenario 3 a. Hashing function: first three digits of a phone number b. Overflow chaining c. File with base address of 0 and ends at 999 d. Values: 3135552314, 7343455523, 3134445555, 3134441234, 7342346555, e. 5555342232, 4072984555, 2692185552 d. Scenario 4 a. Hashing function: k mod 100 b. Internal Chaining c. Array 0 to 99 d. Values: 314 325 623 2234 425 1234 2132 2361 1245 123 436 742arrow_forwardA hash table is an efficient data structure to store and access data via keys. In this problem, you need to find the longest subarray of distinct elements. For example, given an array A = <milk, water, 6724, water, soda, beer, apple, grape, wine>, the longest subarray is <milk, water, 6724, soda, beer, apple, grape, wine> Hint: you need to keep track and update the positions of the elements. a) Explain how many unique subarrays are there from a given array b) Describe your ideas on how to solve the problem, especially how hash tables can be used to keep track of the important information c) Write the most efficient algorithm (pseudo code) to solve this problem with complexity analysis. You can assume that a good hash function is given.arrow_forwardA hash-map has been constructed with quadratic-hashing. The hashing function is h(k;) = (3 * k; + 7) mod 17 and the table length is N = 17. How many cells will be probed by the call of insert(2) 1 4 5 6 7 8 10 11 12 13 14 15 16 26 89 11 35 70 59 Note: First row contains the indices and the second row contains the items.arrow_forward
- 3. Implement quadratic probing, double hashing, and linear probing. Compare them with two criteria: 1) number of collisions, 2) average probe length (probe length: how many tries to find an empty slot; average probe length: total probe length divided by total number of items in the hash table. Summarize the comparison into a table or a plotarrow_forwardwrite a simple hashing function that uses addition and multiplication and then find a pair of strings that will return the same hash value for different strings (i.e you will cause a Hash Collision). The algorithm uses multiplication based on the position of a letter in the hash to avoid a hash collision when two letters are transposed like in 'ABCDE' and 'ABDCE'. Your strings need to be at least three characters long and no more than 10 characters long. Here is the code that computes your hash: while True: txt = input("Enter a string: ") if len(txt) < 1 : break hv = 0 pos = 0 for let in txt: pos = ( pos % 2 ) + 1 hv = (hv + (pos * ord(let))) % 1000000 print(let, pos, ord(let), hv) print(hv, txt) For simplicity we will only use upper and lower case ASCII letters in our text strings. Enter a string: ABCDE A 1 65 65 B 2 66 197 C 1 67 264 D 2 68 400 E 1 69 469 469 ABCDE Enter a string: BACDE B 1 66 66 A 2 65 196 C 1 67 263 D 2 68 399 E 1 69 468 468 BACDEarrow_forwardI am trying to implement a hash table of key-value pairs, where the key determines the location of the pair in the hash table, the key is what the hash function is used on. The hash table that I am trying to implement will use separate chaining (with unordered linked lists) for collision resolution. I need help changing the code where: 1. The "search" method of the code returns the node that was found or "None" 2. The "Node" implementation has a "key" and "value" member This is what I have so far class Node: def __init__(self,initdata): self.data = initdata self.next = None def getData(self): return self.data def getNext(self): return self.next def setData(self,newdata): self.data = newdata def setNext(self,newnext): self.next = newnext class UnorderedList: def __init__(self): self.head = None def isEmpty(self): return self.head == None def add(self,item): temp = Node(item) temp.setNext(self.head)…arrow_forward
- Cuckoo hashing. Develop a symbol-table implementation that maintains twohash tables and two hash functions. Any given key is in one of the tables, but not both. When inserting a new key, hash to one of the tables; if the table position is occupied, replace that key with the new key and hash the old key into the other table (again kicking out a key that might reside there). If this process cycles, restart. Keep the tables less than half full. This method uses a constant number of equality tests in the worst case for search (trivial) and amortized constant time for insert.arrow_forwardImplement a commonly used hash table in a program that handles collision using linear probing. Using (K mod 13) as the hash function, store the following elements in the table: {1, 5, 21, 26, 39, 14, 15, 16, 17, 18, 19, 20, 111, 145, 146}. Use c++arrow_forwardTwo elements with identical keys should have the same hash code. Group of answer choices True False Using an unsorted array to implement a map would allow an O(log2N) get operation (where N is the number of elements in the map). Group of answer choices True False A typical hash function often consists of the following three steps: Group of answer choices hashing, compressing, and indexing. multiplication, addition, and modularization. selecting, digitizing, and combining. modularization, probing, and indexing. compressing, hashing, and probing. Clustering is a side effect of linear probing. Group of answer choices True Falsearrow_forward
- 3. Double hashing is one of the methods to resolve collision. Write a function to implement this method. The equations used in this method are given below. Note: implement everything within the double hash function. P = (P + INCREMENT(Key)) mod TABLE_SIZE INCREMENT(Key) = 1 + (Key mod INCR)arrow_forwardAssume an open addressing hash table implementation, where the size of the array is N = 19, and that double hashing is performed for collision handling. The second hash function is defined as: d(k) = q -k mod q, where k is the key being inserted in the table and the prime number q is = 7. Use simple modular operation (k mod N) for the first hash function. i) Show the content of the table after performing the following operations, in order:put(45), put(25), put(12), put(61), put(38), put(88), remove(12), put(39), remove(61), put(18), put(29), put(29), put(35).i) What is the size of the longest cluster caused by the above insertions? ii) What is the number of occurred collisions as a result of the above operations? iii) What is the current value of the table’s load factor?arrow_forwardProblem 5 ( ,. Suppose that your hash function resolves collisions using open addressing with double hashing, which we discussed in the class. The double hashing method uses two hash functions h and h'. Assume that the table size N = 13, h(k) = k mod 13, h '(k) = 1 + (k mod 11), and the current content of the hash table is: 0 1 2 3 4 5 6 7 8 9 10 11 12 28 98 59 22 43 51 If you insert k = 15 to this hash table, where will it be placed in the hash table? You must describe, step by step, how the location of the key is determined.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education