Computer Science 61A - Spring 1995 - Clancy - Final

Computer Science 61A - Spring 1995 - Clancy - Final - CS61A...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61A: Spring 1995 Final CS61A, Spring 1995 Final Question 1 (5 points): (a) Write a function prefix-to-infix that takes a Scheme arithmetic expression as its argument and returns a list containing the equivalent expression in the ordinary arithmetic notation with operators between the operands, like this: > (prefix-to-infix '(+ (* 2 3) (- 7 4))) ((2 * 3) + (7 - 4)) > (prefix-to-infix '(* (remainder 9 2) 5) ((9 remainder 2) * 5) You may assume that every function in the argument expression has exactly two arguments. (b) The procedure you wrote in part (a) carries out a tree reordering; in each sublist, the three elements are rearranged from the original order (0 1 2) to the new order (1 0 2) . That is, what used to be element number 1 now comes first; what used to be element number 0 now comes second, and what used to be number 2 remains third. We can represent this ordering by the list (1 0 2) . We'd like to generalize this by writing a procedure that takes an ordering as an additional argument, so that we could say (define (prefix-to-infix tree) (tree-reorder '(1 0 2) tree)) Here's an example of a tree-reorder that isn't a prefix-to-infix : > (tree-reorder '(2 1 2 1) '((a b c) (d e f) (g h i))) ((i h i h) (f e f e) (i h i h) (f e f e)) What follows is a partial implementation; your job is to fill in the blank. (define (tree-reorder ordering tree) (if (atom? tree) tree (map _______________________________________________________ ordering))) Assume that no number in the ordering is bigger than the length of any sublist; no error checking is needed. file:///C|/Documents%20and%20Settings/Jason%20Rafte...20Spring%201995%20-%20Clancy%20-%20Final%20Exam.htm (1 of 6)1/27/2007 6:28:49 PM
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS61A: Spring 1995 Final Question 2 (5 points): You are given a possibly infinite stream of lists of numbers. In the following example, the notation {...} represents a stream, while (...) represents a list: {(0 1 0 0 3) (1 2 3 0 4 2) (0 0 0 5 0) () (3) ...}
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern