Optimal strategies of the search for an extremum