Professional Documents
Culture Documents
1
Table of Contents
1) History and definition ……………………………………………… 3
2.2 Insertion……………………………………………………………………………........ 5
2.3 Deletion………………………………………………………………………………… 6
2.4 Modify………………………………………………………………………………….... 7
2.5 Search…………………………………………………………………………………… 8
3) Applications…………………………………………………………. 9
4) References…………………………………………………………….10
2
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
A binary search tree, like Linked Lists, is a data structure made up of nodes. These nodes are either
empty or contain connections to other nodes (links). These other nodes are called a left node and a
right node, respectively. Values are assigned to nodes. These numbers decide where they'll get into
the BST(binary search tree).Each node is referenced by only one other node, its parent, similar to a
linked list (except for the root node). As a result, we can assume that each node in a BST is a BST
in and of itself. We meet another node further down the tree, and that node has a left and a right.
The node then has a left and a right depending on which way we go, and so on. The size of the left
node is often smaller than the size of its parent, the right node still exceeds the number the parent.,
A BST is called balanced if, with the exception of the last level, every level of the tree is completely
filled. The tree is filled from left to right on the final stage. A perfect BST is both full and complete
(all child nodes are on the same level, and each node has a left node).
3
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
The creation of binary search tree takes O (log n) time to complexity. Binary search algorithm often
operates on a sorted list. As a result, the first logical step is to sort the given list. After sorting, the
list's median is compared to the desired value.
• If the desired value is equal to the value of the central index, the index is returned as a response.
• If the target value is less than the list's central index contract, then the right side of the list is
ignored.
• If the optimal value exceeds the value of the central index, the left half is discarded.
• After that, the procedure is replicated on shorter lists until the goal value is discovered.
4
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
• Step 1 - Create a new Node with given value and set its left and right to NULL.
• Step 2 - Check whether tree is Empty.
• Step 3 - If the tree is Empty, then set root to new Node.
• Step 4 - If the tree is Not Empty, then check whether the value of new Node
is smaller or larger than the node (here it is root node).
• Step 5 - If new Node is smaller than or equal to the node then move to its left child. If
new Node is larger than the node then moves to its right child.
• Step 6- Repeat the above steps until we reach to the leaf node (i.e., reaches to NULL).
• Step 7 - After reaching the leaf node, insert the new Node as left child if the new Node
is smaller or equal to that leaf node or else insert it as right child.
5
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
2.3 Modify
To begin building a tree, we must first construct a new form of node with left and right properties.
This node object is similar to the node objects that are found in lists. The only difference is that
instead of one connection, the new node object has two. It always has a value, and the same getters
and setters are used to control its values.
We can use a Tree node to build a BST object once we've implemented it. An operation to insert
values and an operation to delete values are the two key operations we want to implement for our
BST object. We can quickly expand the systems to add more later once we have these two
operations.
BST object will only have one resource, which will be the tree's base. All other values within the
tree can be determined by iterating the root at any time. Recursion is used to enforce the insert
process, as it is with almost every tree method. Let's look at an example to get a better understanding
of what we need to do with our insert process.
6
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
In a binary search tree, the deletion operation is performed with O (log n) time complexity. Deleting
a node from Binary search tree includes following three cases...
We use the following steps to delete a node with one child from BST...
We use the following steps to delete a node with two children from BST...
7
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
8
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Camp
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
3) Applications of BST
BSTs are used for a lot of applications due to its ordered structure.
9
Arab Academy for Science, Technology & Maritime Transport
College of Artificial Intelligence ━━━━━ Alamein Campus
Course code GN121 Data Structures & Algorithms April 2021
Lecturer Prof. Dr. Osama Ismail
Teaching assistant Nagy Khairat Aly
4) References
• https://link.springer.com/content/pdf/10.1007/BF02579253.pdf
• https://afteracademy.com/blog/binary-search-tree-introduction-operations-and-
applications
• https://www.freecodecamp.org/news/data-structures-101-binary-search-tree-
398267b6bff0/
• https://www.upgrad.com/blog/binary-search-
algorithm/#:~:text=Learning%2C%200%25%20EMI-
,Time%20and%20Space%20complexity,values%20not%20in%20the%20list.
10