130 likes | 219 Views
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE. Using C#. Information Technology , 3’rd Semester. Data structure. Lecture 15: Trees Operations. Presented By: Mahmoud Rafeek Alfarra. Outline. Finding the Mini. & Maxi. Values
E N D
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Using C# Information Technology , 3’rd Semester Data structure Lecture 15: Trees Operations Presented By: Mahmoud Rafeek Alfarra
Outline • Finding the Mini. & Maxi. Values • Finding a Node in BST • Removing a Leaf Node From a BST • Emank X Mezank !!
Finding the Mini. Value in BST • Due to the properties of a BST, the smallest value in a BST will always be found at the last left child node of a subtree beginning with the left child of the root node. The Minimum value Presented & Prepared by: Mahmoud R. Alfarra
Finding the Mini. Value in BST Implementation IN BST 4 • Let’s look at the code for the Node class first: Presented & Prepared by: Mahmoud R. Alfarra
Finding the Maxi. Value in BST Implementation IN BST 5 • The largest value in a BST is found at the last right child node of a subtree beginning with the right child of the root node. The Minimum value Presented & Prepared by: Mahmoud R. Alfarra
Finding the Maxi. Value in BST Implementation IN BST 6 Presented & Prepared by: Mahmoud R. Alfarra
Finding a Node in BST 7 Presented & Prepared by: Mahmoud R. Alfarra
Removing Nodes 8 • For some cases, removing a node from a BST is almost trivial. • For other cases, it is quite involved and demands that we pay special care to the code we right. • Otherwise we run the risk of destroying the correct hierarchical order of the BST. Presented & Prepared by: Mahmoud R. Alfarra
Self Practice 9 • Develop an application which use a binary search tree to represent the information of students in our college. • Using this application, we should perform the following tasks: • Insert new student • Find specific student • print the information of students using (InOrder, PreOrder, PostOrder traversing techniques) • Remove some leaves. HW 1.1 Presented & Prepared by: Mahmoud R. Alfarra
Removing a Leaf Node From a BST 10 • Removing a leaf is the simplest case since there are no child nodes to take into consideration. • All we have to do is set each child node of the target node’s parent to null. • Of course, the node will still be there, but there will not be any references to the node. Presented & Prepared by: Mahmoud R. Alfarra
Removing a Leaf Node From a BST 11 Presented & Prepared by: Mahmoud R. Alfarra
Emank X Mezank !! يقول النبي صلى الله عليه وسلم: كفى بالمرء كذبـًا أن يحدثَ بكل ما سمـع
Next Lecture Removing nodes from a Binary Search Tree