View the step-by-step solution to:

# Middle East Technical University Department of Computer Engineering CENG 213 Data Structures Fall '2012-2013 Uncle Barney Due date: 6 January 2013,...

This question is related with the implementation of hashing
Middle East Technical University Department of Computer Engineering CENG 213 Data Structures Fall ’2012-2013 Uncle Barney Due date: 6 January 2013, Sunday, 23:55 1 Objective This homework is intended to help you gain the practice of implementing a hash table, along with its accompanying hash function. You will be Barney Stinson’s best nerd friend, and help him out with his problem. 2 Story Barney goes into a crowded bar. From the beginning till the end, he is surrounded by a number of mates, who leave their phone numbers for him to call. With an old-fashioned approach, he simply takes an address book with him to save the names & numbers. At the end of the night, he runs into a girl, who says “I am Brenda from downtown. Call me.” and leaves. Here is the somewhat-censored call details: - Hey Brenda, just tell me where you are so . .. - I am Brigitte, you idiot. * HANG * He soon realizes the problem. He was too drunk to properly associate the names with phone numbers on the same page, and he called the wrong person. He decides to be more careful about it, nevertheless it still takes too much time to ﬁnd a person among others. His life would have been much easier if each page included only one person. Then, Barney comes to you to design him an address book. The address book you design will be of a dynamic size which he will deﬁne each time. However, he is simply asking more than a standard book, in which each page has the names starting with the associated letter. He needs a more-complex function to map people to pages(analogous to hash table’s buckets), and to access them instantly given the person’s details. The distribution of people in the book’s pages should be as uniform as possible. For evaluation, he will take an address book of your design with him on any given night, over the course of m days. Each time, a random n number of people will give him addresses, and k people (again, random) will want him to call at the end of the night. The quality of your address book will be determined by the distribution of people to the pages, as well as average lookup time. 1
3 Speciﬁcations You will be implementing a hash table class, named as AddressBook, all by yourself. The bare header ﬁle, “AddressBook.h”, is given below. You are free to add any private variables/functions to it. However, your hash table should support at least the given functions. class AddressBook{ private: // . .. members, methods public: // Constructors & Destructor, be careful about memory leaks. AddressBook(); // Default table size is 151 buckets. // numberOfBuckets is a prime number. AddressBook(int numberOfBuckets); ~AddressBook(); // Hash a person to a non-negative integer ( return hash value, not // bucket number). Use hashValue(mod numberOfBuckets) as bucket // number. // Return -1 on invalid parameters. int hashPerson(Person& person); // Put a person to the hash table, along with the phone number. // Do nothing on invalid parameters. // Invalid phoneNumber: "" void addEntry(Person& person, string phoneNumber); // Remove the entry from the address book. // Do nothing on invalid parameters. void removeEntry(Person& person); // Get the total # of people in the given bucket. Return -1 on // invalid bucket number. int getNumberOfPeopleInBucket(int bucket); // Get phone number of a person. // Important: To add an extra flavor to your homework, your code // will be evaluated by how much time it takes to access a phone // number on the average. You will ge a small portion of your grade // depending on the average access time of your code. // For invalid parameters, return empty string. string getPhoneNumber(Person& person); }; 2
Show entire document

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents