Зміст курсу
Binary Search in Python
Binary Search in Python
Sqrt(n)
In this section, we will practice with the BS algorithm.
The first task will be to find the square root of the number.
Look at the explanation of the task! How does it work?
Use hints if needed! Be careful with the tabulation!
Let's practice!
Завдання
- Set condition if the
x
equals0
or1
. - Set the while loop to work while the
left
is lower or equals theright
. - Set condition if the square of the middle elements equals
x
. - Set condition if the square of the middle elements is lower than
x
. - Update the
left
. Theleft
equals themiddle + 1
. - Update the
result
. Theresult
equals themiddle
. - Update the
right
. Theright
equals themiddle - 1
. - Test the function.
Дякуємо за ваш відгук!
Sqrt(n)
In this section, we will practice with the BS algorithm.
The first task will be to find the square root of the number.
Look at the explanation of the task! How does it work?
Use hints if needed! Be careful with the tabulation!
Let's practice!
Завдання
- Set condition if the
x
equals0
or1
. - Set the while loop to work while the
left
is lower or equals theright
. - Set condition if the square of the middle elements equals
x
. - Set condition if the square of the middle elements is lower than
x
. - Update the
left
. Theleft
equals themiddle + 1
. - Update the
result
. Theresult
equals themiddle
. - Update the
right
. Theright
equals themiddle - 1
. - Test the function.
Дякуємо за ваш відгук!
Sqrt(n)
In this section, we will practice with the BS algorithm.
The first task will be to find the square root of the number.
Look at the explanation of the task! How does it work?
Use hints if needed! Be careful with the tabulation!
Let's practice!
Завдання
- Set condition if the
x
equals0
or1
. - Set the while loop to work while the
left
is lower or equals theright
. - Set condition if the square of the middle elements equals
x
. - Set condition if the square of the middle elements is lower than
x
. - Update the
left
. Theleft
equals themiddle + 1
. - Update the
result
. Theresult
equals themiddle
. - Update the
right
. Theright
equals themiddle - 1
. - Test the function.
Дякуємо за ваш відгук!
In this section, we will practice with the BS algorithm.
The first task will be to find the square root of the number.
Look at the explanation of the task! How does it work?
Use hints if needed! Be careful with the tabulation!
Let's practice!
Завдання
- Set condition if the
x
equals0
or1
. - Set the while loop to work while the
left
is lower or equals theright
. - Set condition if the square of the middle elements equals
x
. - Set condition if the square of the middle elements is lower than
x
. - Update the
left
. Theleft
equals themiddle + 1
. - Update the
result
. Theresult
equals themiddle
. - Update the
right
. Theright
equals themiddle - 1
. - Test the function.