Skip to content

Commit 0c97687

Browse files
committed
tree slides
1 parent dcf94d6 commit 0c97687

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

slides/graphtheory/trees.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ The build tree takes exactly three parameters we just talked about: the graph, t
263263

264264
Next we enter a for loop that loops over all the neighbors of the current node, which in turn will become the children of the current node.
265265

266-
Because edges are undirected in the original tree, we absolutely need to avoid a situation where we add a directed edge pointing back to the parent.
266+
Because edges are undirected in the original tree, we absolutely need to avoid a situation where we add a directed edge pointing back to the current node's parent.
267267

268-
So if the parent is null, meaning we're dealing with the root node.
268+
First check that the parent is not null so we don't get a null pointer exception when trying to access the parent's id.
269269

270-
Or the child id is equal to the parent id skip this node.
270+
then check that the child id is equal to the parent id and skip this node if true.
271271

272272
Otherwise we're dealing with a proper child node, so create a new node and add the child tree node to the list of the current node's children
273273

slides/graphtheory/trees_slides.key

-1.27 KB
Binary file not shown.

0 commit comments

Comments
 (0)