2E Determine which characteristics of an algorithm

Chapter 2, Problem 2E

(choose chapter or problem)

Get Unlimited Answers
QUESTION:

?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

Questions & Answers

QUESTION:

?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

ANSWER:

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.

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back