<img alt=”6 Problem 6: extra credit I have a set S of n numbers, all in the universe U [1 264]. I want to build a static dictionary for this set – no insertions or deletions. But I want to make sure that searching in this dictionary is always fast, not just fast in expectation. In particular, I want to design a dictionary with the following properties ·Build-Dictionary(S) should take O(n) time in expectation Dictionary.search(key k) should always take O(1) time – no expectation here . I am ok with using O(n2) space for my dictionary Write pseudocode for an algorithm that satisfies the 3 conditions above You can assume that for any t vou can construct a universal hash function h : U → [1 t] in just 0(1) time. Make sure to analyze your algorithm, and in particular to argue why search is worst-case O(1), and Build-Dictionary is expected O(n) HINT 1: it will not be enough to pick a single universal hash function h, because you might get unlucky and have a lot of collisions. You will thus want to use an approach similar to the select algorithm in class, and keep picking a universal function until you find a good one HINT 2: Say you have a random variable X that takes some non-negative integer value, and you know that E[X]

6 Problem 6: extra credit I have a set S of n numbers, all in the universe U [1 264]. I want to build a static dictionary for this set – no insertions or deletions. But I want to make sure that searching in this dictionary is always fast, not just fast in expectation. In particular, I want to design a dictionary with the following properties ·Build-Dictionary(S) should take O(n) time in expectation Dictionary.search(key k) should always take O(1) time – no expectation here . I am ok with using O(n2) space for my dictionary Write pseudocode for an algorithm that satisfies the 3 conditions above You can assume that for any t vou can construct a universal hash function h : U → [1 t] in just 0(1) time. Make sure to analyze your algorithm, and in particular to argue why search is worst-case O(1), and Build-Dictionary is expected O(n) HINT 1: it will not be enough to pick a single universal hash function h, because you might get unlucky and have a lot of collisions. You will thus want to use an approach similar to the select algorithm in class, and keep picking a universal function until you find a good one HINT 2: Say you have a random variable X that takes some non-negative integer value, and you know that E[X]



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *