Au secoure récursivité fouille dichotomique
Noob260893
-
babacool -
babacool -
Bonjour,
Je dois créer pour mon cour de math discrète un algorithme récursif de fouille dichotomique(binaire) avec maple 13 j'ai deja 2 tests d'algorithmes mais ils ne fonctionnent pas :
1:
FouilleDicho:= proc (x::integer,i::integer,L)
local m:
local n:
local emplacement:
n := nops (L):
m := (L[1]+L[n])/2:
if x = L[m]
then
emplacement := m
else
if (x < L[m] and i < m)
then
FouilleDicho(x, i+1, L)
else
emplacement := 0
end if:
end if:
end proc:
2:
FouilleDicho2:=proc(L, x::integer, i::integer)
local m:
local n:
local emplacement:
n := nops(L):
m := (L[1]+L[n])/2:
if x=L[i]
then
emplacement := i
else
if x < L[m]
then
FouilleDicho2(L,x,m-1)
else
if x > L[m]
then
FouilleDicho2(L,x,m+1)
end if:
end if:
end if:
end proc:
si vous pouviez soit m'aider avec mes 2 codes existants où me proposer un autre algorithme récursif svp
merci d'avance
Je dois créer pour mon cour de math discrète un algorithme récursif de fouille dichotomique(binaire) avec maple 13 j'ai deja 2 tests d'algorithmes mais ils ne fonctionnent pas :
1:
FouilleDicho:= proc (x::integer,i::integer,L)
local m:
local n:
local emplacement:
n := nops (L):
m := (L[1]+L[n])/2:
if x = L[m]
then
emplacement := m
else
if (x < L[m] and i < m)
then
FouilleDicho(x, i+1, L)
else
emplacement := 0
end if:
end if:
end proc:
2:
FouilleDicho2:=proc(L, x::integer, i::integer)
local m:
local n:
local emplacement:
n := nops(L):
m := (L[1]+L[n])/2:
if x=L[i]
then
emplacement := i
else
if x < L[m]
then
FouilleDicho2(L,x,m-1)
else
if x > L[m]
then
FouilleDicho2(L,x,m+1)
end if:
end if:
end if:
end proc:
si vous pouviez soit m'aider avec mes 2 codes existants où me proposer un autre algorithme récursif svp
merci d'avance
1 réponse
je sais pas si ça va t'aider mais voilà ce que j'ai
fonction RechDico(t[]:chaine; d, f,:entier; r:chaine):entier
var m :entier
debut
m:=(f-d+1)\2
Si t[m]=r alors
valret:=m
sinon
si d=f alors
valret:=0
sinon
si t[m]>r alors
valret=RechDico(t[],d,m-1,r)
sinon
valret=RechDico(t[],m+1,f,r)
fin si
fin si
fin si
fin
fonction RechDico(t[]:chaine; d, f,:entier; r:chaine):entier
var m :entier
debut
m:=(f-d+1)\2
Si t[m]=r alors
valret:=m
sinon
si d=f alors
valret:=0
sinon
si t[m]>r alors
valret=RechDico(t[],d,m-1,r)
sinon
valret=RechDico(t[],m+1,f,r)
fin si
fin si
fin si
fin