CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 12 (Due Fri 12-Jun, at 11:59pm)
- This assignment is COLLABORATIVE. This means you may work with your week's collaboration group within the course collaboration boundaries. See the syllabus for details.
- To start:
- Create a folder named 'collab12'
- Download collab12.go
- Edit collab12.go using VSCode
- When you are ready, submit collab12.go to Autolab. For this collab, you may submit up to 10 times, but only your last submission counts.
- Do not hardcode the test cases in your solutions.
- NOTE: For the next few days, assignments in Go will be manually graded.
- 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. - 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 functionmostPopularFriend(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.