categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the algorithm for finding the root of a given number using the bisection method. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:
liczba = 49
poczatek = 0
koniec = liczba
dokladnosc = 0.05
def pierwiastek(poczatek, koniec, dokladnosc):
global liczba
while abs(koniec - poczatek) >= dokladnosc:
srodek = (koniec + poczatek) / 2
if srodek ** 2 == liczba:
return srodek
elif srodek**2 > liczba:
koniec = srodek
else:
poczatek = srodek
return (koniec + poczatek) / 2
print(pierwiastek(poczatek, koniec, dokladnosc))
Video:
Thank you for reading!
Read more