dimanche 10 septembre 2023

Use a binary search to find max of a function

My task is to use a binary search to find the max value of a function of unsigned ints. The domain of the function is 0 to 2^64 - 1. The catch is, I know no information about the max value or the max index. The only information I have is a method, double func(unsigned int x); which returns the value of the function at the integer x. I also know that the function is either strictly increasing, strictly decreasing, or increasing to a point, then decreasing.

I attempted to check for strictly increasing functions by checking if ((func(0) < func(1)) && (func(2^64 - 2) < func(2^64 - 1))) which didn't even work for finding strictly increasing functions.

Aucun commentaire:

Enregistrer un commentaire