Implementation of BinarySearch and CountingOccurrences