When we want to insert a new element, we roughly know in which subtree (left or right) we will insert the element. Similarly, insertion and deletion operations are more efficient in BST. This becomes possible because we can easily determine the rough location of the element to be searched. As elements are ordered, half the subtree is discarded at every step while searching for an element. The BST data structure is considered to be very efficient when compared to Arrays and Linked list when it comes to insertion/deletion and searching of items.īST takes O (log n) time to search for an element. We can say that the above tree fulfills the BST properties. The right subtree has all the nodes that are greater than 20. The left subtree has all the node values that are less than 20. We see that 20 is the root node of this tree. The below diagram shows a BST Representation:Ībove shown is a sample BST. Binary Search Tree (BST) Traversal In Java.Binary Search Tree (BST) Implementation In Java.
0 Comments
Leave a Reply. |