Forum discussion on Binary Search Tree

Answer

Answer

by Asadur Rahaman Yead -
Number of replies: 0

Answer 01

A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties −


The value of the key of the left sub-tree is less than the value of its parent (root) node's key.


The value of the key of the right sub-tree is greater than or equal to the value of its parent (root) node's key.


Thus, BST divides all its sub-trees into two segments; the left sub-tree and the right sub-tree and can be defined as −


left_subtree (keys) < node (key) ≤ right_subtree (keys)



Answer 02

Binary search tree is better than linked list or sorted array.

Binary search is an algorithm for the search-problem, and can be utilized in many different settings, including certain kinds of decision procedures for optimization problems.

Binary search requires that the input data maintains a partial ordering (in simple terms, it is sorted in non-decreasing order). The benefit we want out of the algorithm is to access each value at the middle position in constant time. In a linked list, getting the middle position can take [math]O(n)[/math] time. So the time complexity would go from [math]O(\log{n})[/math] to [math]O(n\log{n})[/math].

A data structure such as an array is far more suitable as you can access any member of the array in constant time. Remember that the data must be sorted to use binary search.