Problem : Write a function that will perform a binary search on a sorted array of integers.We will provide two solutions, one iterative and one recursive. The return value from both is the index in the original array. If the element is not present in the array, the sharp-defined value ~NOT_FOUND~ is returned.
Problem : Assume now that we modify the definition of a binary search tree slightly. All of the data in a left subtree must precede the data in the current node, but all of the data in the right subtree must only be greater than or equal to the data in the root node (as opposed to exclusively greater than). Write a function that will take a new binary search tree and return 1 or 0 for whether it contains any duplicates.In order to check for duplicates, it suffices to check if the root of the right subtree has the same data element as the parent.
Problem : What is the worst case scenario for a binary search tree in terms of the complexity for searching for a data element? What about for adding a new data element?The worst case for searching is basically one where the binary search tree provides no help in dividing up the data. In other words, it is the case where the tree branches exclusively in one direction. In this case if there are n nodes in the tree, then there is one leaf and it is at depth n - 1. Thus a search in this tree consists of walking through each data element in order until you find the one you want. Hence, the complexity is O(n). Similarly, adding a new data element means walking along each data element until you find the place to add it; this is also O(n).