CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 12 (Due Fri 12-Jun, at 11:59pm)




  1. mostCommonWebsite(a []string) cs112.StringSet [15pts]
    As a busy CMU student, you notice that you're getting distracted a lot while you're trying to work and decide to put that to rest by using your internet history to track which sites you visit the most. Luckily, since you're a superstar 112 student who just learned about efficiency, you can do this analysis super fast.

    Write the function mostCommonWebsite, that takes a browser history (list of strings) such as ["google.com", "agar.io", "cs.cmu.edu/~112", "agar.io"], and returns a set of the most commonly visited sites in this list (in this case, there is only one most common site ("agar.io"), so we return {"agar.io"}). If there is more than one most common site, then return a set containing all of them. So, mostCommonWebsite(["cs.cmu.edu/~112", "agar.io", "cs.cmu.edu/~112", "google.com", "agar.io"]) returns the set {"agar.io", "cs.cmu.edu/~112"} since both occur twice. Your solution should run in O(n) where n is the length of your history.

  2. mostPopularFriend(m map[string]cs112.StringSet) string [15pts]
    Recall that friendsOfFriends(d) takes a map m like this:
    mkSet := cs112.StringSetFromSlice m := map[string]cs112.StringSet{ "fred": mkSet([]string{"wilma", "betty", "barney"}) "wilma": mkSet([]string{"fred", "betty", "dino"}) }
    With this in mind, write the function mostPopularFriend(m map[string]cs112.StringSet) string that takes a dictionary of that form, and returns the name that occurs the most number of times in all the sets of friends. In the example above, mostPopularFriend would return "betty". You may assume that there is exactly one such name, so ignore ties.