-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Time complexity for fraction-search-algorithm #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did you understand the algorithm correctly? It is indeed logarithmic in
Or why do you think think that it is quadratic? |
Hi all, Aeren is right that the algorithm is quadratic. First of all, proper search on the Stern-Brocot tree should compress the output in run-length encoding. So, if Another thing to note is that it returns strings like |
It takes N calls to reach 1/N (1/1 -> 1/2 -> 1/3 -> 1/4 -> ... -> 1/N) |
@Aeren1564 My bad. I was completely wrong here. We should fix that, and provide a faster version. Implementing it with binary search doesn't look too hard. |
b19ce68: I rewrote the recursive code into iterative manner, so that it's |
The algorithm described in https://cp-algorithms.com/others/stern_brocot_tree_farey_sequences.html#fraction-search-algorithm works in
linearquadratic time in numerator+denominator, but the article claims that it is a "binary search algorithm".The text was updated successfully, but these errors were encountered: