CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

Similar documents
CSE 143 Sample Midterm Exam #7 (11wi)

CSE 143 Sample Midterm Exam #1

CSE 143 Sample Midterm Exam #8 (12wi)

CSE 143 Section Handout #13 Practice Midterm #5

CSE 143 Sample Midterm Exam #4

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

CSE 143, Winter 2009 Sample Midterm Exam #2

CSE 143, Winter 2009 Final Exam Thursday, March 19, 2009

CSE143 Midterm Summer Name of Student: Section (e.g., AA): Student Number:

CSE 143, Winter 2010 Final Exam Thursday, March 18, 2010

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

CSE 373, Winter 2013 Final Exam, Tuesday, March 19, Good luck! You can do it!

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

CSE 143 SAMPLE MIDTERM

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CSE 142, Summer 2010 Midterm Exam, Friday, July 30, 2010

CSE 143 SAMPLE MIDTERM SOLUTION

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules:

CSE 142, Spring 2009, Final Exam

CSE 142, Autumn 2010 Final Exam Wednesday, December 15, Name:

CSE 143 Sample Final Exam #3

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CSE 143: Computer Programming II Autumn Sample Solutions

CSE 142, Winter 2007 Final Exam. Name:

CSE 143: Computer Programming II Spring 2015 Final Exam Solutions

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

CSE 143, Winter 2010 Midterm Exam Key

CSE 143 Sample Final Exam #5

CS 106B Practice Midterm Exam #1 (by Marty Stepp)

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS 367: Introduction to Data Structures Midterm Sample Questions

Points off Total off Net Score. CS 314 Final Exam Spring 2016

CSE 143 Lecture 10. Recursion

CSE 143 Sample Final Exam #1

CS 307 Midterm 2 Spring 2008

C Sc 227 Practice Test 2 Section Leader Your Name 100pts. a. 1D array b. PriorityList<E> c. ArrayPriorityList<E>

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

CS 314 Exam 2 Spring 2016

CSE143 Summer 2008 Final Exam Part A KEY August 21, 2008

CS 314 Exam 2 Spring

CS171 Midterm Exam. October 29, Name:

Computer Sciences 302 Exam 2 Information & Sample Exam

Facebook. / \ / \ / \ Accenture Nintendo

1. (9 points) Recall the definition of the ListNode class: public class ListNode { int data; ListNode next; }

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

1. Binary Tree Traversal. 2. Binary Search Tree. 1 of 12. Consider the following tree: Pre-order: In-order: Post-order:

Midterm Exam 2 CS 455, Spring 2011

CSE 143. Lecture 4: Stacks and Queues

You must bring your ID to the exam.

CS165 Practice Final Exam

CSE 143. Lecture 9: introduction to recursion reading: 12.1

Adam Blank Lecture 5 Winter 2015 CSE 143. Computer Programming II

CS 307 Final Spring 2011

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 154, Autumn 2012 Final Exam, Thursday, December 13, 2012

Data Structures and Algorithms Winter Semester

CS1020: DATA STRUCTURES AND ALGORITHMS I

final int a = 10; for(int i=0;i<a;i+=2) { for(int j=i;j<a;j++) { System.out.print("*"); } System.out.println(); }

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

CS 314 Midterm 2 Fall 2012

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

Problem Description Earned Max 1 PHP 25 2 JavaScript/DOM 25 3 Regular Expressions 25 4 SQL 25 TOTAL Total Points 100

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

Points off A 4B 5 Total off Net Score. CS 314 Final Exam Spring 2015

Recursion. Garfield AP Computer Science. As usual, significant borrowings from Stuart Reges and Marty Stepp at UW -- thanks!!

CSE143 Summer 2008 Final Exam Part B KEY August 22, 2008

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

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

Practice Midterm Exam #1

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

Lecture 19: Recursion

Recursion. Chapter Simple Recursion. Goals Trace recursive algorithms Implement recursive algorithms

