Tree and Graph Data Structures

Search & Personal Recommendations

Tree and Graph Data Structures

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

The "Search & Personal Recommendations" 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 two ways to search a graph, by exploring depth first and by exploring breadth first, and explains how this will allow for personal recommendations.

Preview
Close

Transcript from the "Search & Personal Recommendations" Lesson

[00:00:00]
>> Bianca Gandolfo: Remember, we're trying to make recommendations, remember that?
>> Speaker 2: [LAUGH]
>> Bianca Gandolfo: Yeah. So, the reason for all of that, the reason we created this graph data structure is because wanted to model our data better for our recommendation engine, right? So, we built the data structure, now we need to do some work with it, right?

[00:00:21]
So, here is our graph from before, except with the people in it. So, before we just showed the relationship between the foods. And that's useful if you want to kinda get these general recommendations. But I want personalized recommendations, something that isn't already on my list, necessarily like I wanna try something new.

[00:00:45]
So, if I have myself in the graph, I can check if I already like that or not. So this would be a personalized recommendation, while the other one without the people would be sort of like a generalized recommendation in general people who like bread, might also like tea kinda thing.

[00:01:04]
So that's the difference.
>> Bianca Gandolfo: So to do that, right, so if I wanna know what my friends are eating for breakfast, I would need to search my graph until I find a shared preference with a friend. So me and my friend, we both like tea. The next thing I wanna do is find something that she likes that I don't already like.

[00:01:26]
So, coffee, I already like that, so I'm not interested in that. I'd much rather try something new. Not true, usually I just drink coffee. But in this case, eggs, right? So you understand how this works? And this isn't like two different from how recommendation algorithms actually work. So it's more or less like this, with like huge amounts of data.

[00:01:51]
So, all right. Traversing, that's what we're doing next. So we traversed the tree earlier. Now we're gonna traverse a graph. Yeah? All right. So, we have two different searching algorithms that we use to explore graphs and also trees. We have depth first search and breadth first search, and they are going to look at every single note in the tree or graph, except approach it in a slightly different way.

[00:02:31]
And because of that, they're optimize for different use cases, and you will see. So, here is our tree, you can imagine that it has our recommendation stuff in there. But let's look at numbers. So, the way that we visit the graph for depth for research is gonna be starting with one node.

[00:02:55]
Again, if we're in a graph, this is not necessarily your root node. You just chose a node, right? And then you keep exploring down further, further, further. And then you come up and go deep. This is why it's called depth for search because it's gonna all the way down to the last child, last unexplored child and then come back and then go deep again.

[00:03:20]
While breadth for search, searches things in layers. So we start here and then it's gonna go straight across, straight across, straight across.
>> Bianca Gandolfo: Cool. What do you think breadth first search would be better for?
>> Speaker 3: You may hit a node earlier as you are zoning for this part.

[00:03:48]
>> Bianca Gandolfo: Yeah, so, if you want to see the shortest path to something, breath for search is a good algorithm.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now