### Check out a free preview of the full Tree and Graph Data Structures course

The "Drawing a Graph" Lesson is part of the full, Tree and Graph Data Structures course featured in this preview video. Here's what you'd learn in this lesson:

Bianca introduces graphs by giving examples of what they can represent and displaying a visualization of breakfast recommendations as a graph.

### Transcript from the "Drawing a Graph" Lesson

[00:00:00]

>> Bianca Gandolfo: So we wanna have a smarter recommendation engine to power our morning routine, right? Optimal success, that's the goal. We need to have breakfast. So we need to model our data better to give us these recommendations. So the natural choice for this is gonna be a graph, right?

[00:00:21]

So we have many preferences with relationships to one another. So graphs show relationships of things to other things, right? We draw that with circles and lines, but we'll see what that looks like in code and a little bit. But first, let's take a stab at drawing a graph.

[00:00:42]

So get your paper back out, and we have three friends here. First one is me, I like coffee, toast, and tea. And we have another friend, she likes coffee, eggs, and tea. And then I have another friend, our friend, he likes coffee, iced tea, and also eggs. So let's take a stab at what this might look like, drawn out with relationships.

[00:01:16]

Just guess, it doesn't have to be right. Some things to consider is, do you want to include the people on this graph? Do you wanna exclude them?

>> Bianca Gandolfo: Yeah, I guess that's the main thing and why? So here I am, I am just putting the toast. So I just kinda changed this where I'm thinking about excluding the people.

[00:01:45]

We'll talk about like why or why not, but let's just draw out the food relationship and we'll talk about in a few minutes why or why not. We may want to exclude or include the people. So I like coffee, I also like toast. We draw a line, right?

[00:02:05]

We've been doing this for a while. If you've been taking data structures and algorithms, we put a thing, we put a thing, and we draw a line. And we draw another line, right? And we keep doing this until we have a bunch of lines connecting our nodes. Except this is a graph, so we call these vertices.

[00:02:21]

So a node in a graph, it's called a vertex, you could call it a node, but it's called a vertex. And the relationships represented by the line is called an edge, and so it's interesting. Think in your head like what that could look like in code, just think about it.

[00:02:44]

>> Speaker 2: Only coffee is connected to toast and egg and iced tea

>> Bianca Gandolfo: So what's the question exactly?

>> Speaker 2: I mean I'm just saying that information we need to put into that graph.

>> Bianca Gandolfo: Yeah, it's definitely like something we would need to store. Definitely we need to know, we've had to store the objects and then we have to store the relationships.

[00:03:09]

Yeah, but the thing about what else I wanna tell you about graphs. There's so much to say. We can just keep it like this.

>> Speaker 3: Can you add other categories? It can be food and drink or [INAUDIBLE] or?

>> Bianca Gandolfo: You could, I mean that's the cool thing actually that I should say about graphs is that is so flexible and there in lies the power, right?

[00:03:34]

Because we could put people and food in it, you can do some really cool stuff based on all of that. You can model a lot of real life things with a graph. From maps, Google Maps, totally a graph. Even modeling like in Princeton's computer science algorithms one class, they talk about this percolation.

[00:04:04]

So they model gravel, a rock in space, as a graph. And you can find the path to see how the water runs through, if it is permeable or not. So you can model, literally rocks in spaces, to see if water can run through. Also, genetics and stuff like that.

[00:04:28]

So graph theory as of subject, it's huge. There's so many things that you can do with it. Today, we'll just learn the very first things that you need to know, and then you can go online and read about all the cool stuff.

### Learn Straight from the Experts Who Shape the Modern Web

- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops