1. 斐波那契搜索简介:
斐波那契搜索就是在二分查找的基础上根据斐波那契数列进行分割的。在斐波那契数列找一个等于略大于查找表中元素个数的数F[k],将原查找表扩展为长度为F[n](如果要补充元素,则补充重复最后一个元素,直到满足F[k]个元素),完成后进行斐波那契分割,即F[k]个元素分割为前半部分F[k-1]个元素,后半部分F[k-2]个元素,找出要查找的元素在那一部分并递归,直到找到。
2.图解斐波那契搜索
3. 代码实现
#include <iostream>
#include<vector>
#include<cstdlib>
#include<ctime>
const int FIBOSIZE = 20;
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//生成斐波那契数列
void fibonacci(vector<int>& F)
{
F.push_back(1);
F.push_back(1);
for(int i=2;i<FIBOSIZE;i++)
{
F.push_back(F[i