From the course: Python Data Structures: Trees

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Deleting nodes: Theory

Deleting nodes: Theory - Python Tutorial

From the course: Python Data Structures: Trees

Start my 1-month free trial

Deleting nodes: Theory

- [Instructor] Deletion from a tree like insertion starts with searching the tree based on a target value. If the value is not found, we return without doing anything we don't make any changes to the tree but if we do find the target value, we have to remove it but we can't just, you know, take it out or any children that has, might go floating off into space. So we have to be careful. There are three cases to consider for deletion. Zero children, one child and two children. Remember, according to the Computer Scientists all problems are caused by children. In the case of zero children like this 25 we just remove the link to the parent node. The node gets deleted and we're all good. That's it. In this case, the node to be deleted has one child like the 75 here. Here, the child becomes the parent just like I'm turning into my mother. So we take this hundred, move it up. This link becomes a link to 100 now…

Contents