Question: Must use R5RS Scheme Language A function f defined: f(n) = n, if n <4 f(n) = f(n-1) + 2f(n-2) + 3f(n-3) + 4f(n-4), otherwise
Must use R5RS Scheme Language
A function f defined:
f(n) = n, if n<4
f(n) = f(n-1) + 2f(n-2) + 3f(n-3) + 4f(n-4), otherwise
Part 1: Write a procedure that computes f by means of a recursive process (i.e., see example of a recursive process below)
(define (factorial n) (if (= n 1) 1 (* n (factorial (- n 1)))))
Part 2: Write a procedure that computes f by means of an iterative process (i.e., see example of an iterative process below)
(define (factorial n) (define (factorial-iteration product counter) (if (> counter n) product (factorial-iteration (* counter product) (+ counter 1)))) (factorial-iteration 1 1))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
