Suppose we want to create an address book which contains names, phone numbers, e
ID: 3826988 • Letter: S
Question
Suppose we want to create an address book which contains names, phone numbers, emails, and other personal information. In the questions below, give support to your answers based on the typical operations (for example, finding a person by his/her email) you might use. Explain why the algorithm and/or data structure you use gives a good tradeoff between memory use and runtime complexity. Some of the questions below could require nested data structures (for example, a Map which has values that are Sets).
a) Which data structures should you use for the address book in general to store the class Person? Give reasoning for your answer.
b) Suppose you have friends who live in various different cities. What data structure could be useful to find these friends efficiently. You can suppose that each friend has a city field associated with them. Give reasoning to your answer. Think about search engines for this question.
c) Suppose you want to check that there are no people with the same email address. Which algorithm(s)/data structure(s) might you use to do this? Give reasoning for your answer.
d) Suppose in you know which of the people in you address book are friends which each other. Now suppose you take yourself out of the graph. Which algorithm(s)/data structure(s) would help you determine the number of unrelated groups of friends you have? Give reasoning for your answer.
e) Suppose you want to list your friends who have March birthdays in order of date. What algorithm(s)/data structure(s) whould you use to accomplish this. You may assume that you have a birthday field which has a Date class that contains date and month member variables. Declare any other assumptions you make and give reasoning for your answer.
Explanation / Answer
Answer:
Data structures are the most efficient and effective kind of structures which are used for accessing and retrieving the data with the least response time using primary key present in the database and through which we can retrieve the whole information of that data.
a) We wil use "Hash Map" as a data structure for the address book to store the class person as hash map uses two things:
1. Key
2. Value
With the help of key we can easily store and access the value in address book.
b) We will use "Relational DBMS" as a structure by creating a table which consists of tuples friends id, friend city etc. and by creating a query and specifying the condition of city like
where city="xyz";
and through this we can easily retrieve the names of friends living in that particular city.
3) We will use "Select distinct" statement in relational dbms which gives distinct values of that particular attribute and by using the key corresponding to that particular value we can check wether two persons have same email id or not.
5) Since we want to know the list of friend's whose birthday lies in march in terms of order by date so we will use the data structure called as sql query by specifying that:
select friend's name from friend's
where friend.birthmonth="march" and order by birthdate;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.