Back to course home
0% completed
Vote For New Content
I dont understand the comparison if (num > x) instead of if (num > x/2)
Manuel
Jan 8, 2025
As you first stated sqrt (x) is in the range 0 - x/2
Then, why are you doing this verification if (num > x) instead of if (num > x/2) ?
Thanks
0
0
Comments
Comments
S
semjase77 a month ago
Because num doesnt refer to the sqrt(x) but to midmidwhere mid is a potential integer value of sqt(x) and num is the square of that value . If num > x it means the value mid is to high to be the integer part of sqrt(x) so we need to keep doing binary search for the ...
On this page
Problem Statement
Solution
Step-by-Step Algorithm
Algorithm Walkthrough
Code
Complexity Analysis
Time Complexity
Space Complexity