Answers for "recherche dichotomique recursive en algorithme"

0

recherche dichotomique recursive en algorithme

def recherche_dichotomique( element, liste_triee ):
    a = 0
    b = len(liste_triee)-1
    m = (a+b)//2
    while a < b :
        if liste_triee[m] == element :
            return m
        elif liste_triee[m] > element :
            b = m-1
        else :
            a = m+1
        m = (a+b)//2
    return a
Posted by: Guest on March-19-2021
0

recherche dichotomique recursive en algorithme

def recherche_dichotomique_recursive( element, liste_triee, a = 0, b = -1 ):
    if a == b : 
        return a
    if b == -1 : 
        b = len(liste_triee)-1
    m = (a+b)//2
    if liste_triee[m] == element :
        return m
    elif liste_triee[m] > element :
        return recherche_dichotomique_recursive(element, liste_triee, a, m-1)
    else :
        return recherche_dichotomique_recursive(element, liste_triee, m+1, b)
Posted by: Guest on March-19-2021

Browse Popular Code Answers by Language