Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give the type annotations arid implement the following functions: Explain what t

ID: 3784198 • Letter: G

Question

Give the type annotations arid implement the following functions: Explain what the function f below does. Justify your answer by running it on some examples. (define (f xs) (let ((g (lambda (x r) (if (even? x) (+ r 1) r)))) (foldr g 0 xs))) (Optional if you do 3) Complete the following definition of concat that flattens a list of lists. In order to complete it you have to fill in the dots. Careful, this is a use of fold at a higher-order type. (define (concat xss) (let ((g (lambda (xs h) ...))) (foldr g identity xss)))

Explanation / Answer

In order to show that f(n)+g(n) = O(h(n)), we need to find constants k and n0 such that for all n n0, f(n)+g(n) kh(n). Since f(n) = O(h(n)) and g(n) = O(h(n)) then by definition:

Take k = k1 + k2, and n0= max(n1,n2). Then
f(n)+g(n) k1h(n) + k2h(n) = (k1 + k2)h(n) = kh(n), for all n n0.
Hence f(n)+g(n) = O(h(n)).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote