Académique Documents
Professionnel Documents
Culture Documents
K2 K4 K6 K9 K14
K1
Decision Tree for Fibonacci Search
Algorithm illustarates the procedure for
fibonacci search
N is the number of data elements is such that
(i) Fk+1 > (n+1) and
(ii) Fk = (n+1) for some m>=0 where Fk+1 and Fk
are two consecutive fibonacci numbers
Algorithm for Fibonacci Search
Procedure Fibonacci_search(L,n,K)
// L(1:n) is a linear ordered (non decreasing) list of data
elements. N is such that Fk+1>(n+1). Also Fk+m=(n+1). K
is the key to be searched in the list //
Obtain the largest fibonacci number Fk closest to n+1
p= Fk-1
q=Fk-2
r=Fk-3
m=(n+1) (p+q)
If (K>L(p)) then p=p+m
Found=false
Algorithm for Fibonacci Search
While ((P<>0) and (not found)) do
Case
: K=L[p] { print (key found);
found=true;
}
: K <L[p] : if (r=0) then p=0
else {p=p-r; t=q; q=r; r=t-r;}
: K > L[p] : if (q=1) then p=0
else {p=p+r; q=q-r; r=r-q}
Endcase
Endwhile
If (found=false) then print (key not found);
End fibonacci_search.
Algorithm for Fibonacci Search
Let us search for the key K=434
L=(2,4,8,9,17,36,44,55,81,84,94,116,221,256,3
02,256,396,401,434,536)
N=20, the number of elements is such that (i)
F9 > n+1 and (ii) F8+m = (n+1) where m=0 and
n=20
The algorithm for fibonacci search first obtains
the largest fibonacci number closest to n+1. ie
F8 in this case.
Algorithm for Fibonacci Search
It compares K=434 with the data element with index F7
i.e.L[13]=221
Since K>L[13] the search list is reduced to
L[14:20]={256,302,356,396,401,434,536}
Now K compares itself with L[18]=401. Since K>L[18]
the search list is further reduced to L[19:20]={434,536}
Now K is compared with L[20]=536. Since K<L[20] is
true it results in the search list {434} which when
searched yields the search key.
The key is successfully found
Following a similar procedure, searching for 66 in the
list yields an unsuccessful search
Algorithm for Fibonacci Search
Search < t p q r Remarks
key K K=L[p]
>
434 13 8 5 n=20
m=0 since
F8+0=n+1
K > L[13] = 221 13 8 5 Since K > L[p]
p=p+m
K > L[13] = 221 18 3 2
K > L[18} = 401 20 1 1
K < L[20] = 536 1 19 1 0
K = L[19] = 434 Key is Found
Algorithm for Fibonacci Search
Search < t p q r Remarks
key K K=L[p]
>
66 13 8 5 n=20
m=0
K > L[13] = 221 8 8 5 3
K > L[8] = 55 11 2 1
K < L[11] = 94 2 10 1 1
K < L[10] = 84 1 9 1 0
K < L[9] = 81 Since (r=0) p is set to 0
Key is not found
Fibonacci Search
An advantage of fibonacci search over binary
search is that while binary search involves
division which is computationally expensive,
during the selection of next element for key
comparison, fibonacci search involves only
addition and subtraction