0% found this document useful (0 votes)
33 views3 pages

T2 (AddlSlot)

Uploaded by

Supriya M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

T2 (AddlSlot)

Uploaded by

Supriya M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Amrita Vishwa Vidyapeetham

Amrita School of Engineering, Bangalore Campus


Department of Computer Science & Engineering
Periodical Test 2 - October 2013 (Additional Slot)
Course Name & Code: Structure and Interpretation of Computer Programs (CSE221)
Date & Time: 19/10/2013 Duration: 2 Hrs.
Branch& Semester: CSE – AS Max. Marks: 50
Answer all the questions:
Part A (8 x 3 = 24 marks)
1. Draw the box and pointer notation for the list ((e (f) g) h). What is the output generated for the
operation cdadar on the above list?
2. Evaluate the following:
i) (caddr ’((2 3 5) (7 11 13) (17 19)))
ii) (cddar ((2 (12 3)) 45 2 ))
3. Write the equivalent Lisp expression for the following box and pointer notations:

4. Consider the following function and evaluate the expression: (quiz-f '(a b) '(b a)).
(define (quiz-f a b)
(list 'a b '(list a 'b)) )
5. Generate the Huffman tree and find the bit patterns to be encoded for the alphabets A, B, E, S, P, Q
and T. The frequencies of the alphabets are 8, 6, 12, 3, 15, 6 and 23 respectively. Encode the
message TEAPETBET using the constructed tree.
6. Write a procedure check that returns true if the given element x is lesser than the elements in the
given ordered set, else returns false.
7. Using the binary tree abstract data type, write the predicate all-larger? that takes two arguments, a
binary tree of numbers and a single number x, and returns #t if every number in the tree is larger
than the second argument x, else returns #f.
8. The procedure square-list takes a list of numbers as argument and returns a list of the squares of
those numbers.
I/P : (square-list (list 1 2 3 4))
O/P: (1 4 9 16)
Complete the missing terms in the two versions of the procedure written to perform the mentioned
task.
i) (define (square-list items) ii) (define (square-list items)
(if (null? items) nil (map <??> <??>))
(cons <??> <??>)))

Part B (5 x 4 = 20 marks)
9. Assume that the Scheme Interpreter has the functions: accumulate, map, filter, enumerate-tree
and enumerate-interval defined in it. Using the above as conventional interfaces, define the
procedures to perform the following:
i) To find the sum of odd squares of the Fibonacci numbers between 0 and n.
ii) To generate a list with the squares of the even elements in a given tree.
10. Consider the following fold-left procedure
(define (fold-left op initial sequence)
(define (iter result rest)
(if (null? rest) result
(iter (op result (car rest)) (cdr rest))))
(iter initial sequence))
What are the values of
i) (fold-left / 1 (list 1 2 3))
ii) (fold-left list nil (list 1 2 3))
11. Consider the following function.
(define (accumulate f L init-value)
(if (null? L) init-value
(f (car L) (accumulate f (cdr L) init-value)) ) )
What does evaluation of the expression (accumulate cons '(1 2 3) '( )) produce? Show
the work.
12. Define a procedure subsent that takes in a sentence and a parameter i, and
returns a sentence with elements starting from position i to the end. The first
element has i = 0. In other words, (subsent ‘(6 4 2 7 5 8) 3) returns (7 5 8).
13. Write a procedure called intersection-set that returns the list created with the
intersection of the elements present in the two given ordered sets s1 and s2.
For eg., if s1 contains (1 3 5 9) and s2 contains (2 5 6 9), the resultant set is (5
9).

Part C (6 marks)
14. A point can be represented as a pair of numbers: the x coordinate and the y coordinate.
Accordingly, specify a constructor make-point and selectors x-point and y-point that define this
representation. Using the selectors and constructors, write procedure add-points and sub-points that
adds and subtracts the two given points. Write a procedure called print-point that prints the point in
the format (x-point, y-point).
!!!!!!!!!!!!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy