Trimming Leaves Algorithmically
When deleting a leaf in the tree, the structure of the tree does not change. If we examine the tree below, the outlined nodes can be deleted safely without changing the overall structure of the tree.
The leaves circled in red can simply be removed without modifying the existing leaf structure. Nodes that pointed to the deleted leaf node will no longer point to that node.
You thought this would be a tediously long explanation? Nope. Like I try to reiterate through my articles, simplicity is key. Don’t overthink it. Computer Science topics, especially Algorithms, can be enjoyable as long as you see the simplicity in the topics.
If you liked what you read, my book, An Illustrative Introduction to Algorithms, covers this Algorithm and many more.