
Title:
Popularity  Intro to Computer Science

Description:

So here's a typical group of friends in middle

school. And some of the people are popular, some of

them might not be. The first step to deciding

who's popular, is looking at who has a lot of

friends. So let's draw in some links, that show

who's a friend. And friendship links are one directional. Just

because Alice's friends with Bob, doesn't mean that Bob

is friend with Alice. So we'll draw our links as

arrows, so this means this person, we'll call him Bob, is

friends with Alice. And let's say, Alice

has many friends. And let's say Bob is also friends with

this person, they're friends with each other.

We have lots of friendship links. Some

of them are bidirectional but not all of them. So, we have lots of friendships.

So, is this enough to decide who's popular. So, if you

went to a school like I did, it's not. Just having a

lot of friends is not enough to make you popular, you

have to have the right friends. You have to be friends with

the popular people. So, it's not enough to have lots of

geeky friends say in high school, you've gotta have lots of friends

that are popular. So that means the definition of popular, isn't

just about having lots of friends, it's about having lots of friends,

who also have lots of friends. That's what

make some one popular, so we can define

popularity of a person is the number of

people who are friends with p. This means

the number of links from someone else to

that person is their popularity score. So here

is Charlie, so there are one, two, three

links into Charlie, so Charlie's popularity score would

be three. Alice also has three links, so her

popularity score would also be three. Bob only has one

arrow going to Bob, so his popularity score would be

one. So, this isn't a bad way to define popularity,

but it's not quite right. So, the definition of popularity

doesn't just depend on the number of friends you have,

it depends on, both, the number, and the popularity of

your friends. So, we can change the definition. Let's instead

define the popularity score of a person p. Now

it's going to be the sum of the popularities of

all of their friends. So we can write that in

a mathematical way, so using the sigma means to sum

up. We're going to take each friend, that is in

the friends of p. And we're going to sum up the

popularity score of the friends. If the mathematical notation is

unfamiliar to you, we could also write this as pseudo

Python code. We're thinking of the popularity of

a person p. Let's assume we have a

function that gives us the friends. So we're

going to start with a score of zero. We're going to

loop through the friends. And for each friend,

we're going to add to p score, the popularity score

of the friend. And we'll return the score

as the result. So now, you've seen a mathematical

definition of popularity, you've seen the same thing as code. I'm going to ask

you a very important quiz question next. Its an easy one to get

right if you try it twice because there's only two answers, but think

about it carefully. See if you can get it right the first time.