COS 126 Written Exam 2, Fall 2009

Similar documents
COS 126 Written Exam 2 (Spring 2015)

COS 226 Midterm Exam, Spring 2010

COS 126 Midterm 1 Written Exam, Fall 2009

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 2

COS 126 Midterm 1 Written Exam Spring 2015

COS 226 Midterm Exam, Spring 2011

COS 126 General Computer Science Fall Written Exam 1

COS 226 Midterm Exam, Spring 2009

COS 226 Algorithms and Data Structures Spring Midterm

COS 126 Written Exam 2 Spring 18

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Final Exam, Spring 2009

CS171 Midterm Exam. October 29, Name:

COS 126 General Computer Science Fall Exam 1

COS 126 Midterm 1 Written Exam Fall 2011

COS 126 Midterm 2 Programming Exam Fall 2012

COS 126 General Computer Science Fall Midterm 1

COS 126 Midterm 1 Written Exam Fall 2014!

COS 126 MIDTERM 1, FALL

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Written Exam 2 Fall 2016

COS 126 General Computer Science Spring Written Exam 1

11/22/1999 7pm - 9pm. Name: Login Name: Preceptor Name: Precept Number:

COS 126 Midterm 1 Written Exam Fall 2012

COS 126 General Computer Science Fall Exam 1

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

1. [5 points each] True or False. If the question is currently open, write O or Open.

COS 226 Algorithms and Data Structures Spring Midterm

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

COS 126 General Computer Science Spring Exam 2

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Spring Midterm

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

COS 226 Algorithms and Data Structures Spring Midterm Exam

input sort left half sort right half merge results Mergesort overview

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

COS 226 Final Exam, Spring 2010

COS 226 Algorithms and Data Structures Spring Midterm

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

COS 126 General Computer Science Spring Midterm 1

COS 126 General Computer Science Fall Exam 1

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

CSE373 Fall 2013, Midterm Examination October 18, 2013

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

COS 226 Algorithms and Data Structures Fall Final

CSE wi: Practice Midterm

COS 126 Midterm 1 Written Exam Fall 2013

SAMPLE EXAM Final Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 16 December 2010

Chapter 9 Graph Algorithms

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

CSE332 Summer 2010: Final Exam

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

4.2 Sorting and Searching. Section 4.2

COS 126 Exam 2 Review Part 1

Prelim 2 Solution. CS 2110, April 26, 2016, 7:30 PM

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Introduction to Computer Science II (CSI 1101)

Chapter 9 Graph Algorithms

Final Examination CS 125 Introduction to Computer Science Fall Hours

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

overview overview who practicalities introduction data structures and algorithms lecture 1 sorting insertion sort pseudo code merge sort

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

Test #2. Login: 2 PROBLEM 1 : (Balance (6points)) Insert the following elements into an AVL tree. Make sure you show the tree before and after each ro

COS 226 Algorithms and Data Structures Spring Second Written Exam

Computer Science 217 Final Exam May 15, :30pm-4:30pm

Theory Bridge Exam Example Questions Version of June 6, 2008

CS 101 Spring 2007 Midterm 2 Name: ID:

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Name: UTLN: CS login: Comp 15 Data Structures Midterm 2018 Summer

Computer Science /21/2000

COS 226 Algorithms and Data Structures Fall Final Exam

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

Lecture 2: Getting Started

CSE 11 Midterm Fall 2008

1 Inheritance (8 minutes, 9 points)

Comp Intermediate Programming EXAM #2 March 30, 2005 Rice University - Instructors: Cox & Nguyen

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

University of Maryland College Park Dept of Computer Science

Princeton University Computer Science COS226: Data Structures and Algorithms. Midterm, Fall 2013

Prelim 2. CS 2110, April 26, 2016, 5:30 PM Total Question True/False Complexity Heaps Trees Graphs Max Score Grader

Analyzing Complexity of Lists

(the bubble footer is automatically inserted into this space)

Closed Computer and Book 1 Double-sided sheet of notes allowed staple to your test when done

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Final Exam. COMP Summer I June 26, points

You will not be tested on JUnit or the Eclipse debugger. The exam does not cover interfaces.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

CSC 210, Exam Two Section February 1999

Introduction to Computing II (ITI 1121) Final Examination

CS 455 Final Exam Fall 2016 [Bono] December 13, 2016

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

Prelim 2 Solution. CS 2110, April 26, 2016, 5:30 PM

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Transcription:

NAME: COS 126 Written Exam 2, Fall 2009 login ID: precept: This test is 11 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators or other electronic devices are permitted. Give your answers and show your work in the space provided. Put your name, login ID, and precept number on this page (now), and write out and sign the Honor Code pledge before turning in the test. You have 50 minutes to complete the test. "I pledge my honor that I have not violated the Honor Code during this examination." Signature 1 Binary Search Trees /8 2 DFAs /12 3 Linked Lists /15 4 ADTs and APIs /10 5 Mergesort /10 6 Architecture /6 7 Circuit /8 8 Theory /12 9 Church-Turing /6 10 TSP performance /5 11 Debugging /5 TOTAL /97 December 17, 2009

1. Binary Search Trees (8 points). Draw the binary search tree that results when you insert the keys 33 67 14 26 43 71 70 in that order into an initially empty tree. 33 / \ 14 67 \ / \ 26 43 71 / 70 Circle the statements below that explain why using binary search trees makes sense (more than one might apply). A. Search in BSTs is always much faster than in linked lists. B. Everything in a computer is encoded in binary. C. BSTs are a reasonable way to implement efficient symbol tables for typical clients. D. Inserting and deleting data items is much easier in BSTs than in sorted arrays. E. BSTs use less space than linked lists. 2

2. Deterministic Finite Automata (12 points). Consider the following DFAs: Match each DFA with one of the descriptions below by writing its letter in the blank to the left of the corresponding description. Since there are two more descriptions than DFAs, you must leave two options blank. B Bitstrings with at least one 1 A Bitstrings with an equal number of occurrences of 01 and 10 Bitstrings with more 1s than 0s Bitstrings with an equal number of occurrences of 0 and 1 C Bitstrings that end in 1 3

3. Linked Lists (15 points). Consider the following Java class, which implements a linked list data structure: public class Test { private Node start; private Node finish; private class Node { private int key; private Node next; public Node(int key) { this.key = key; this.next = null; public Test() { start = null; finish = null; // Instance methods A(), B(), C(), D(), E(). Answer the questions on the following page about these five instance methods for this class: public void A(int key) public void D() { { Node x = new Node(key); if (start == finish) if (start == null) start = finish = null; start = x; else else finish.next = x; { finish = x; Node t = start; while (t.next!= finish) t = t.next; public int B() t.next = null; { return finish.key; finish = t; public void C() public Test E() { { Node t = start; Test two = new Test(); while (t!= null) while (start!= null) { { System.out.print(t.key + " "); two.a(this.b()); t = t.next; this.d(); System.out.println(); return two; 4

(i) (10 points) Match each instance method with one of the descriptions below by writing its letter in the blank to the left of the corresponding description. Since there are twice as many descriptions as instance methods, you must leave five options blank. C Prints the list in order Prints the list in reverse order Adds a key at the beginning of the list A Adds a key to the end of the list Copies the list in order E Copies the list in reverse order Returns the key in the first element of the list B Returns the key in the last element of the list Removes the first element of the list D Removes the last element in the list (ii) (5 points) In the space provided, write the output produced by the following code: Test test = new Test(); test.a(1); test.a(7); test.a(4); test.a(9); test.c(); test.d(); (test.e()).c(); first line of output: 1 7 4 9 second line of output: 4 7 1 5

4. ADTs and APIs (10 points). Complete the following API for a StringSET abstract data type by filling in the blanks to the left of the given method descriptions with full method signatures. (one answer is provided for you). For each method you must provide a return type (if any), name, parameter types, and parameter names. Method names are your choice, but each name should clearly and succinctly identify the behavior of its method. public class StringSET public StringSET() constructor; initialize to empty set public void add(string s) add the given string to the set public void remove(string s) remove the given string from the set public boolean contains(string s) return true if the given string is in the set; false otherwise. public StringSET union(stringset s) return the union of this set and the given set public StringSET intersect(stringset s) return the intersection of this set and the given set 6

5. Mergesort (10 points). Consider the following implementation of recursive mergesort: public class Mergesort { public static void sort(comparable[] a, Comparable[] aux, int lo, int hi) { if (hi - lo <= 1) return; int mid = lo + (hi - lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid, hi); merge(a, aux, lo, mid, hi); // merges 2 sorted subarrays into a[lo..hi-1]. System.out.print(lo + " " + hi + " "); for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); public static void sort(comparable[] a) { int N = a.length; Comparable[] aux = new Comparable[N]; sort(a, aux, 0, N); Note that the last three lines of the recursive method have been instrumented to print the values of the indices and the contents of the array. Give the output produced by these methods when invoked by the following code (the first line is filled in for you): Character[] a = { 'y', 'i', 'b', 'w', 'l', 'o', 'l' ; Mergesort.sort(a); 1 3 y b i w l o l 0 3 b i y w l o l 3 5 b i y l w o l 5 7 b i y l w l o 3 7 b i y l l o w 0 7 b i l l o w y 7

6. Architecture (6 points). Suppose that we plan to expand the TOY architecture to support 22-bit instructions (rather than 16-bit instructions) with the following format: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Format 1: opcode destination d source s source t Format 2: opcode destination d - - - - - address - - - - - Answer the three questions below, by writing one of the following numbers in the blank to the right of each question: 2, 4, 8, 12, 16, 22, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384. (i) How many different opcodes can be encoded? 16 (ii) How many registers could the machine have? 64 (iii) How many words could the addressable memory have? 4096 7. Circuits (8 points). In the space to the right, give the truth table for the Boolean function computed by the following circuit: x y z op --------------------- ---- 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 8

8. Theory (12 points). In the blanks, mark each of the statements below as true (T) or false (F). A. T Your iphone is equivalent to a Universal Turing Machine (UTM). B. F Any app on your iphone is equivalent to a UTM. C. T A UTM can simulate the operation of any Turing machine, including itself. D. T If P=NP, there is no problem that is in NP but is not NP-complete. E. T A UTM can decide whether a given string is in the language described by a given regular expression. F. F No Turing machine can decide whether a given DFA halts. 9. Church-Turing Thesis (6 points). In the blanks, mark each of the statements about the Church-Turing thesis below as true (T) or false (F). A. T The Church-Turing thesis is a theory about our universe: it cannot be proven mathematically. B. T The Church-Turing thesis implies that no computer can solve the halting problem. C. T The Church-Turing thesis implies that there is no need to investigate computational limits for every computer individually. 9

10. TSP performance (5 points). Suppose that we have a program that finds a solution to the traveling salesperson problem which takes 1000 seconds to find an optimal solution for a 1000-city tour, and, for an N-city tour, we suspect it takes time proportional to. How much time should we estimate for an optimal 2000-city tour? You may use a power of two in your answer an answer of the form is preferred. 1000 * 2 ^ 1000 seconds. 11. Debugging (5 points) Do not attempt this question until you have completed the rest of the exam, as it may take too much time. One of the instance methods in question 3 has a bug (an error that could cause a run-time exception). In the space provided, briefly describe the bug and write the name of the method. description of bug: if finish is null, finish.key will cause a null pointer exception. method with bug: B 10