- Python Data Structures and Algorithms
- Benjamin Baka
- 254字
- 2021-07-09 19:45:07
Divide and conquer - long multiplication
For recursion to be more than just a clever trick, we need to understand how to compare it to other approaches, such as iteration, and to understand when its use will lead to a faster algorithm. An iterative algorithm that we are all familiar with is the procedure we learned in primary math classes, used to multiply two large numbers. That is, long multiplication. If you remember, long multiplication involved iterative multiplying and carry operations followed by a shifting and addition operation.
Our aim here is to examine ways to measure how efficient this procedure is and attempt to answer the question; is this the most efficient procedure we can use for multiplying two large numbers together?
In the following figure, we can see that multiplying two 4 digit numbers together requires 16 multiplication operations, and we can generalize to say that an n digit number requires, approximately, n2 multiplication operations:

This method of analyzing algorithms, in terms of the number of computational primitives such as multiplication and addition, is important because it gives us a way to understand the relationship between the time it takes to complete a certain computation and the size of the input to that computation. In particular, we want to know what happens when the input, the number of digits, n, is very large. This topic, called asymptotic analysis, or time complexity, is essential to our study of algorithms and we will revisit it often during this chapter and the rest of this book.
- JMeter 性能測(cè)試實(shí)戰(zhàn)(第2版)
- Java FX應(yīng)用開發(fā)教程
- VSTO開發(fā)入門教程
- 深入淺出Windows API程序設(shè)計(jì):編程基礎(chǔ)篇
- aelf區(qū)塊鏈應(yīng)用架構(gòu)指南
- Full-Stack Vue.js 2 and Laravel 5
- C++程序設(shè)計(jì)基礎(chǔ)教程
- INSTANT OpenNMS Starter
- Android 應(yīng)用案例開發(fā)大全(第3版)
- Asynchronous Android Programming(Second Edition)
- SQL Server與JSP動(dòng)態(tài)網(wǎng)站開發(fā)
- Windows Embedded CE 6.0程序設(shè)計(jì)實(shí)戰(zhàn)
- Practical GIS
- Mastering SciPy
- 深入淺出 HTTPS:從原理到實(shí)戰(zhàn)