@@ -473,25 +473,33 @@ Our approach to finding the center or centers of a tree is going to be to
473
473
repeatedly remove the outer layer of leaf nodes. This process resembles that of
474
474
peeling an onion, you start outside in.
475
475
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.
477
479
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.
479
484
480
485
After that, repeat the same process. Find identify the leaf nodes.
481
486
482
- And prune them.
487
+ Prune them and update the degree values .
483
488
484
489
If you keep doing this you'll eventually reach the center of the tree.
485
490
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.
487
495
488
- Identify all the leaf nodes.
496
+ Identify all the leaf nodes with a degree of 1
489
497
490
- Prune them
498
+ Prune them, and update the degree values.
491
499
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 .
493
501
494
- Then prune them.
502
+ Then prune them, and update the degree values .
495
503
496
504
When you're left with either 1 or 2 nodes you've found the center or centers.
497
505
0 commit comments