Ex 2_25 n位十進制整數轉換為二進制形式..._第四次作業
阿新 • • 發佈:2017-12-05
運行時 es2017 整數 cnblogs 二進制 .cn http bsp alt
*xL+xR=pwr2bin(n/2)*dec2bin(xL)+dec2bin(xR)
(a) 當n=1時,(10)d=(1010)b
當n=2時,(100)d=(10)d x (10)d=(1010)b x (1010)b
當n=4時,(10000)d=(100)d x (100)d=(1010)b x (1010)b x (1010)b x (1010)b
…
因此z=pwr2bin(n/2)
T(n)=T(n/2)+(cn/2)log23=>T(n)=O(nlog23)
(b)
若十進制整數x的位數等於1,則返回binary[x]
假設位數為n(n>1且n為2的冪),則把x平均分成兩部分xL和xR,每一部分為n/2位
則x=10n/2
=fastMultiply(pwr2bin(n/2),dec2bin(xL))+dec2bin(xR)
運行時間為
T(n)=2T(n)+O(nlog23)=>T(n)=O(nlog23)
Ex 2_25 n位十進制整數轉換為二進制形式..._第四次作業