fibnacci serch sample

fibnacci serch sample


V={1, 2, 3, 4, 5, 6, 7},在V中用Fibonacci查找元素1,被选取为轴点mi的元素依次是:

Fib = {0, 1, 1, 2, 3, 5, 8,13…}

[lo, hi) = [0,7): n = 7 = Fib(k)-1 = Fib(6) - 1; k = 6; mid = Fib(6-1) - 1 = 4; V[mid]=5;1 < V[mid];

[lo, hi) = [0, 4): n = 4 = Fib(k)-1 = Fib(5) - 1; k = 5; mid = Fib(5-1) - 1 = 2; V[mid]=3;1 < V[mid];

[lo, hi) = [0, 2): n = 2 = Fib(k)-1 = Fib(4) - 1; k = 4; mid = Fib(4-1) - 1 = 1; V[mid]=2;1 < V[mid];

[lo, hi) = [0, 1): n = 1 = Fib(k)-1 = Fib(3) - 1; k = 3; mid = Fib(3-1) - 1 = 0; V[mid] == 1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值