[SOUND] All right, in this support video, we're gonna write some code.

Mia has talked to you about two ways of representing a graph,

using an adjacency list, and using an adjacency matrix.

And she's also talked to you about the out degree of the vertices in a graph.

So, in this video what we're going to do is we're actually going to write a method

where we get all of the nodes that are one degree one hop away

from a particular node in the graph.

And we'll be writing this code for

both an adjacency matrix as well as an adjacency list representation.

So, by the end of this video, you'll be able to write this code.

We're gonna do it together.

Not actually in Eclipse.

We're just gonna write it out on these slides.

And the reason I'm choosing to write by hand, rather than write in the code in

Eclipse is that sometimes when you're writing on paper, or on a tablet computer.

You're a little bit more thoughtful about what it is that you're doing.

Because you're not able to run the code and test it.

So, that's why I'm gonna show you this code written out on a tablet.

All right, so lets review the Adjacency Matrix Representation for the graph.

As you may recall there's a row for every vertex in the graph, so

these rows correspond to vertices 1, 2, 3, 4 and 5.

5 and then, in each row there's a 0 in the entry if there's no edge from that vertex

to the vertex represented by the column, and there's a 1 if there is an edge.

So for example, if we look at this edge right here,

we can find that 1 for that edge in row 2.

Go over here to entry 3 and there's our edge.

There's a 1 there.

And 2 doesn't have edges anywhere else, so there are no other 1's in 2's realm.

So, we're going to use this information to write the get neighbors method

in our graph representation.

So, we've got the start of our graph representation there on the screen,

we've got our matrix representing the edges in the graph.

And our goal now is to write get neighbors.

So, let's go on and actually do the writing.

Although before we do, let's actually go back for one second and look at this graph

and think about, how can we tell what nodes are neighbors of a particular node.

Well, all we really need to do is we need to look at the row.

So, we just look at this row right here, and if there's a 0 in that entry, then,

it's not a neighbor.

But if there's a one in the entry, then it is a neighbor, and that's the essence of

the algorithm that we're going to use to implement in our method.

So, here's the header for our gate neighbor's method.

We're going to return a list of integers, and

that list of integers is going to contain all the vertex integers

that our neighbors of the particular node that we pass in.

So, we're taking an int v, which is a vertex in our graph, we're gonna return

the integers representing all the neighbors of that vertex.

So, let's get started.

Well, what's the first thing that we need?

We need to return a list, so we're going to need to have a list to return.

So, let's go ahead and create that list.