2021-03-24

                                           Karatsuba Algorithm 

 

This algorithm is from: https://www.codesdope.com/blog/article/karatsuba-algorithm/

 

The idea is to recursively divide an n-digit number into two halves (each half having half the digits) until they are small enough (having 1 digit) to be multiplied using the naive method. Consider two numbers X and Y having base m which are represented using the following equation,

                                                                           

Here, the terms having ceil(n/2) will be more clear when you will see the implementation. So for simplicity purpose, you can take n as even for now. The multiplication of X and Y is carried out in the following equations,

                                                                        

In the above equation, X and Y have n digits and a, b, c and d have n/2 digits each. There are four multiplications (ac, ad, bc, bd) of numbers having size n/2 (having number of digits equal to n/2). So basically, we divided our multiplication problem of size n into four sub-multiplications of size n/2. But still the time complexity of the recurrence relation formed T(n)=4T(n^{2})+O(n)T(n)=4T(n^{2})+O(n)is O(n^{2})). Therefore, the trick is to split the middle part of the above equation as shown below,

                                     

As the multiplications ac and bd are already calculated in the equation (1), we reduced the multiplications ad and bc into one multiplication (a+b)∗(c+d)(a+b)∗(c+d). Therefore, there are now three multiplications of size n/2 (having number of digits equal to n/2) and the recurrence relation formed is T(n)=3T(n^{2})+O(n),he resultant equation becomes as shown below,

                    

                    

                              

 

                               

 

                                     

                                   

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值