1)Ans:
The properties of Binary Search Tree:
a)The maximum number of nodes at level ‘l’ will be 2l−1 . Here level is the number of nodes on path from root to the node, including the root itself. We are considering the level of root is 1.
b)Maximum number of nodes present in binary tree of height h is 2h−1 . Here height is the max number of nodes on root to leaf path. Here we are considering height of a tree with one node is 1.
c)In a binary tree with n nodes, minimum possible height or minimum number of levels arelog2⟮n+1⟯ . If we consider that the height of leaf node is considered as 0, then the formula will be log2⟮n+1⟯−1.
d)A binary tree with ‘L’ leaves has at least log2L+1 number of levels.
e)If a binary tree has 0 or 2 children, then number of leaf nodes are always one more than nodes with two children.
As binary tree is one kind of tree; it has all properties of tree in graph theory.
2)ANS:
A binary tree has a better time complexity for searching O(log N) but in the worst case can be the same as a linked list O(n). This means searching a binary tree will be faster than searching a linked list. Also, binary trees store values implicity sorted, so sorting operations are trivial.
Binary trees are great because they allow efficient sorting and searching. Their disadvantage is that in the worst case they can degenerate into a linked list in terms of efficiency. For example, inserting already-sorted data into a tree. Another disadvantage is coding complexity. Binary trees are much more complex than linked lists, especially for deletion and memory freeing. Also, to solve the problem of degeneration stated above, a self-balancing tree must be used which creates even more complexity.
Linked lists are simple to implement and have many practical applications, however, they have a lot of limitations. The best search algorithm that can be used on them is a linear search. The best sorting algorithms that can be used are not the best available. For example, any sort that requires random-access cannot be used on a linked list.
1. Properties of Binary Search Tree.
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)
2. 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.