Skip to content

Commit f03cab7

Browse files
committed
edited some text
1 parent de01bac commit f03cab7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lessons/intro-bst.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,39 @@ icon: "search"
1010
A Binary Search Tree is a binary tree that additionally satisfies the binary search property.
1111

1212
### Binary Tree Property
13-
This property states that the key in each node must be greater than or equal to any key stored in the left sub-tree and less than or equal to any key stored in the right sub-tree.
13+
This property states that the key in each node must be greater than or equal to any key stored in the left sub-tree and less than or equal to any key stored in the right sub-tree.
1414

1515
![BinarySearchTree_diagram](images/BinarySearchTree_diagram.png)
1616

17-
### Operations in Binary Search Tree
17+
## Operations In BST
1818

19-
## Searching
19+
### Searching
2020
1. We begin by examining the root node. If the tree is null , the key we are searching for does not exist in the tree.
2121
2. If the key equals that of the root If the key is equal that of route the search is successful and we return the node .
2222
3. If the key is less than that of the root we search the left subtree. Similarly, if the key is greater than that of the root, we search the right subtree.
2323
4. This process is repeated until the key is found or the remaining subtree is null.
2424
5. If the search key is not found after a null subtree is reached, then the key is not present in the tree.
2525

26-
## Insertion
26+
### Insertion
2727
To insert for a key in the tree , we follow the binary search property and insert accordingly.
2828
1. Compare the key to be searched with the root key.
2929
2. If the key is lesser than the roots value, we return the left subtree of the node.
3030
3. If the key is greater than the roots value, we return the right subtree of node.
3131
4. This process continued until we hit a leaf node. The new node is inserted to this location as a new node.
3232

33-
## Deletion
33+
### Deletion
3434
When removing a node from a binary search tree it is mandatory to maintain the in-order sequence of the nodes.
3535
There are three possible cases to consider:
3636
1. Deleting a node with no childeren :simply remove the node from the tree
37-
3837
2. Deleting a node with one child: remove the node and replace it with its child.
3938
3. Deleting a node with two children: First we find the inorder successor of the node. <br>
4039
Then the contents of this in-order successor are copied to the node to be deleted.
4140
Finally, the in-order successor is deleted
4241
<br>
4342

44-
## Example Code
43+
## Let's see the implementation of Binary Search Tree using an example:
4544

46-
```
45+
```java
4746
// Java implementation of recursive Binary Search
4847
class BinarySearch {
4948
// Returns index of x if it is present in arr[l..r],

0 commit comments

Comments
 (0)