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 find 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 define 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
Background image of page 1
3 Specifications You will be implementing a hash table class, named as AddressBook, all by yourself. The bare header file, “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
Background image of page 2
Show entire document

This question was asked on Jan 17, 2013.

Recently Asked Questions

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 and customizable flashcards—available anywhere, anytime.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access or to earn money with our Marketplace.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
  • -

    Flashcards

    Browse existing sets or create your own using our digital flashcard system. A simple yet effective studying tool to help you earn the grade that you want!

    Browse Flashcards