How to implement Fibonacci algorithm in two ways in C++?
I mean I wan to implement Fibonacci algorithm in both divide and conquer(D&C) method and dynamic programming and finally extract time complexity of both methods and compare the complexities and choose one of them.please guide me.


Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 12:38 AM EDT
Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 10:36 AM EDT
using namespace std;
int main()
{
int i=1; int j=0; int k=0; int h=1; int t=0; int n;
cin>>n;
while (n)
{ if (n%2)
{ t=j*h; j=i*h+j*k+t; i=ik+t; }
t=h*h; h=2*k*h+t; k=k*k+t; n=n/2; }
cout<<j;
return 0; }
Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 11:22 AM EDT
if you got ur answer accept answer.
Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 10:22 PM EDT
http://www.c-program-example.com/2011/10/c-program-to-implement-floyds-algorithm.html
Akhil GargRank #772 · 3K reputationPosted Apr 19, 2015, 8:48 AM EDT
Accept the answer if it solved your problems. . :)
Joe WilsonRank #631 · 3.8K reputationPosted Apr 17, 2015, 10:12 AM EDT
Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 10:38 AM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Apr 17, 2015, 10:59 AM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Apr 17, 2015, 10:07 PM EDT
Akhil GargRank #772 · 3K reputationPosted Apr 17, 2015, 10:19 PM EDT
Joe WilsonRank #631 · 3.8K reputationPosted Apr 19, 2015, 8:14 AM EDT