How do I perform a fibonacci search algorithm in Matlab?

2 Ansichten (letzte 30 Tage)
alifiyah haq
alifiyah haq am 17 Jun. 2016
Kommentiert: Geoff Hayes am 18 Jun. 2016
I am trying to perform a simple search algorithm (fibonacci search) for an array [2,3,5,7,9,10,19 ,20] that performs similarly to a linear search (for the position of an element (target search key) within the array. Can anyone assist me?
I have a linear search as follows:
function output = Search(data, key) % function
n = 0;
output = [];
for k = 1:1:length(data) % go through elements 1:N
if (data(k) == key) % element = key
n = n + 1;
output(n) = k; % position
end
end
end
------------------------
>> Search([2 3 5 7 9 10 19 20], 20) will return me 8.
  1 Kommentar
Geoff Hayes
Geoff Hayes am 18 Jun. 2016
alifiyah - the Fibonacci search algorithm seems fairly straightforward. What problem are you having with implementing it?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by