1. Engineering
  2. Computer Science
  3. 5 points algorithm 3 and algorithm 4 contain four procedures...

Question: 5 points algorithm 3 and algorithm 4 contain four procedures...

Question details

[5 points] Algorithm 3 and Algorithm 4 contain four procedures that are supposed to compute Fn, the n-th Fibonacci number, for a non-negative integer n. Recall that Fibonacci numbers are defined by Fo 0, F, and F F-1+F-2 for integers n 2 2. Explain for each procedure why it works or does not work. If the procedure does not work, provide an example input on which it fails; otherwise, give a correctness proof.

Algorithm 3 Three programs that are supposed to compute Fn for a non-negative integer n 1: procedure FO(n) 3:While m > 3 do 5: 6: 7 8:if m0 then 9: return i if m - 1 then else 10 else return j 12 13: 14: return k 15: procedure F1(n) 16: 17: while m >3 do 18: 19: 20 21 if m - 0 then return i 23 24:else 25 26; 27 28 if m-1 then return j else return k

29: procedure F2(n) 30: m←n 31: if m <2 then 32 return mm 34 while m> 2 do 36: 37: return k

O C procedure F3(n) while m 3 do if m 0 then return i else if m 1 then return j else return k

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution