1a 1b Total /10 pts /10 pts /20 pts



Similar documents

Algorithms and Data Structures Written Exam Proposed SOLUTION

Worksheet for Teaching Module Probability (Lesson 1)

Computer Programming I

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

>

Functional Programming

CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions. Linda Shapiro Spring 2016

Full and Complete Binary Trees

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

PIC 10A. Lecture 7: Graphics II and intro to the if statement

Cassandra. References:

Algorithms are the threads that tie together most of the subfields of computer science.

6. Control Structures

Form Validation. Server-side Web Development and Programming. What to Validate. Error Prevention. Lecture 7: Input Validation and Error Handling

Moving from CS 61A Scheme to CS 61B Java

JavaScript: Control Statements I

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Chapter 7: Functional Programming Languages

CS 425 Software Engineering

Compiler Construction

Chapter 2: Elements of Java

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012


Recursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Chapter 15 Functional Programming Languages

Unit 6. Loop statements

AP Computer Science Java Subset

Foundations of Programming

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

CS106A, Stanford Handout #38. Strings and Chars

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Regression Verification: Status Report

CS 425 Software Engineering. Course Syllabus

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Programming Database lectures for mathema

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Review of Hashing: Integer Keys

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Introduction to Python

Normalisation in the Presence of Lists

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Discrete Mathematics I Distance Learning (online) sections

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

So let us begin our quest to find the holy grail of real analysis.

Binary search algorithm

AP Computer Science A 2010 Scoring Guidelines

Static Program Transformations for Efficient Software Model Checking

PRI-(BASIC2) Preliminary Reference Information Mod date 3. Jun. 2015

FEEG Applied Programming 3 - Version Control and Git II

Software Development (CS2500)

dictionary find definition word definition book index find relevant pages term list of page numbers

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Lewis, Loftus, and Cocking. Java Software Solutions for AP Computer Science 3rd Edition. Boston, Mass. Addison-Wesley, 2011.

Programming Languages CIS 443

CIS/MKTG4500 Customer Relationship Management

NAME: (Please PRINT) CEN Software Engineering

How To Program In Scheme (Prolog)

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

BCN 4612 Estimating II - Semester Course Outline Course Syllabus

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

cs2010: algorithms and data structures

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Psychological Tests and Measurements PSYC Summer 2016

csce4313 Programming Languages Scanner (pass/fail)

The Halting Problem is Undecidable

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

arrays C Programming Language - Arrays

Decision Logic: if, if else, switch, Boolean conditions and variables

Software Testing. Jeffrey Carver University of Alabama. April 7, 2016

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Example of a Java program

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

MATH 304 Linear Algebra Lecture 9: Subspaces of vector spaces (continued). Span. Spanning set.

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

PROFESSOR TATHAGATA DASGUPTA

Biology 360 Genetics Lecture Syllabus and Schedule, Fall 2012 Tentative

Software Engineering

CS 425 Software Engineering. Course Syllabus

Solution: start more than one instruction in the same clock cycle CPI < 1 (or IPC > 1, Instructions per Cycle) Two approaches:

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Discrete Optimization

Optimizing object definitions functions

Linear Algebra. A vector space (over R) is an ordered quadruple. such that V is a set; 0 V ; and the following eight axioms hold:

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Umbrello UML Modeller Handbook

Fundamentele Informatica II

Building Java Programs

Crash Dive into Python

SQL Tables, Keys, Views, Indexes

Transcription:

Instructions 1. This is an open-notes, open-book, open-computer, open-internet exam. 2. The exam is due in class on November 10, 2008. 3. You can work on this exam as much as you like. There is no time limit. 4. Please make sure you have all 5 pages of this exam. 5. You will not be penalized on trivial syntax errors, such as a missing parenthesis. Multiple errors or errors that lead to ambiguous code will have points deducted, however. 6. In all of the questions, feel free to write additional helper methods to get the job done. 7. The emphasis is on correctness of the code, not efficiency or on simply generating the right result. 8. You are free to use any code that was given to you in the lectures and labs, or that you wrote in this exam. 9. You do not have to write generic code in this exam. Please write and sign the Rice Honor Pledge here: 1a 1b Total /10 pts /10 pts /20 pts Nov. 3-Nov. 10 2008 1 of 5

