

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this exam paper are: Arbitrary Degree, Scheme Print, Global Variables, Algorithm, Applicative-Order Evaluation, Normal -Order Evaluation, Linear Recursive Process, Coefficients, Linear Iterative Function, Polynomial
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!
What will Scheme print in response to the following expressions? If it produces an error or runs forever without a result, just say "error". If it is a procedure, say "procedure". Assume no global variables have been defined beforehand except where noted.
(word '(+2 3) (+2 3))
((lambda (x y z) (* 5 y)) 3 4 7)
;from ex. 1.32, p. 61 (accumulate se '(hurrah) (lambda(x) (word 'hip x)) 1 (lambda (x) (1+x)) 3)
((if 3 - *) 32 2)
(a b c)
(let ((a 5) (* +) (+ *)) a(+ a a))
((lambda (-) (- 2)) (lambda (*) (+ * 4) ))
_______ A Ø (log(2n)) algorithm is slower than a Ø (2 log(n)) algorithm
_______ For small size inputs knowing the Ø order of an algorithm is more useful than for large inputs
_______ If f(x) is Ø (log x), then lim (x => infinity) f(x)/(log x) is zero
evaluates (g y) more often than a normal -order evaluation
_______ Function g below defines a linear recursive process
(define (g a b c) (if (> a b) c (+ c ( g (+ a 1) (- b 1) (+ c 1)))))
of that sentence and an empty sentence if there is no such element. Count from zero. For example,
(li-nth 0 '(1 2 3 4)) 1 (li-nth 2 '(1 2 3 4)) 3 (li-nth 4 '(1 2 3 4)) '()
Does the following segment of scheme define a function? In one sentence, explain why or why not.
(define (f x) aaaaaa ((lambda (u) aaaaaa ((let ((a 0) aaaaaaa let ((b 1)) aaaaaaa let (random u))) aaaaaaaa (+ 45 x)))
A polynomial can be repeated as a sentence, where the words are the coefficients of the terms. The first element of the sentence represents the term of degree 0 (the constant term), the second represents the term of degree 1, etc. So, for example, 3x² + 2x+ 1 would be '(1 2 3) and 27x 8 + 1 would be '(1 0 0 0 0 0 0 0 27) The polynomial whose coefficients are all zero is represented by '().
as a sentence and returns their sum, represented as a sentence. For example
(add-polys '(1 2 3) '(1 0 0 0 0 0 0 0 27)) (2 2 3 0 0 0 0 0 27)
In this representation, multiplying polynomials by terms (otherwise known as monomials; 9x² is a monomial or term whereas 9x² + 1 is a polynomial with two terms) involves shifting and multiplying.
sentence, a term coefficient and the degree of a term and returns the product represented by a sentence For example, if I wanted to multiply 9x² + 2x + 1 by 7x 3 , I would do:
(term-multiply-poly '(1 2 9) 7 3) (0 0 0 7 14 63)
it behaves as if the shorter were padded with 0's. For example,
(interleave-2 '(1 2 3 4) '(5 6 7 8)) (5 1 6 2 7 3 8 4) (interleave-2 '(9) '(10)) (10 9) (interleave-2 '(9) '(10 11 12)) (10 9 11 0 12 0) (interleave-2 '(1 2 3 4) '(5)) (5 1 0 2 0 3 0 4)