Fully working binary search