练习1.20
这道题要求我们分别在正则序和应用序的情况下来研究书中的gcd函数,并且还要算出实际执行remainder运算的次数。题目中先问的正则序后问的应用序,但由于应用序比较简单,我们先来看看应用序:
(gcd 206 40) (gcd 40 6) (gcd 6 4) (gcd 4 2) (gcd 2 0) 2 因此(gcd 206 40)共调用了5次remainder函数。再来看看正则序的情况:
(gcd 206 40) (gcd 40 (remainder 206 40)) (gcd (remainder 206 40) (remainder 40 (remainder (206 40)))) (gcd (remainder 40 (remainder (206 40))) (remainder (remainder 206 40) (remainder 40 (remainder (206 40))))) (gcd (remainder (remainder 206 40) (remainder 40 (remainder (206 40))))) (remainder (remainder 40 (remainder (206 40))) (remainder (remainder 206 40) (remainder 40 (remainder (206 40))))))到这里就相当于参数是2和0了,在这里我已经将if去掉了,至于remainder调用多少次数数便知道了。
版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。