Midterm
Individual interview questions.
Describe 3 approaches to design a data type that can:
- Add words.
- Return a list of all the unique words in alphabetical order.
- Return the number of times a given word has been added.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the total number of words. If helpful, you can choose your own variable to describe the number of unique words.
Describe 3 approaches to design a data type that can:
- Add “observed” words.
- Add “known” words.
- Return how many “observed” words are present in “known”.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the number of “observed” words and M is the number of “known” words.
Describe 3 approaches to design a data type that can:
- Add user reviews, where a user review has a name, a date, and a rating.
- Return the reviews that fall between a given start and end date range.
- Return the reviews by a given name.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the total number of reviews and M is the number of reviews returned by the date range query.
Describe 3 approaches to design a data type that can:
- Add numbers.
- Return the value that is closest to the median of all added values.
- Remove the value that is closest to the median of all added values.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the size of the data type.
Describe 3 approaches to design a data type that can:
- Add places, where a place consists of an (x, y) coordinate pair.
- Return the closest place to a given x coordinate.
- Return the closest place to a given y coordinate.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the size of the data type.
Describe 3 approaches to design a data type that can:
- Add numbers.
- Remove the minimum number.
- Remove the maximum number.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the size of the data type.
Describe 3 approaches to design a data type that can:
- Add an element to the front (index 0), which increases the index of every other element.
- Return the element at index i.
- Promote the element at index i to index 0.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the size of the data type.
Describe 3 approaches to design a data type that can:
- Add words.
- Return the most frequent word.
- Return the most frequent word of given length k.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the size of the data type.
Describe 3 approaches to design a data type that can:
- Add a post written by a given user.
- Undo the last post written by a given user.
- Return a list of all posts written by a given user in the order that they were added.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the number of posts and M is the number of users.
Describe 3 approaches to design a data type that can:
- Cast a vote for a candidate.
- Return the number of votes for a given candidate.
- Return the candidate with the greatest number of votes.
For your most efficient approach, give a worst-case asymptotic analysis for all methods where N is the number of votes and M is the number of candidates.