Skip to content

Commit 2670079

Browse files
committed
Tree center slides
1 parent 6c34da1 commit 2670079

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

slides/graphtheory/trees.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,25 +473,33 @@ Our approach to finding the center or centers of a tree is going to be to
473473
repeatedly remove the outer layer of leaf nodes. This process resembles that of
474474
peeling an onion, you start outside in.
475475

476-
For this tree, we first identify all the leaf nodes.
476+
The first thing we're going to do it compute the degree of each node, that is
477+
the number of node's it's connected to. You'll notice that each leaf node will
478+
have a degree of 1 since leaf nodes can only be connected to one other node.
477479

478-
Then we prune them.
480+
For this tree, the leaf nodes are those in red.
481+
482+
Once we know what the leaf nodes are we can prune them and update the degree
483+
of each of the nodes.
479484

480485
After that, repeat the same process. Find identify the leaf nodes.
481486

482-
And prune them.
487+
Prune them and update the degree values.
483488

484489
If you keep doing this you'll eventually reach the center of the tree.
485490

486-
Let's do another example
491+
It's a simple concept, let's do another example. Feel free to pause the video
492+
and find the center yourself using the algorithm I just described.
493+
494+
First compute all the node degree values.
487495

488-
Identify all the leaf nodes.
496+
Identify all the leaf nodes with a degree of 1
489497

490-
Prune them
498+
Prune them, and update the degree values.
491499

492-
Find the new set of leaf nodes, these are all the nodes with 1 alive child.
500+
Find the new set of leaf nodes, these are all the nodes with a degree of 1.
493501

494-
Then prune them.
502+
Then prune them, and update the degree values.
495503

496504
When you're left with either 1 or 2 nodes you've found the center or centers.
497505

slides/graphtheory/trees_slides.key

214 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)