Anúncio

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

1 de Apr de 2023
Consider the two functions below which both compute the value of f(n.pdf
Próximos SlideShares
Consider the following social-affiliation network of a small neighbo.pdfConsider the following social-affiliation network of a small neighbo.pdf
Carregando em ... 3
1 de 1
Anúncio

Mais conteúdo relacionado

Mais de americancolor(20)

Anúncio

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?
Anúncio