Computer Science

IT Matura Course | Algorithms #23


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
Administrator

This post was written by the administrator

Recent Posts

Proof Problems in Mathematics The Beginning Integrals, Course Practical Physics for Engineers IT Matura Course | Algorithms IT Matura Course | Databases IT Matura Course | Theory IT Matura Course | Spreadsheet

Archive

Year 2022

Comments