Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented By: Mahmoud Rafeek Alfarra

Similar presentations


Presentation on theme: "Presented By: Mahmoud Rafeek Alfarra"— Presentation transcript:

1 Presented By: Mahmoud Rafeek Alfarra
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Data structure Using C# Information Technology , 3’rd Semester Lecture 16: Trees Operations (Removing nodes) Presented By: Mahmoud Rafeek Alfarra

2 Outline Deleting a Node With One Child
Deleting a Node With Two Children Emank X Mezank !!

3 Deleting a Node With One Child
When the node to be deleted has one child, there are four conditions we have to check for: The node’s child can be a left child; or The node’s child can be a right child; or The node to be deleted can be a left child; or The node to be deleted can be a right child. Presented & Prepared by: Mahmoud R. Alfarra

4 Deleting a Node With One Child
4 5 5 2 45 2 45 Node to be deleted 30 Node to be deleted 30 10 10 Presented & Prepared by: Mahmoud R. Alfarra

5 Deleting a Node With One Child
5 Presented & Prepared by: Mahmoud R. Alfarra

6 Deleting a Node With Two Children
6 Deletion now gets tricky when we have to delete a node with two children. If we need to delete the node marked 52.We can’t replace it with the subtree starting at the node marked 54 because 54 already has a left child. The answer to this problem is to … Presented & Prepared by: Mahmoud R. Alfarra

7 Delete (with two children)
6 2 8 1 5 3 4 6 3 8 1 5 4 delete (3) Replace data of the node (2) with the smallest data of its right subtree (3) and delete that node (3) from the right subtree

8 Deleting a Node With Two Children
8 Move the inorder successor into the place of the deleted node. Presented & Prepared by: Mahmoud R. Alfarra

9 Finding the successor 9 Presented & Prepared by: Mahmoud R. Alfarra

10 Deleting a Node With Two Children
10 We have two special cases: The successor is the right child of the node to be deleted. The successor is the left child of the node to be deleted. Presented & Prepared by: Mahmoud R. Alfarra

11 قولوا لا إله إلا الله تُفلحـوا
Emank X Mezank !! قال النبي صلى الله عليه وسلم: قولوا لا إله إلا الله تُفلحـوا

12 Next Lecture Hashing


Download ppt "Presented By: Mahmoud Rafeek Alfarra"

Similar presentations


Ads by Google