cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

Similar documents
cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

Exam 2. Name: UVa ID:

cs1120: Exam 2 Due: Thursday Nov 29 at 3:30pm (in class)

Richard Feynman, Lectures on Computation

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Merge Sort. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

Repetition Through Recursion

Midterm I - Solution CS164, Spring 2014

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

UVa ID: NAME (print): CS 4501 LDI Midterm 1

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Sample Final Exam Questions

;; definition of function, fun, that adds 7 to the input (define fun (lambda (x) (+ x 7)))

CS 314 Principles of Programming Languages. Lecture 16

YOUR NAME PLEASE: *** SOLUTIONS ***

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

CSE341 Spring 2017, Final Examination June 8, 2017

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

April 2 to April 4, 2018

Structure and Interpretation of Computer Programs

by the evening of Tuesday, Feb 6

Department of Electrical Engineering and Computer Sciences Fall 2000 Instructor: Dan Garcia CS 3 Final Exam

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Structure and Interpretation of Computer Programs

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

University of Massachusetts Lowell

CSE341 Spring 2017, Final Examination June 8, 2017

CSE413 Midterm. Question Max Points Total 100

CS264: Homework #1. Due by midnight on Thursday, January 19, 2017

Write a procedure powerset which takes as its only argument a set S and returns the powerset of S.

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

Scheme: Strings Scheme: I/O

A Brief Introduction to Scheme (II)

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

(Refer Slide Time: 01.26)

CSE341 Spring 2016, Final Examination June 6, 2016

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)

Warm-up and Memoization

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

You must define a class that represents songs. Your class will implement the Song interface in $master/proj2/cs61b/song.java.

Data Structures and Algorithms Key to Homework 1

Prelim CS410, Summer July 1998 Please note: This exam is closed book, closed note. Sit every-other seat. Put your answers in this exam. The or

CS 314 Principles of Programming Languages

Homework 4: Clustering, Recommenders, Dim. Reduction, ML and Graph Mining (due November 19 th, 2014, 2:30pm, in class hard-copy please)

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Recursion I and II. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

Working with recursion

Department of Computer Science Core Graduate Comprehensive Exam Fall 2018

Functional Programming. Pure Functional Programming

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Structure and Interpretation of Computer Programs

This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

Problem Set 6 Due: 11:59 Sunday, April 29

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Fall 2017 December 4, Scheme. Instructions

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CS261: Problem Set #1

Test 1 Review Questions with Solutions

Part I: Written Problems

Lecture 35: Analysis Review & Tail Recursion 10:00 AM, Nov 28, 2018

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Spring 2014 Final (with corrections)

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

Preliminary Examination I Computer Science 312, Cornell University 6 March 2003

Documentation for LISP in BASIC

A random five-digit number: a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3

CS 540-1: Introduction to Artificial Intelligence

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University


Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

CSCI-1200 Data Structures Spring 2017 Lecture 5 Pointers, Arrays, Pointer Arithmetic

COE428 Lecture Notes Week 1 (Week of January 9, 2017)

Structure and Interpretation of Computer Programs

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

CS 2500 Exam 1 Fall 2012

Introduction to Sets and Logic (MATH 1190)

A Concepts-Focused Introduction to Functional Programming Using Standard ML Sample Exam #1 Draft of August 12, 2010

CS8 Final Exam E03, 09M, Phill Conrad, UC Santa Barbara 09/10/2009

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017

The Limits of Sorting Divide-and-Conquer Comparison Sorts II

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CMSC351 - Fall 2014, Homework #2

