This course has been updated! We now recommend you take the Complete Intro to Computer Science course.

Check out a free preview of the full Four Semesters of Computer Science in 5 Hours, Part 2 course:
The "Graphs Exercise" Lesson is part of the full, Four Semesters of Computer Science in 5 Hours, Part 2 course featured in this preview video. Here's what you'd learn in this lesson:

Find the most common job in your social graph.

Get Unlimited Access Now

Transcript from the "Graphs Exercise" Lesson

>> Brian Holt: So we're gonna have you do exactly what I was talking about which is to find the most common job in your job network or your follower network.
>> Brian Holt: So I'm gonna give you a function called findMostCommonTitle. Excuse me, [COUGH] give you function called findMostCommonTitle. It's gonna take in some ID.

[00:00:27] This is gonna be a getUser function that you give it an ID, and it's gonna give you back a user.
>> Brian Holt: And then how many degrees of separation I want you to go away from the user.
>> Brian Holt: So just to show you where the data is actually coming from, it's just a different code pen that I abstracted out.

[00:00:47] But I can show you what it looks like, and if you wanna look at it, feel free to.
>> Brian Holt: It's just this huge list. I think it's a thousand users that I put in here.
>> Brian Holt: Yeah.
>> Brian Holt: So 0, or no, it's 1 to 1,000.
>> Brian Holt: And you'll see here that it'll have a name.

[00:01:11] By the way, these are all totally randomly generated, so if there's something unsavory in there, I apologize. [LAUGH] Company which you can just ignore. The title which is what I want you to find the most common title within these degrees of separation. And then it's going to have connections.

[00:01:30] And this is going to be one to ten people that this person is connected to, right? There might be duplicates in here because again it was randomly generated and I did not check. [LAUGH] But that shouldn't matter, right? Because we shouldn't be checking a person once anyway.
>> Brian Holt: But so that getUser if you give 987 it's going to return to this particular person, right?

[00:01:56] So that's how that is working-
>> Brian Holt: Behind the scenes. So that's what that getUser function here does. So you give it a number and it gives you that back.
>> Brian Holt: So yeah, degrees of separation, if I give you two then you should check your connections and your connection's connections.

[00:02:16] Three, you should check all those. [COUGH] So you do two degrees of separation. I also made sure that there was one answer to these, right? So in this particular case you don't have to worry about if there's equal. There is one correct answer to each one of these.

>> Brian Holt: And then down here at the bottom, for extra credit, if you do seven degrees of separation, you will get everyone in this social network except five people that are not connected, which is #sad. But I'm sure they're fine.
>> Brian Holt: Okay, so let's give you maybe 30 minutes, and then we'll regroup and go through these together.