Lazy Evaluation: a) (10 pts) You are to write an ALazyEval called LazyNCopiesEval that will create a finite (ending!) list using the lazy list framework. LazyNCopiesEval takes an Object o and an int n, and produces a list of length n filled with the object o. If n is 0 or less, the list created by LazyCombineEval is empty. You may use an if statement to deal with n>=0. Example: o o=1, n=0 () o o=1, n=1 (1) o o=1, n=2 (1, 1) o o=1, n=3 (1, 1, 1) Notes: a. Think delegation always. b. There are no if statements needed, unless you are working with primitive data (ints, doubles, etc.)! c. Don t forget about the possibility that the source lists may be or become empty. Please insert your code for LazyNCopiesEval.java below: package lrs.lazylrsevaluators; import lrs.*; * Given an element e and a number n, creates a list of length n, * containing elements of e. public class LazyNCopiesEval extends ALazyEval { public LazyNCopiesEval(Object e, int n) { _e = e; _n = n; // FOR STUDENT TO COMPLETE: add fields and methods here protected Object _e; protected int _n; public LRStruct nextlrs() { * If _n is >0, decrements _n and returns a lazy list with _e as first. * @return a list with _e as first if _n>0, empty otherwise. public LRStruct makelrs() { if (_n-->0) return makelazylrs(_e); else return new LRStruct(); Nov. 3-Nov. 10 2008 2 of 5

Nov. 3-Nov. 10 2008 3 of 5

Lazy Evaluation: b) (10 pts) You are to write an ALazyEval called LazyListNCopiesEval that will create a possibly infinite. LazyListNCopiesEval takes two LRStructs: the first LRStruct li contains Integers (i1, i2, i3, ), the second LRStruct lo contains Objects (o1, o2, o3, ). The lazy list created by LazyListNCopiesEval contains i1 copies of o1, i2 copies of o2, i3 copies of o3, and so on. If one if the integers is 0, then the corresponding object will be skipped. Example: o li = (), lo= () result = () o li = (1), lo= () result = () o li = (), lo= (1) result = () o li = (1), lo= (1) result = (1) o li = (2), lo= (1) result = (1, 1) o li = (3), lo= (1) result = (1, 1, 1) o li = (1, 1), lo= (1) result = (1) o li = (1), lo= (1, 1) result = (1) o li = (1, 2), lo= (1, 2) result = (1, 2, 2) o li = (0), lo= (1) result = () o li = (0, 1), lo= (0, 1) result = (1) o li = (0, 1, 0), lo= (0, 1, 0) result = (1) o li = (1, 1, 1, ), lo= (1, 2, 3, ) result = (1, 2, 3, ) Please insert your code for LazyListNCopiesEval.java below: package lrs.lazylrsevaluators; import lrs.*; import fp.*; * Takes two lists, one list of integers Li(i1, li2, li3,...) and one list * of objects Lo(o1, o2,...). It lazily creates a list that contains i1 * elements of o1, followed by i2 elements of o2, and so on. * If one of the two lists Li or Lo ends, this list ends. public class LazyListNCopiesEval extends ALazyEval { Constructs a LazyListNCopiesEval, which creates a lazy list. * @param li input list with integers * @param lo input list with objects public LazyListNCopiesEval(LRStruct li, LRStruct lo) { this.li = li; this.lo = lo; // FOR STUDENT TO COMPLETE: add fields and methods here private LRStruct li; private LRStruct lo; private LRStruct out = new LRStruct(); public LRStruct nextlrs() { * If the lambda list is non-empty, remove the lambda a lambda and pass the value list * to it. Return the value of the lambda application. If the lambda list is empty, * clone the value list. * @return a list with the elements that come out of the lambdas. public LRStruct makelrs() { return (LRStruct)out.execute(new IAlgo() { // out list is empty Nov. 3-Nov. 10 2008 4 of 5

return (LRStruct)li.execute(new IAlgo() { // returning a non-lazy empty LRStruct will prevent // the code from returning here return new LRStruct(); // empty public Object nonemptycase(final LRStruct ihost, Object... inp) { return (LRStruct)lo.execute(new IAlgo() { // returning a non-lazy empty LRStruct will prevent // the code from returning here return new LRStruct(); // empty public Object nonemptycase(lrstruct host, Object... inp) { // both non-empty out = new LazyNCopiesEval(host.removeFront(), (Integer)ihost.removeFront()).makeLRS(); ); ); public Object nonemptycase(lrstruct host, Object... inp) { // out list is still non-empty, return first element of it return makelazylrs(host.removefront()); ); Nov. 3-Nov. 10 2008 5 of 5