Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 14.3, Problem 6E
Program Plan Intro
To maintain a dynamic set Q of numbers that supports the operation MIN-GAP that gives the magnitude of difference of the two closest numbers in Q.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
If we can assume that the keys in the list have been arranged in order (forexample, numerical or alphabetical order), then we can terminate unsuccessfulsearches more quickly. If the smallest keys come first, then we can terminatethe search as soon as a key greater than or equal to the target key has beenfound. If we assume that it is equally likely that a target key not in the list is inany one of the n + 1 intervals (before the first key, between a pair of successivekeys, or after the last key), then what is the average number of comparisonsfor unsuccessful search in this version?
Consider an initially empty hash table, with an initial size of two buckets, and a load factor threshold of 0.725. After inserting the values 27, 13, 11, 47, 35, and 19 in that order, using big-oh notation, give the average-case time to search for a number between 10 and 50, and the worst-case for the same search. You may assume that the size of the hash table is doubled when necessary.
public int hashCode( int k ) {
int h = k * 3 - 2;
return h % this.size();
}
Problem 2: In this problem we assume that h: U → {0, 1, . . . , m − 1} is a good hashfunction, that is, every key k has the same probability 1/m to map to any place in the tableT of length m.(i) What is the probability that three pairwise distinct elements u1, u2, u3 ∈ U aremapped by the function h to the same place in the table (that is, h(u1) = h(u2) =h(u3))?(ii) We insert three elements into an empty hash table T using the hash function h. Ifcollision is solved by chaining, what is the probability that T[0] and T[1] are empty?
Knowledge Booster
Similar questions
- Hey, Given is a hash table with an initial size of 1000 and a hash function that ensures ahashing, where the keys are chosen randomly under the uniformity assumption.me are chosen. After how many insertions do you have to expect a collision probability of more than 80%?of more than 80%?To keep the number of collisions low during hashing, one can reduce the size of the has-hash table after a certain number of insertions. After which number n of inserted elements must the table be increased for the first time, if no collision occurred in the previous n - 1 elements and the probability of a collision in the n-th insertion should be less than 20%?arrow_forwardShow, in the style of the trace given with the code, how the entropy-optimal sort first partitions the array B A B A B A B A C A D A B R A Use the form to answer the question as same on the picture. lt i gt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 B A B A B A B A C A D A B R A.arrow_forwardSuppose we use a hash function h to hash n distinct keys into an array T oflength m. Assuming simple uniform hashing, what is the expected number ofcollisions? More precisely, what is the expected cardinality of ffk; lg W k ¤ l andh.k/ D h.l/g?arrow_forward
- Suppose we have a hash map that uses the standard “mod” hash function shown in the chapter and uses linear probing for collision resolution. The starting hash table length is 5, and the table chooses to rehash to twice its former size once the load factor reaches or exceeds 0.5. If we begin with an empty map, what will be the final state of the hash table after the following key/value pairs are added and removed? Draw the entire array and the contents of each index, including any resizing and rehashing necessary. Write “X” in any index in which an element is removed and not replaced by another element. Also write the size, capacity, and load factor of the final hash table. HashMap<Integer, String> map = new HashMap<Integer, String>(); map.put(7, "Jessica"); map.put(34, "Tyler"); map.put(17, "Ryan"); map.put(15, "Tina"); map.put(84, "Saptarshi"); map.remove("Tyler"); map.put(7, "Meghan"); map.put(33, "Kona"); map.remove(17); map.put(6, "Tina"); map.remove(84); map.put(15,…arrow_forwardLet S be the set consisting of all 10 digits and all upper- and lowercase letters. Let U be the set of all (ordered) strings consisting of exactly four elements from S. Construct an injective hash function h: U -> N with the smallest possible value of maxUh(u). Modify your hash function to give a simply uniform map h' to the set {0, ..., 30}. In other words, if U is a probability space with P(u) = P(u') for all u, u' in U, then the random variable h': U -> {0, ..., 30} should have a uniform distribution..arrow_forwardIt is straightforward and efficient to compute the union of two sets using Boolean values. We may create a new union set by Oring the matching items of the two BitArrays since the union of two sets is a combination of the members of both sets. At other words, if the value in the corresponding place of either BitArray is True, a member is added to the new set.Computing the intersection of two sets is analogous to computing the union, except that the And operator is used instead of the Or operator Using the same technique we used to detect the difference, we can determine if one set is a subset of another. For example, if:setA(index) && !(setB(index))evaluates to False then setA is not a subset of setB.The BitArray Set ImplementationWrite The code for a CSet class based on a BitArray.arrow_forward
- What is the worst-case performance of a lookup operation in a hashmap and why? Group of answer choices A- O(1), hashmap always has a constant time lookup, and that is why we like using this associative data structure. B- O(lg(n)) hashmap has a log(n) lookup because we are able to perform a binary search on the keys because our hashmap always maintains a sorted order of entries added. C- O(n) because we can have a bad hash function that puts all of our items in the same bucket, thus we would have to iterate through all n items.arrow_forward#. Consider a hash table of size 11 with hash function h(x) = x mod 11.Draw both hash tables (Closed-Bucket and Open-Bucket) that results after inserting, in the given order, the following values: 45, 12, 35, 67, 25, 52, 88, 70, 68, 53, 55arrow_forwardNote: Your solution should have O(n) time complexity, where n is the number of elements in l, and O(1) additional space complexity, since this is what you would be asked to accomplish in an interview. Given a linked list l, reverse its nodes k at a time and return the modified list. k is a positive integer that is less than or equal to the length of l. If the number of nodes in the linked list is not a multiple of k, then the nodes that are left out at the end should remain as-is. You may not alter the values in the nodes - only the nodes themselves can be changed.arrow_forward
- QuickSort is run for an array A in a manner that PARTITION consistently produces a 5:1 split for the (sub)arrays to be sorted (recursively) next. Picture the recurrence tree for this scenario ... What will be the length of the longest path from the root to a leaf (= deepest depth)in this tree? Group of answer choices log_5/6 (n) ... "log of n with base 5/6" log_6/5 (n) ... "log of n with base 6/5" log_6 (n) ... "log n with base 6" n^log_5(6) ... "n to the power of log_5(6)"arrow_forwardConsider a open bucket hash table and closed bucket hash table in which the keys are student identifiers (strings of 6 digits). Assume the following number of buckets and hash function: m = 100; hash(id) = first two digits of id #. Starting with an empty hash table, show the effect of successively adding the following student identifiers: 000014, 990021, 990019, 970036, 000015, 970012, 970023. Use following function as second hash function hash(id) = last digit of id # Show the effect of deleting 000014 from the hash table. (Java Programming DSA)arrow_forwardGiven:• a hash function: h(x) = | 3x + 1 | mod M• bucket array of capacity 'N'• set of objects with the folloeing keys: 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, 5 (to input from left to right) 1. What would be the hash table where M=N=11 and collisions are taken care of using linear probing? 2. What would be the hash table where M=N=11 and collisions are taken care of using separate chaining? 3. Would a size N for the bucket array be able to exist, so that no collisions happen with thehash function h(x) = | 2x + 5 | mod 11 and the keys above?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