tailieunhanh - Algorithms for programmers phần 9

Một tính năng quan trọng của thuật toán một số hoạt động phải được thực hiện để hoàn thành một nhiệm vụ của một kích thước N nhất định. N số lượng nên có một số lượng hợp lý phát triển đúng với kích cỡ của nhiệm vụ. | Chapter 11 Arithmetical algorithms Asymptotics of algorithms An important feature of an algorithm is the number of operations that must be performed for the completion of a task of a certain size N. The quantity N should be some reasonable quantity that grows strictly with the size of the task. For high precision computations one will take the length of the numbers counted in decimal digits or bits. For computations with square matrices one may take for N the number of rows. An operation is typically a machine word multiplication plus an addition one could also simply count machine instructions. An algorithm is said to have some asymptotics f N if it needs proportional f N operations for a task of size N. Examples Addition of an N-digit number needs proportional N operations here machine word addition plus some carry operation . Ordinary multiplication needs N2 operations. The Fast Fourier Transform FFT needs N log N operations a straight forward implementation of the Fourier Transform . computing N sums each of length N would be N2 . Matrix multiplication by the obvious algorithm is N3 N2 sums each of N products . The algorithm with the best asymptotics wins for some possibly huge N. For smaller N another algorithm will be superior. For the exact break-even point the constants omitted elsewhere are of course important. Example Let the algorithm multi take N2 operations mult2 take N log2 N operations. Then for N 64 multi is faster and for N 64 mult2 is faster. Completely different algorithms may be optimal for the same task at different problem sizes. Multiplication of large numbers Ordinary multiplication is N2. Computing the product of two million-digit numbers would require 1012 operations taking about 1 day on a machine that does 10 million operations per second. But there are better ways . . . 170 CHAPTER 11. ARITHMETICAL ALGORITHMS 171 The Karatsuba algorithm Split the numbers U and V assumed to have approximately the same length .

TỪ KHÓA LIÊN QUAN