Transcript from the "Depth-First Search with a Tree Solution" Lesson
>> Bianca Gandolfo: What do you remember about depth first search with a tree, and how is it different? Let's compare just for fun.
>> Speaker 2: You don't have to keep track of where you've visited.
>> Bianca Gandolfo: Let's go,
>> Bianca Gandolfo: Why don't we have to keep track of where we've visted in the tree?
>> Speaker 3: Cuz you don't have to worry about the pads.
>> Bianca Gandolfo: Yeah, cuz here's our tree one.
>> Bianca Gandolfo: So for a tree, in this case we're not keeping track of our depth. We could do that though if we wanted in a similar way. What we're doing this for each here.
[00:01:05] The main difference is we have those for each. This for each is gonna check if it's visited. This tree we don't.
>> Bianca Gandolfo: And what's the reason again? I said it but then suddenly forgot.
>> Bianca Gandolfo: Why? What happens--what's the difference between a tree and a graph? The main difference?
>> Speaker 3: A graph can have cyclical paths.
>> Bianca Gandolfo: Yeah, and so what would happen if we didn't check, if we visited and we had a cycle?
>> Speaker 2: Infinite loop.
>> Bianca Gandolfo: We'd have an infinite loop. And so we have this catch that's saying okay, if this has been visited we're not gonna keep traversing, and recursing into that every time.
[00:02:06] Cool? Great.
>> Bianca Gandolfo: All right. Any questions?
>> Bianca Gandolfo: So, there was a question online about passing this to for each. For each takes a second parameter. And that's just setting the context so that you don't lose the value of this. We briefly talked about this being kind of finicky and there's certain rules.
[00:02:39] And how we can't explicitly set it inside of the body of the function except for using call and apply or using the keyword new. Or what else did we say? Just calling it to the left of the dot, etcetera. And then some functions take that into consideration in their implementation like for each to make sure that you're able to explicitly set what this is, so that you don't lose your context.