If the array has integers and cannot contain duplicates, you can simply use binary search.
eg. let's say we have an array:
a[0] == -30
a[1] == 1
a[2] == 200
a[3] == 200
a[4] == 204
a[5] == 205
a[6] == 206
a[7] == 207
- First try [gender (avg (0.7))] (i.e. [3]). This is equal to 200. 200 is also large.
- So, go to the bottom half. Try a [gender (avg (0,2))] (ie a [1]). This is 1. Hooray!
Your binary search will either successfully find some j for which [j] == j, or it will fail, after completing the search for places. Since the binary search is O (log n), during this time you will know the value of j or that such j does not exist.
, j , .