BINARY SEARCH TREE SEARCHING Always starts from the root, compare the data stored with the key we are searching for. I f the data is less than the key value, search in the left subtree otherwise search in the right subtree. a binary search tree can reduce the search time to O(n). Algorithm If root . data is equal to search . data return root else while data not found If data is greater than node . data goto right subtree else goto left subtree If data found return node endwhile return data not found end if INSERTION Start from the root and go down searching for a proper location. If the data is less than the key search for empty location in the left subtree, otherwise searh for empty location in the right subtree. Insert the data if the data that want to be insert is not in the tree (NULL), won't insert duplicates. Algorithm If root is NULL the...
Comments
Post a Comment