CSE 143 Sample Midterm Exam #7 (11wi)

Similar documents
CSE 143 Sample Midterm Exam #1

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

CSE 143 Sample Midterm Exam #8 (12wi)

CSE 143 Sample Midterm Exam #4

CSE 143, Winter 2009 Sample Midterm Exam #2

CSE 143 Section Handout #13 Practice Midterm #5

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

CSE 143 SAMPLE MIDTERM

CSE 143 SAMPLE MIDTERM SOLUTION

CSE 143: Computer Programming II Spring 2015 Midterm Exam Solutions

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

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

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

CSE 143 Sample Final Exam #5

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

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

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

CSE 143 Lecture 10. Recursion

CSE 143 Sample Final Exam #3

CS 314 Exam 2 Spring 2016

CSE 143, Winter 2010 Midterm Exam Key

CS 314 Exam 2 Spring

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

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

This exam is open book. Each question is worth 3 points.

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

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(); }

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

CS 367: Introduction to Data Structures Midterm Sample Questions

1. Write the output generated by the following code. (8pts) 2. Write the output generated by the following code (8pts)

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

MIDTERM WEEK - 9. Question 1 : Implement a MyQueue class which implements a queue using two stacks.

CS61BL Summer 2013 Midterm 2

CSE 143. Lecture 4: Stacks and Queues

C Sc 227 Practice Test 2 Section Leader Name 134pts

Announcements. Recursion and why study it. Recursive programming. Recursion basic idea

Data Structure (CS301)

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

Building Java Programs

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

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

Facebook. / \ / \ / \ Accenture Nintendo

Stacks Fall 2018 Margaret Reid-Miller

Queues. Stacks and Queues

Lecture 19: Recursion

CSE 143 Sample Final Exam #1

Linked Structures. See Section 3.2 of the text.

CSE 143 Practice Final Exam #0

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

Csci 102: Sample Exam

CSE413 Midterm. Question Max Points Total 100

CS 314 Exam 2 Fall 2017

Practice Midterm Exam #1

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

Largest Online Community of VU Students

CS165 Practice Final Exam

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

C Sc 227 Practice Test 2 Section Leader Name 134pts ANSWERS

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

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

1. Stack Implementation Using 1D Array

CS 307 Midterm 2 Spring 2008

Linked Lists. References and objects

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2013

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

You must bring your ID to the exam.

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

Basic Data Structures

CS171 Midterm Exam. October 29, Name:

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

CSE 143 Lecture 3. More ArrayList; object-oriented programming. reading: 10.1;

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

THE UNIVERSITY OF WESTERN AUSTRALIA

Data Structures and Algorithms Winter Semester

CIS Fall Data Structures Midterm exam 10/16/2012

Array Based Lists. Collections

Basic Data Structures 1 / 24

DM537 Object-Oriented Programming. Peter Schneider-Kamp.

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS165 Practice Final Exam Answer Key

CS 307 Final Spring 2011

Queues Fall 2018 Margaret Reid-Miller

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.

The examination is open-book, and you may make use of any texts, handouts, or course notes. You may not, however, use a computer of any kind.

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

CSE 143 Lecture 4. Preconditions

CMPT 125: Practice Midterm Answer Key

COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)

Maximum Grade: 5 points out of 10 of the exam.

CS 314 Exam 2 Spring 2018

CS 307 Final Fall 2009

CSE 143X. Accelerated Computer Programming I/II

CSE wi: Practice Midterm

COS 226 Algorithms and Data Structures Fall Midterm

CS 314 Midterm 2 Spring 2013

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,

CSE 143: Computer Programming II Autumn Sample Solutions

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

Section 05: Midterm Review

Transcription:

CSE 143 Sample Midterm Exam #7 (11wi) 1. ArrayList Mystery Write the output produced by the following method when passed each of the following ArrayLists: public static void mystery(arraylist<integer> list) { for (int i = 0; i < list.size(); i++) { int n = list.get(i); if (n % 10 == 0) { list.remove(i); list.add(n); System.out.println(list); List Output a) [1, 20, 3, 40] b) [80, 3, 40, 20, 7] c) [40, 20, 60, 1, 80, 30] 2. Recursive Tracing Write the output produced by the following recursive method when passed each of the following integer parameters: public static void mystery(int n) { if (n <= 1) { System.out.print(": "); else { System.out.print((n % 2) + " "); mystery(n / 2); System.out.print(n + " "); Call Result a) mystery(8); b) mystery(25); c) mystery(46); 1 of 5

3. Stacks and Queues Write a method reversefirstk that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order. For example, suppose a variable q stores the following elements: front [10, 20, 30, 40, 50, 60, 70, 80, 90] back The call of reversefirstk(4, q); should change the queue to store the following elements in this order: front [40, 30, 20, 10, 50, 60, 70, 80, 90] back If k is 0 or negative, no change should be made to the queue. If the queue passed is null or does not contain at least k elements, your method should throw an IllegalArgumentException. 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) {... 2 of 5

4. Collections Write a method duplicatevalues that accepts a Map from strings to strings as a parameter and returns a count of how many values in the map are duplicates of another value in the map. For example, if a variable named map contains the following key/value pairs: {Marty=Stepp, Jessica=Miller, Mike=Stepp, Stuart=Reges, James=Hale, Amanda=Camp, Hal=Perkins, Biz=Camp, Kendrick=Perkins, Sam=Perkins, Eve=Riskin, Jane=Perkins In the above map, there are two occurrences of the value Stepp, so one (1) of them is a duplicate; there are two occurrences of the value Camp, so one (1) of them is a duplicate; and there are four occurrences of the value Perkins, so three (3) of them are duplicates. Therefore the call of duplicatevalues(map) would return 1+1+3 = 5. (One way of thinking of it is that we could hypothetically remove 1 occurrence of Stepp, 1 occurrence of Camp, and 3 occurrences of Perkins; and those values would still be represented in the map.) If the map contains no duplicate values or contains no values at all, your method should return 0. Note that we are asking about duplicate values, not keys. You should not make any assumptions about the order in which the keys or values appear in the map. You may assume that the map is not null and that none of its keys or values are null strings. You may create only up to two (2) new data structures of your choice (list, stack, queue, set, map, array, etc.) as auxiliary storage. (You can have as many simple variables as you like.) Your solution should run in strictly less than O(N 2 ) time, where N is the number of pairs in the map. You should not modify the contents of the map passed to your method. 3 of 5

5. Linked Lists Write a method fronttoback that could be added to the LinkedIntList class that moves the first element of the list to the back end of the list. Suppose a LinkedIntList variable named list stores the following elements from front to back: [18, 4, 27, 9, 54, 5, 63] If you made the call of list.fronttoback();, the list would then store the elements in this order: [4, 27, 9, 54, 5, 63, 18] If the list is empty or has just one element, its contents should not be modified. 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. Do not mutate the data of any existing node; change the list only by modifying links between nodes. 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;... 4 of 5

6. Recursion Programming Write a recursive method largestdigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your method should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. The following table shows several example calls: Call Returns largestdigit(14263203) 6 largestdigit(845) 8 largestdigit(52649) 9 largestdigit(3) 3 largestdigit(0) 0 largestdigit(-573026) 7 largestdigit(-2) 2 For full credit, obey the following restrictions in your solution. A solution that disobeys them may get partial credit. You may not use a String, Scanner, array, or any data structure (list, stack, map, etc.). Your method must be recursive and not use any loops (for, while, etc.). Your solution should run in no worse than O(N) time, where N is the number of digits in the number. 5 of 5