?2E Determine which characteristics of an algorithm described in the text (after Algorithm 1) the following procedures have and which they lack. a) procedure ?double?(n ? ?: positive integer) while n? ? > 0 n??? 2?n b) procedure ?divide?(n ? ? : positive integer) while n? ? > 0 m? := 1/?n?. n? := ?n? ?–? 1 c) procedure ?sum?(?n:? positive integer) sum? := 0 while i<10 sum := sum – i d) procedure ?choose?(?a,? b ? :? integers). x? := either ?a? or ?b
Solution In this question we have to determine the characteristics of given algorithm and the following procedures they have and which they lack. Step 1 Given that a) p rocedure double( positive integer) while n > 0 n 2n This algorithm is not finite since n is a positive number and the while loop will run forever in this algorithm. b) procedure divide(n : positive integer) while n 0 m := 1/n. n := n – 1 At n = 0 line m := 1/n cannot be executed so eventually the case would be that this algorithm is not effective. Also this algorithm lacks correctness since m := 1/n keeps the algorithm from arriving at correct answer.