370 likes | 524 Views
Delve into the world of Fibonacci numbers, exploring their definition, computation methods, and significance through efficient algorithms. Learn the running time and visual representation of these sequences for a comprehensive understanding.
E N D
Introduction:Fibonacci Numbers http://iti.wtf Algorithms and Data Structures Artem A. Golubnichiy artem@golubnichij.ru Department of Software of Computer Facilities and Automated Systems KatanovKhakass State University
STRUCTURE OF THE CLASS • Problem Overview; • Naive Algorithm; • Efficient Algorithm.
DEFINITION In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones.
DEFINITION In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones.
DEFINITION In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597 . . .
EXAMPLE F20 = 6765
EXAMPLE F20 = 6765 F50 = 12586269025
EXAMPLE F20 = 6765 F50 = 12586269025 F100 = 354224848179261915075
EXAMPLE F20 = 6765 F50 = 12586269025 F100 = 354224848179261915075 F500 = 13942322456169788013972438287040728395007025658769730 7264108962948325571622863290691557658876222521294125
RUNNING TIME Let T(n) denote the number of lines of code executed by FibRecurs(n) if n ≤ 1 T(n) = 2
RUNNING TIME Let T(n) denote the number of lines of code executed by FibRecurs(n) if n ≥ 2 T(n) = 3 + T(n – 1) + T(n – 2)
RUNNING TIME Therefore T(n) ≥ Fn T(100) ≈ 1.77∙1021 Takes 56000 years at 1Ghz
WHY SO SLOW? Fn Fn-2 Fn-1 Fn-2 Fn-3 Fn-3 Fn-4 Fn-4 Fn-5 Fn-5 Fn-6 Fn-4 Fn-4 Fn-3 Fn-5
WHY SO SLOW? Fn Fn-2 Fn-1 Fn-2 Fn-3 Fn-3 Fn-4 Fn-4 Fn-5 Fn-5 Fn-6 Fn-4 Fn-4 Fn-3 Fn-5
WHY SO SLOW? Fn Fn-2 Fn-1 Fn-2 Fn-3 Fn-3 Fn-4 Fn-4 Fn-5 Fn-5 Fn-6 Fn-4 Fn-4 Fn-3 Fn-5
ANOTHER ALGORITHM Imitate hand computation: 0, 1
ANOTHER ALGORITHM Imitate hand computation: 0, 1, 1 0 + 1 = 1
ANOTHER ALGORITHM Imitate hand computation: 0, 1, 1, 2 0 + 1 = 1 1 + 1 = 2
ANOTHER ALGORITHM Imitate hand computation: 0, 1, 1, 2, 3 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3
ANOTHER ALGORITHM Imitate hand computation: 0, 1, 1, 2, 3, 5 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5
ANOTHER ALGORITHM Imitate hand computation: 0, 1, 1, 2, 3, 5, 8 0 + 1 = 1 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8
NEW ALGORITHM T(n) = 2n + 2. So T(100) = 202
VISUALIZING ALGORITHMS Recursive Table