Anzeige

Consider the two functions below which both compute the value of f(n.pdf

1. Apr 2023
Consider the two functions below which both compute the value of f(n.pdf
Nächste SlideShare
Consider the following social-affiliation network of a small neighbo.pdfConsider the following social-affiliation network of a small neighbo.pdf
Wird geladen in ... 3
1 von 1
Anzeige

Más contenido relacionado

Más de americancolor(20)

Anzeige

Consider the two functions below which both compute the value of f(n.pdf

  1. Consider the two functions below which both compute the value of f(n). The function f1 was replaced with f2 because integer multiplications () were found to take 4 times longer than integer additions (+). int f1(n : integer) if (n == 1) then return(1) else return(2 f1(n 1)); int f2(n : integer) if (n == 1) then return(1) else return(f2(n 1) + f2(n 1)); i. Give a recurrence relation for f1, which satisfies the number of multiplications (*) executed as a function of n. ii. Solve the recurrence relation from Part i. iii. Give a recurrence relation for f2, which satisfies the number of additions (+) executed as a function of n. iv. Solve the recurrence relation from Part iii. v. Both functions compute the same function f. Was it a good idea to replace f1 with f2?
Anzeige