Skip to content

Instantly share code, notes, and snippets.

@sulmanweb
Created May 20, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sulmanweb/cd0ed0ede2cb883396aacc79d888af7b to your computer and use it in GitHub Desktop.
Save sulmanweb/cd0ed0ede2cb883396aacc79d888af7b to your computer and use it in GitHub Desktop.
Find Fixed Point in Sorted Array Algorithm
def find_fixed_point(array)
n = array.length
high = n - 1
low = 0
while low <= high
mid = low + (high - low / 2)
if array[mid] == mid
return mid
elsif array[mid] < mid
low = mid + 1
else
high = mid - 1
end
end
# if no fixed point exist
return -1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment