Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary search tree. Removing a node

Similar presentations


Presentation on theme: "Binary search tree. Removing a node"— Presentation transcript:

1 Binary search tree. Removing a node

2 There are three cases ◦Case 1: Node to be deleted has no children.
◦Case 2: Node to be deleted has one child. ◦Case 3: Node to be deleted has two children.

3 ◦Case 1: Node to be deleted has no children

4 ◦Case 1: Node to be deleted has no children

5 ◦Case 2: Node to be deleted has one child.

6 ◦Case 2: Node to be deleted has one child.

7 ◦Case 3: Node to be deleted has two children

8 ◦Case 3: Node to be deleted has two children

9 ◦Case 3: Node to be deleted has two children
Find minimum element in the right subtree of the node to be removed. In current example it is 19

10 ◦Case 3: Node to be deleted has two children
Replace 12 with 19. Notice, that only values are replaced, not nodes. Now we have two nodes with the same value.

11 ◦Case 3: Node to be deleted has two children
Remove 19 from the left subtree.


Download ppt "Binary search tree. Removing a node"

Similar presentations


Ads by Google