CIS 110 Introduction to Computer Programming Summer 2018 Final. Recitation # (e.g., 201):

CS165 Practice Final Exam Answer Key

UNIVERSITY REGULATIONS

Midterm Exam 2 CS 455, Spring 2014

CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination

Data Structure (CS301)

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

C Sc 127B Practice Test 2 Section Leader Your Name 100pts

CSE 143. Lecture 7: Linked List Basics reading: 16.2

Csci 102: Sample Exam

CS 314 Midterm 2 Spring 2013

CS 216 Exam 1 Fall SOLUTION

CS 314 Exam 2 Spring 2018

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Midterm Exam 2 CS 455, Spring 2015

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSE373 Fall 2013, Midterm Examination October 18, 2013

Student Number: Lab day:

THE UNIVERSITY OF WESTERN AUSTRALIA

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

Transcription:

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010 Personal Information: Name: Section: Student ID #: TA: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor calls for papers. This exam is open-book/notes. You may not use any computing devices including calculators. Code will be graded on proper behavior/output and not on style, unless otherwise indicated. Do not abbreviate code, such as "ditto" marks or dot-dot-dot... marks. The only abbreviations that are allowed for this exam are: S.o.p for System.out.print, and S.o.pln for System.out.println. You do not need to write import statements in your code. If you enter the room, you must turn in an exam before leaving the room. You must show your Student ID to a TA or instructor for your exam to be accepted. Good luck! Score summary: (for grader only) Problem Description Earned Max 1 ArrayList Mystery 20 2 Recursive Tracing 20 3 Comparable 15 4 Stacks and Queues 15 5 Collections 15 6 Linked Lists 15 TOTAL Total Points 100 1 of 6

1. ArrayList Mystery Consider the following method: public static void mystery(arraylist<integer> list) { for (int i = 1; i < list.size(); i += 2) { if (list.get(i - 1) >= list.get(i)) { list.remove(i); list.add(0, 0); System.out.println(list); Write the output produced by the method when passed each of the following ArrayLists: List a) [10, 20, 10, 5] Output b) [8, 2, 9, 7, -1, 55] c) [0, 16, 9, 1, 64, 25, 25, 14, 0] 2. Recursive Tracing For each of the calls to the following recursive method below, indicate what value is returned: public static int mystery(int n, int k) { if (k == 0 k == n) { return 1; else if (k > n) { return 0; else { return mystery(n - 1, k - 1) + mystery(n - 1, k); Call Returns a) mystery(7, 1) b) mystery(4, 2) c) mystery(4, 3) d) mystery(5, 3) e) mystery(5, 4) 2 of 6

