• Home
  • Textbooks
  • Computer science with Mathematica: theory and practice for science, mathematics, and engineering
  • Complexity of Algorithms

Computer science with Mathematica: theory and practice for science, mathematics, and engineering

Roman Maeder

Chapter 7

Complexity of Algorithms - all with Video Answers

Educators


Chapter Questions

05:55

Problem 1

Powers of numbers or matrices $m^n$ can be computed by working on the exponent $n$ from left to right (from the most significant to the least significant bit). This method has the advantage that each iteration of the loop requires only one multiplication with large numbers, whereas the second multiplication - if the bit is equal to one - is with the original $m$. For Fibonacci numbers, this matrix $m$ consists only of zeroes and ones.
1. Program the left-to-right method in general form (for powers of numbers), similar to the definition of BinaryPower [] in Section 7.1.3.
2. Write a special version of the definition for the computation of the $n$th Fibonacci number and compare its run time with method fibh[] from Section 7.2.6.

Gabriel Eduok
Gabriel Eduok
Numerade Educator

Problem 2

Make some experiments with the loop for computing the $n$ the Fibonacci number (program $f i b c[]$ in Section 7.2 .2$)$ and estimate the time it would take to compute $f i b c[10 \wedge 7]$.

Check back soon!

Problem 3

In this exercise, we want to experiment with long-integer multiplication algorithms.
1. Write a program times $[a, b]$ for the multiplication of two long integers similar to the program plus [] in Section 7.4.1. Use the naive schoolbook method for multiplication.
2. Implement the Karatsuba method.
3. For what size of numbers is the Karatsuba method faster than the simple algorithm?

Check back soon!