Transcription:

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class) UVA ID (e.g., wrw6y) : Directions Work alone. You may not discuss these problems or anything related to the material covered by this exam with anyone except for the course staff between receiving this exam and turning it in. Open resources. You may use any books you want, lecture notes, slides, your notes, and problem sets. You may not use DrScheme or DrRacket, but it is not necessary to do so. You may also use external non-human sources including books and web sites. If you use anything other than the course books, slides, and notes, cite what you used. You may not obtain any help from other humans other than the course staff. Answer well. Answer all questions 1-9 (question 0 is your UVA ID in two places, which hopefully everyone will receive full credit for), and optionally answer questions 10-11. You may either: (1) print out this exam and write your answers on it or (2) write your answers directly into the provided Word template and print the result out. Whichever one you choose, you must turn in your answers printed on paper and they must be clear enough for us to read and understand. You should not need more space than is provided to write good answers, but if you want more space you may attach extra sheets. If you do, make sure they are clearly marked. The questions are not necessarily in order of increasing difficulty, so if you get stuck on one question you should continue on to the next question. There is no time limit on this exam, but it should not take a well-prepared student more than a few hours to complete. It may take you longer, though, so please do not delay starting the exam. There is no valid excuse (other than a medical or personal emergency) for running out of time on this exam. No "snow jobs". If you leave a question blank, you will receive three points for it. If you have no idea and waste our time with long-winded guessing, we will be less sanguine and the grading will be more sanguine. :-) Use any Scheme procedure from class. In your answers, you may use any Scheme procedure that appears in the lecture notes or in the book without redefining it (e.g., length, filter, sort, findbest, etc.). If there are multiple similar names (e.g., map vs. list-map), use whichever you like. Full credit depends on the clarity and elegance of your answer, not just correctness. Your answers should be as short and simple as possible, but not simpler. Your programs will be judged for correctness, clarity and elegance, but you will not lose points for trivial errors (such as missing a closing parenthesis).

UVA ID again (e.g., wrw6y) : Your Scores 0 1 2 3 4 5 6 7 8 9 EC Total 10 10 10 10 10 10 10 10 10 10 2 100 (Your scores are recorded on the second page so that they are not visible to other students when tests are distributed or passed back.)

1. Consider the following grammar: S ::= N N and S N ::= A B C D E F A ::= randall simon B ::= darius phillip ε C ::= jackson cowell D ::= paula E ::= julie ε F ::= abdul The start symbol is S. The symbol ε denotes the empty string. (a) Is the language of this grammar infinite or finite? (b) Give a string of length six (i.e., six words) that is in the language of the grammar. (a) (b) 2. Consider the following Scheme definition. (define (territory worker-fun lst) (if (null? lst) null (append (territory worker-fun (cdr lst)) (cons (worker-fun (car lst)) null)))) Provide a convincing argument that territory is not equivalent to map. (Hint: provide inputs on which they behave differently.) 3

