سوال ۶۶ کنکور ارشد علوم کامپیوتر ۱۳۹۷
اگر نشاندهندهٔ kامین عدد در دنبالهٔ فیبوناچی باشد، بهترین زمان برای محاسبه چیست؟
پاسخ صحیح: گزینهٔ C —
Goal. Compute a single Fibonacci number with the index , as fast as possible (counting arithmetic operations as unit-cost, which is the usual convention in these exam questions).
Naive bounds (rejected).
- Iterating the recurrence up to index costs additions. With that is — option 2, but not the best time.
- The exponential recursive definition is far worse, so it is irrelevant here.
Best method: fast matrix exponentiation / fast doubling. The Fibonacci map is linear:
So is read off from where . A power is computed by repeated squaring (exponentiation by squaring) in matrix multiplications, each multiplication being for a fixed matrix.
Substitute the index :
The factor of from squaring the index is absorbed by the asymptotic notation. Hence the best time is — option 3.
Exam trick: , so squaring the index does not change the order of the fast-doubling cost. The trap answers are (naive iteration to index ) and (mis-simplifying to ).