<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adarsh Raj</title>
    <description>The latest articles on DEV Community by Adarsh Raj (@adsv1623).</description>
    <link>https://dev.to/adsv1623</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F418001%2F998c25d2-a05d-49f9-bc74-160ea8983a28.jpeg</url>
      <title>DEV Community: Adarsh Raj</title>
      <link>https://dev.to/adsv1623</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adsv1623"/>
    <language>en</language>
    <item>
      <title>Fast Fibonacci Algorithms</title>
      <dc:creator>Adarsh Raj</dc:creator>
      <pubDate>Sun, 28 Jun 2020 12:45:11 +0000</pubDate>
      <link>https://dev.to/adsv1623/fast-fibonacci-algorithms-2324</link>
      <guid>https://dev.to/adsv1623/fast-fibonacci-algorithms-2324</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gm_EsKrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vwbczstikrq4rhjkats8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gm_EsKrT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vwbczstikrq4rhjkats8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     Algorithms For Fast Fibonacci Series.
&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;p&gt;The Fibonacci sequence is defined as &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;F(0)=0&lt;/strong&gt; , &lt;strong&gt;F(1)=1&lt;/strong&gt; &lt;br&gt;
  &lt;strong&gt;F(n)&lt;/strong&gt; = &lt;strong&gt;F(n−1)&lt;/strong&gt;+&lt;strong&gt;F(n−2)&lt;/strong&gt;   for &lt;strong&gt;n≥2&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the sequence (starting with F(0)) is 0, 1, 1, 2, 3, 5, 8, 13, 21, ….&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning Outcomes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;See the huge difference between a slow algorithm and a fast one.

&lt;ul&gt;
&lt;li&gt;Matrix exponentiation (fast)&lt;/li&gt;
&lt;li&gt;Fast doubling (faster)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Other Problems On Fibonacci

&lt;ul&gt;
&lt;li&gt;Pisano Period( F(n) mod m ) m ≥ 2.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  # &lt;strong&gt;Matrix exponentiation&lt;/strong&gt; (fast)
&lt;/h2&gt;

&lt;p&gt;Matrix Exponentiation (also known as matrix power, repeated squaring) is a technique used to solve linear recurrences.&lt;br&gt;
The concept of matrix exponentiation in its most general form is very useful in solving questions that involve calculating the nth term of a linear recurrence relation in time of the order of log(n).&lt;br&gt;
The algorithm is based on this innocent-looking identity (which can be proven by mathematical induction):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Caf2VWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/73rfgt3654eip3oo2453.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Caf2VWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/73rfgt3654eip3oo2453.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Final Matrix Form Will be -&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C7x2-uiy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r5wnfrbbts4iwtww1a92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C7x2-uiy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r5wnfrbbts4iwtww1a92.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fibonacci Problem On leetcode(&lt;a href="https://leetcode.com/problems/fibonacci-number/"&gt;Link&lt;/a&gt;)using Matrix exponentiation:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1O0O77Dd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wk4ly6ufidpvok8qnyx8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1O0O77Dd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wk4ly6ufidpvok8qnyx8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JSsbTFvy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a3wzsl9yasswomk1szy6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JSsbTFvy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a3wzsl9yasswomk1szy6.png" alt="Alt Text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Source Code&lt;/em&gt;&lt;/strong&gt;: &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://leetcode.com/problems/fibonacci-number/"&gt;Problem&lt;/a&gt;&lt;strong&gt;:-&lt;/strong&gt;&lt;a href="https://github.com/adsv1623/Dev-Post/blob/master/Fibonacci-Exponential.cpp"&gt;Solution&lt;/a&gt;  &lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;# Fast doubling&lt;/strong&gt; (faster)
&lt;/h2&gt;

&lt;p&gt;Fast doubling is based on two formulae&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ABNk6tgM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nj8la72mh7kup2cd6a7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ABNk6tgM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nj8la72mh7kup2cd6a7v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These identities can be extracted from the matrix exponentiation algorithm. This algorithm is the matrix exponentiation algorithm with the reductant calculations removed. It should be a constant factor faster than matrix exponentiation, but the asymptotic time complexity is still the same.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AkYXr7el--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/inyiljn5me909q8c2nin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AkYXr7el--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/inyiljn5me909q8c2nin.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Soution&lt;/strong&gt;:-&lt;a href="https://github.com/adsv1623/Dev-Post/blob/master/Fast-Doubling-Fibonacci.cpp"&gt;Link&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1&gt;
  
  
  &lt;em&gt;Other Problems&lt;/em&gt;:
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1.Pisano Period.&lt;/strong&gt;&lt;br&gt;
Take a detailed look at this table.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hFJU1rvt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z1853jpdg6jg3qwsuqs9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hFJU1rvt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z1853jpdg6jg3qwsuqs9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
You see is it Periodic?&lt;br&gt;
yes,Both these sequences are periodic! For m = 2, the period is 011 and has length 3, while for m = 3 the period is 01120221 and has length 8. &lt;/p&gt;

&lt;p&gt;Let's say, F(2015) mod 3 we just need to find the remainder of 2015 when divided by 8. Since 2015 = 251·8+7, &lt;br&gt;
we conclude that F(2015) mod 3 = F 7 mod 3 = 1.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;:-&lt;a href="https://github.com/adsv1623/Dev-Post/blob/master/Pisano.cpp"&gt;Link&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Github&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/adsv1623"&gt;
        adsv1623
      &lt;/a&gt; / &lt;a href="https://github.com/adsv1623/Dev-Post"&gt;
        Dev-Post
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      My blogs
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Dev-Post&lt;/h1&gt;
&lt;h2&gt;
This C++ Program demonstrates the the computation of Fibonacci Numbers using Matrix Exponentiation.&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Here is source code of the C++ Program to Find Fibonacci Numbers using Matrix Exponentiation.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Pisano Period For Computation Of Last digits For A large Fibonacci Sequence.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/adsv1623/Dev-Post"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Other Sites:&lt;a href="https://funloop.org/post/2017-04-14-computing-fibonacci-numbers.html"&gt;Helper Guide&lt;/a&gt; , &lt;a href="https://youtu.be/EEb6JP3NXBI"&gt;video&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;If you can think of any other way to improve this algorithm or if you could point out something that you think I did wrong, you’re more than welcome to reach out to me by responding to this and pointing out the mistakes. If you like this solution, please hit the “Like” button below, it’ll mean a lot to me. Thanks:-)&lt;/em&gt;&lt;/strong&gt;

</description>
      <category>fibonnaci</category>
    </item>
  </channel>
</rss>
