Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (12 points) Consider the following algorithm: procedure alg1(a, b: positive inte gers procedure alg2(a, b: positive integers) while y0 while y 0 r- mod
1. (12 points) Consider the following algorithm: procedure alg1(a, b: positive inte gers procedure alg2(a, b: positive integers) while y0 while y 0 r- mod y return return T Before you start: trace each of these algorithms with a few possible inputs Work to understand what function each implements. You do not need to hand this work in (a) You are told that algorithm algl is finite. You do not need to prove this claim; but it's good practice to think about how you would. Define pseudocode for algorithm alg3 that is identical to algl except for one line and which describes an algorithm that is not finite. Prove that your example works by specifying sample input where the algorithm never returns output because it goes into an infinite loop trace the algorithm on this input to justify your answer. (b) Is algorithm alg2 finite? That is, is its computation guaranteed to terminate no matter which positive integers are chosen for a and b? Note: for full credit, give your answer (yes or no) and justify it. If your answer is yes, the justification should explain why the algorithm can't possibly go into an infinite loop no matter what inputs are chosen (think carefully about the type of the inputs and the loop condition). If your answer is no, you need to find an erample where the algorithm never returns output because it goes into an infinite loop.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started