3. Comparable Suppose you have a pre-existing class Dieter that models a person trying to monitor diet and weight to improve his/her Body Mass Index (BMI) rating. The class has the following data and behavior: Field/Constructor/Method private String name private int height private int weight public Dieter(String name, int h, int w) public String getname() public int getheight() public int getweight() public double getbmi() public void gain(int pounds) public void lose(int pounds) Description the dieter's full name, such as "John Smith" the dieter's height, in inches the dieter's weight, in pounds makes a dieter with given name, height, weight returns the dieter's name returns the dieter's height returns the dieter's weight computes the dieter's Body Mass Index (BMI), which is (weight / height 2 ) 703 called when the dieter gains weight called when the dieter loses weight Make Dieter objects comparable to each other using the Comparable interface. Add any necessary code below, and/or make any changes to the existing code headings shown. Dieters are primarily compared by their BMI ratings; a dieter with a lower BMI is "less than" one with a higher BMI. If two dieters have the same BMI, the tie is broken by height; the shorter person is considered to be "less than" the taller one. If two dieters have the same BMI and height, the tie is broken by name. The dieter whose name comes first in alphabetical order is considered "less than" the one whose name comes later in ABC order. If the two dieters have the same BMI, height, and name, they are considered to be "equal." Your method should not modify any dieter's state. You may assume the parameter passed is not null. public class Dieter {... // write any added code here 3 of 6

4. Stacks and Queues Write a method expunge that accepts a stack of integers as a parameter and makes sure that the stack's elements are in ascending order from top to bottom, by removing from the stack any element that is smaller than any element(s) on top of it. For example, suppose a variable s stores the following elements: bottom [4, 20, 15, 15, 8, 5, 7, 12, 3, 10, 5, 0] top The element values 3, 7, 5, 8, and 4 should be removed because each has an element above it with a larger value. So the call of expunge(s); should change the stack to store the following elements in this order: bottom [20, 15, 15, 12, 10, 5, 0] top Notice that now the elements are in non-decreasing order from top to bottom. If the stack is empty or has just one element, nothing changes. You may assume that the stack passed is not null. (Hint: An element e that should be removed is one that is smaller than some element above e. But since the elements above e are in sorted order, you may not need to examine all elements above e in order to know whether to remove e.) For full credit, obey the following restrictions in your solution. A solution that disobeys them can get partial credit. You may use one queue or stack (but not both) as auxiliary storage. You may not use other structures (arrays, lists, etc.), but you can have as many simple variables as you like. Use the Queue interface and Stack/LinkedList classes discussed in lecture. Use stacks/queues in stack/queue-like ways only. Do not call index-based methods such as get, search, or set (or for-each) on a stack/queue. You may call only add, remove, push, pop, peek, isempty, and size. You have access to the following two methods and may call them as needed to help you solve the problem: public static void s2q(stack<integer> s, Queue<Integer> q) {... public static void q2s(queue<integer> q, Stack<Integer> s) {... 4 of 6

5. Collections Write a method commonfirstletters that accepts a list of strings as a parameter, and returns a Set of strings. Your method should examine the strings in the list passed and return a set of all first letters that occur more than once. In other words, if two or more strings in the list begin with a particular character (case-insensitively), that letter should be part of the set that you return. Consider a list variable called list containing the following elements: ["hi", "how", "is", "He", "Marty!", "this", "morning?", "fine.", "?huh?", "HOW", "I"] One word in the list begins with "f", four begin with "h", two begin with "i", two begin with "m", one begins with "t", and one begins with "?". Therefore the set you return should contain the following elements: ["h", "i", "m"] If no first character occurs 2 or more times, return an empty set. The order the elements appear in the set does not matter. You may assume that the list passed is not null and that none of its elements are null or empty strings. For full credit, obey the following restrictions in your solution. A solution that disobeys them can get partial credit. You may create only up to two (2) new data structures of your choice (list, stack, queue, set, map, etc.) as auxiliary storage. (You can have as many simple variables as you like.) Your solution should run in less than O(N 2 ) time, where N is the number of strings in the list. You should not modify the contents of the list passed to your method. 5 of 6

6. Linked Lists Write a method removemin that could be added to the LinkedIntList class that removes the smallest element value from the linked list. Suppose a LinkedIntList variable named list stores the following elements: [8, 4, 7, 2, 9, 4, 5, 3] If you made the call of list.removemin();, the list would then store the elements: [8, 4, 7, 9, 4, 5, 3] If the list has more than one occurrence of the minimum value, the first occurrence is the one that should be removed. For example, [8, 10, 13, 8, 8, 14, 9, 8, 11] becomes [10, 13, 8, 8, 14, 9, 8, 11]. If the list is empty, you should throw a NoSuchElementException. For full credit, obey the following restrictions in your solution. A solution that disobeys them can get partial credit. Do not call any other methods on the LinkedIntList object, such as add, remove, or size. Do not create new ListNode objects (though you may have as many ListNode variables as you like). Do not use other data structures such as arrays, lists, queues, etc. Your solution should run in O(N) time, where N is the number of elements of the linked list. Assume that you are adding this method to the LinkedIntList class (that uses the ListNode class) below. public class LinkedIntList { public class ListNode { private ListNode front; public int data;... public ListNode next;... 6 of 6