Search:
In BST, searching always start from the root. If the node you're trying to find is smaller than the root, then the program will start searching recursively on the left, vice-versa if the node you're trying to find is bigger than the root.
Insert:
When it comes to inserting new nodes, apply the same logic as searching until the new node find the correct spot to be inserted. Example: Add (64).
The logic goes like this; start from the root, 64 > 40 then it goes to the right side, 64 < 78 then it goes left, 64 > 50 then it goes on the right side. Since its empty then 64 will be inserted below 50 as its right side child.
Delete:
When deleting a certain data within a BST, firstly you have to check whether it fulfills one condition or not.
- Is it a Leaf node?
- Does it have any children?
- If the deleted notes is a leaf, just delete.
- If the deleted node is a parent or root, use either the highest value node within the left sub-tree or the lowest value from the right sub-tree. For me, I use the highest value in the left sub-tree.
Infix, Postfix, and Prefix:
Computer doesn't read functions like humans do, well for at least that is what they have told me in uni. In example we read 2+4 as is. This is called Prefix. The normal way of human interpreting mathematical functions. What computer reads are either postfix nor prefix.
Postfix:
From the word "Post", it means that the operator will be posted behind the operand. Example 2+4 will turn into 24+.
Prefix:
Prefix is just like the opposite of postfix which is the operator will be posted first then the operand. Example 2+4 will turn into +24.
Those are probably the topics I will be discussing briefly this time. Thank you for viewing and I hope it helps. Leave a comment below if you want to add or you may think I made a mistake saying things. Other than that, I will see you guys in the next post.
No comments:
Post a Comment