Deletion is the least straightforward operation within a binary tree, and requires some careful maneuvering. Let’s say that we want to delete the 4 from this binary tree:
First, we perform a search to first find the 4, and then we can just delete it one step:
While that was simple, let’s say we now want to delete the 10 as well. If we delete the 10
we end up with an 11 that isn’t connected to the tree anymore. And we can’t have that, because ...
Get A Common-Sense Guide to Data Structures and Algorithms now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.