3. Write a Scheme procedure no-homework that accepts a list of strings as input. It should return the same list of strings in the same order, but with all instances of homework replaced by none. For example: > (no-homework (list locke ben homework sawyer homework ) ( locke ben none sawyer none ) > (no-homework (cons ( claire null)) ( claire ) (define (no-homework lst) 4. Define a make-list-remover procedure that takes one input, an element, and produces a procedure as output. The output procedure is a procedure that takes a list of numbers as input, and produces as output that same list but with all entries matching the original element removed. (Hint: besides "define", how do we make procedures in Scheme?) For example: > (make-list-remover 5) #<procedure> > ((make-list-remover 2) (list 1 2 3)) (1 3) > ((make-list-remover 7) (list 10-2 13)) (10-2 13) (define (make-list-remover n) 4

5. Define a procedure nested-sum that takes one input: a list. The list may contain integer elements, but it may also contain other lists (which may themselves contain other lists, hence "nested"). The procedure should return the sum total of the elements anywhere in the list. For example: > (list? (list 1 2 3)) #t > (nested-sum (list -9-8 -7 0 4 5 6)) -9 > (nested-sum (list 1 2 (list 0 (list 4 5)) 7 (list -3 0))) 16 > (nested-sum (list )) 0 > (nested-sum (list -1 (list ) -3)) -4 (Hint 1: rewrite-lcommands. Hint 2: There are three cases. The list may be empty, its first element may itself be a list, or its first element may be an integer. Two of those three cases involve recursive calls.) (define (nested-sum lst) 5

6. Answer each of the following questions about function growth. Give an argument that explains each answer. For example, to prove that n is in O(n/2) you might demonstrate the constants n 0 = 1 and c = 2. If there is any ambiguity, use the definitions from Chapter 7 of the course book. Is n+8 in O(n)? Why or why not? Is n 4 in O(n 3 )? Why or why not? Is n in Ω(4 n - 3)? Why or why not? Is log n in Ω(n 3 )? Why or why not? Is 5n 2 in Θ(n 3 )? Why or why not? 6

7. Consider the following four procedures: (define (map f lst) (if (null? lst) null (cons (f (car lst)) (map f (cdr lst))))) (define (my-reverse lst) (define (reverse-helper x y) (if (null? x) y (reverse-helper (cdr x) (cons (car x) y)))) (reverse-helper lst null)) (define (revmap-alpha f lst) (my-reverse (map f lst))) (define (revmap-beta f lst) (if (null? lst) null (append (revmap-beta f (cdr lst)) (list (f (car lst)))))) Give the running time of my-reverse and revmap-alpha and revmap-beta in Big Theta Θ notation. Assume f runs in constant time. Which of revmap-alpha and revmapbeta is faster? Can there be an asymptotically faster revmap procedure? (Hint: either demonstrate "yes" by giving the procedure, or argue that no such faster procedure is possible.) (a) my-reverse is Θ (b) revmap-alpha is Θ (c) revmap-beta is Θ (d) The faster procedure is (e) 7

8. Consider the task of sorting a music playlist for a portable music player or cell phone. We will represent each song as a cons pair of its artist and its title. We wish to sort the playlist by title first, and then by artist. Write a procedure sort-playlist that accepts one argument, a list of songs, and returns that same list of songs, but sorted as per the description above. Example: > (define song1 (cons "ABBA" "Mamma Mia") > (define song2 (cons "Taylor Swift" "Love Story") > (define song3 (cons "Beyonce" "Single Ladies") > (define song4 (cons "Randy Newman" "Love Story") > (define song5 (cons "Lonely Island" "I'm On A Boat")) > (sort-playlist (list song1 song2 song3 song4 song5)) ( ("Lonely Island". "I'm On A Boat") ("Randy Newman". "Love Story") ("Taylor Swift". "Love Story") ("ABBA". "Mamma Mia") ("Beyonce". "Single Ladies" ) ) > (string<? "ABBA" "Beyonce") #t > (eq? "ABBA" "Beyonce") #f (No points off if you sort Z-A instead of A-Z. All points off if you sort by artist first.) (define (sort-playlist lst) 8

9. In the not too distant future (next Sunday A.D.), YouTube, Twitter and Facebook have merged together to form YouTwitFace, one social networking site to rule them all and in the darkness bind them. You have been asked to write a friend analysis procedure for this site. Lists of friends are available. Given such a list, you are to find the person with the most friends. You should write two procedures. The first, number-of-friends, takes as input a lists of pairs of strings (representing friends) and a particular string (the person under consideration) returns an integer (the number of friends of that person). The second, most-friends, takes as input a list of pairs of strings (representing friends, as before). It should return the name of the person with the most friends. (This can be done in under 10 lines total.) Example: > (define friends (list (cons rachel monica ) (cons phoebe rachel ) (cons rachel joey ) (cons monica joey ) (cons monica chandler ) )) > (number-of-friends friends rachel ) 3 > (number-of-friends friends chandler ) 1 > (most-friends friends) rachel (define (number-of-friends lst who) (define (most-friends lst) 9

10. (Extra credit, two points max, no points for leaving this blank.) Give the running time for your implementation of most-friends using Θ notation (or a hypothetical implementation if you did not complete #9). Assume that the friend list contains F friend pairs. 11. (Zero points.) Do you feel your performance on this exam will fairly reflect your understanding of the course material so far? If not, explain why. You will not lose any points for your answer. 10