斐波那契算法的分析

编程入门 行业动态 更新时间:2024-10-25 06:21:25
本文介绍了斐波那契算法的分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在阅读一个纤维球菌编号程序的分析,如下所示。提到这种实现方式效率低下。确实,对Fn进行递归调用的次数为F(n + 1)。

I am reading an analysis of a fibanocci number program, shown below. It is mentioned that this implementation is inefficient. Indeed, the number of recursive calls to compute Fn is F(n+1).

我的问题是:对Fn进行递归调用的次数为F (n + 1)是什么意思?

My question is: what does "the number of recursive calls to compute Fn is F(n+1)" mean?

int F(int i) { if (i < 1) return 0; if (i == 1) return 1; return F(i-1) + F(i-2); }

推荐答案

用于计算斐波那契的幼稚实现数字需要F(n + 1)个递归调用来计算数字F(n);也就是说,要计算f(10)= 55,您需要进行89个递归调用,而89是F(11)。

The naive implementation to compute fibonacci numbers takes F(n+1) recursive calls to compute the number F(n); i.e. to compute f(10)=55 you need 89 recursive calls, and 89 is F(11).

更多推荐

斐波那契算法的分析

本文发布于:2023-11-29 00:59:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!