CS314 Exam 2 - Fall Suggested Solution and Criteria 1

Similar documents
CS314 Exam 1 - Fall Suggested Solution and Criteria 1

CS314 Exam 2 - Spring Suggested Solution and Criteria 1

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces.

CS314 Exam 1 - Fall Suggested Solution and Criteria 1

for dequeue will be O(N). (Or words to that effect. Needed to mention both or -1.)

CS314 Final - Fall Suggested Solution and Criteria 1

CS314 Exam 2 - Spring Suggested Solution and Criteria 1

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces

CS314 Spring 2014 Midterm 1 Solution and Grading Criteria.

1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces

1. Answer as shown or -2 unless question allows partial credit. No points off for differences in spacing, capitalization, commas, and braces

CS314 Exam 1 - Spring Suggested Solution and Criteria 1

CS314 Final - Spring Suggested Solution and Criteria 1

1. Code Trace: 2. Program Logic (0.5 each) X <= y y > z x == 1 A S N S N S A A N S S S S A S POINT A POINT B POINT C POINT D POINT E

CS314 Fall 2011 Midterm 1 Solution and Grading Criteria.

1. Answer as shown or -2 unless question allows partial credit. No points off for differences in spacing, capitalization, commas, and braces

1. Expressions - 1 point each. -1 for missing or extra " OR.0. differences in capitalization of true and false okay. No limit on points off.

CS314 Fall 2012 Midterm 1 Solution and Grading Criteria.

Fall_2010_M1_SuggestedSolutioAndGradingCrit.txt 10/8/2010

D. Do inorder traversal on tree, values in ascending order, no repeats.

CS 314 Exam 2 Fall 2017

CS 312 Midterm 2 Fall 2013

CS 314 Exam 2 Spring

We have the pointers reference the next node in an inorder traversal; called threads

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

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

CSE373 Fall 2013, Midterm Examination October 18, 2013

CS 314 Exam 2 Spring 2018

Points off Total off Net Score. CS 314 Final Exam Spring Your Name Your UTEID

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

CS 216 Exam 1 Fall SOLUTION

CS 307 Midterm 2 Fall 2010

CS 314 Final Spring 2013 SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION - SOLUTION

CS 307 Midterm 2 Spring 2011

Computer Science Foundation Exam

DIT960 Datastrukturer

CS 307 Midterm 2 Fall 2008

CS 314 Exam 2 Spring 2016

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

Principles of Computer Science

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CS 314 Final Fall 2011

CS 314 Final Fall 2012

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

CS 307 Final Fall 2009

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Computer Science II Fall 2009

Computer Science Foundation Exam

In addition to the correct answer, you MUST show all your work in order to receive full credit.

Second Examination Solution

CS 307 Midterm 2 Spring 2008

Generic BST Interface

CMPSCI 187 Midterm 1 (Feb 17, 2016)

CS 314 Midterm 2 Fall 2012

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

CS 307 Final Spring 2009

More loops Ch

Largest Online Community of VU Students

Week 2. TA Lab Consulting - See schedule (cs400 home pages) Peer Mentoring available - Friday 8am-12pm, 12:15-1:30pm in 1289CS

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

CSCE 2014 Final Exam Spring Version A

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

Name CPTR246 Spring '17 (100 total points) Exam 3

ECE264 Spring 2013 Final Exam, April 30, 2013

Flow Control. CSC215 Lecture

Summer Final Exam Review Session August 5, 2009

CPSC 35 Midterm Exam

CS 312 Midterm 2 Fall Jose Stas Aaron

CS61BL Summer 2013 Midterm 2

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

Section 05: Solutions

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

- 1 - Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions. CS106B Spring 2013

CS165 Practice Final Exam Answer Key

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

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

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

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

CS 314 Midterm 2 Spring 2013

CS2110 Assignment 3 Inheritance and Trees, Summer 2008

CSCI 1301: Introduction to Computing and Programming

CS 3114 Data Structures and Algorithms READ THIS NOW!

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

1) Holiday Lights 30 Points

Lab Exercise 8 Binary Search Trees

1B1b Implementing Data Structures Lists, Hash Tables and Trees

CS18000: Programming I

Fun facts about recursion

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CIT-590 Final Exam. Name: Penn Key (Not ID number): If you write a number above, you will lose 1 point

Sample Questions for Midterm Exam 2

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

CS171 Final Practice Exam

CS 61B Asymptotic Analysis Fall 2018

BINARY TREES, THE SEARCH TREE ADT BINARY SEARCH TREES, RED BLACK TREES, TREE TRAVERSALS, B TREES WEEK - 6

EECS 311 Data Structures Midterm Exam Don t Panic!

CSE373 Winter 2014, Midterm Examination January 29, 2014

CS 415 Midterm Exam Fall 2003

Practice exam for CMSC131-04, Fall 2017

Transcription:

CS314 Fall 2017 Exam 2 Solution and Grading Criteria. Grading acronyms: AIOBE - Array Index out of Bounds Exception may occur BOD - Benefit of the Doubt. Not certain code works, but, can't prove otherwise Gacky or Gack - Code very hard to understand even though it works. (Solution is not elegant.) LE - Logic error in code. NAP - No answer provided. No answer given on test NN - Not necessary. Code is unneeded. Generally, no points off NPE - Null Pointer Exception may occur OBOE - Off by one error. Calculation is off by one. RTQ - Read the question. Violated restrictions or made incorrect assumption. 1. Answer as shown or -1 unless question allows partial credit. No points off for minor differences in spacing, capitalization, commas, and braces. A. 5 B. 741!-26810 C. 13 D. 42 E. 1000 or 1024 seconds F. 12 seconds (O(N) with LinkedList) G. 500 seconds (O(N 2 ) with ArrayList) H. (syntax error or drawing) -------------> I. O(N 3 ) J. 110 K. 32 seconds (pop is O(N) based on implementation) L. 44 seconds M. 20 seconds N. 4 2 2 6 2 4 8 O. 0 then a runtime error occurs (ClassCastException) P. 4 Q. 12 0-5 20 26 37 25 17 R. 3 S..002 seconds (Method is O(N) due to small number of values) T. 16 seconds (Method is O(N 2 )) Commonly missed questions: D, H, K, O, and R CS314 Exam 2 - Fall 2017 - Suggested Solution and Criteria 1

2. Comments. Meant to be an easy question involving linked lists. Question involves moving through linked lists, but not actually changing them. Common Problems: not checking out of bounds at start and just returning false using nonexistent methods always O(N) instead of stopping at stop index public boolean rangeisequal(linkedlist314<e> other, int start, int stop) { if (stop > this.size stop > other.size) Node<E> n1 = this.first; Node<E> n2 = other.first; for (int i = 0 ; i < start; i++) { n1 = n1.next; n2 = n2.next; int numcheck = stop - start; for (int i = 0; i < numcheck; i++) { if (!n1.data.equals(n2.data)) n1 = n1.next; n2 = n2.next; 20 points, Criteria: if stop out of bounds, return false immediately, 1 point (efficiency) 2 temp nodes, 1 point move both temp nodes to start node, 5 points (off by one -2) loop with correct bounds for checking data in nodes equal, 3 points check data in nodes (not nodes themselves), 3 points use equals correctly, 2 points return false on first mismatch, 2 points move down list correctly when checking data, 2 points return correct answer if same, 1 point Other penalties: using disallowed methods, -8 (can be less for severity) destroy either list, -8 recursive solution with N stack frames -5 (space efficiency) Null Pointer Exceptions -4 use getdata / getnext -2 (just once) off by one errors, -2 CS314 Exam 2 - Fall 2017 - Suggested Solution and Criteria 2

3. Comments: Having to change a linked list. not checking if start == stop and if so doing nothing, NO-OP (no operation) not stopping at node before node at position start not dealing with moving first if start == 0 not updating size. I thought these were easy points and it was mentioned in the post condition public void removerange(int start, int stop) { if (start < stop) { int numremoved = stop - start; if (numremoved == size) // clear whole list. first = null; else if (start == 0) { // special case, removing first node for (int i = 0; i < numremoved; i++) { first = first.next; else { // general case, move to node before start Node<E> n = first; for (int i = 1; i < start; i++) n = n.next; // now remove the right number of nodes for (int i = 0; i < numremoved; i++) n.next = n.next.next; //?? Special case for stop == size?? size -= numremoved; do nothing if start == stop, 2 points special case handled correctly when start == 0, moving first, 4 points general case, move to node before start correctly, 4 points general case, remove correct number of nodes, 6 points update size correctly, 4 points Other penalties: using disallowed methods, -8 (can be less for severity) recursive solution with N stack frames -5 (space efficiency) NullPointerException, -6 infinite loop due to not moving, -6 CS314 Exam 2 - Fall 2017 - Suggested Solution and Criteria 3

4. Comments: Meant to be a simple question involving moving through a binary tree without changing it. returning early not handling case when tree is empty summing 1 or 3 elements instead of parent and child public int parentchildpairswhosesumequals(int tgt) { return help(root, tgt); private int help(bnode n, int tgt) { if (n == null (n.left == null && n.right == null)) return 0; // leaf or empty int result = 0; if (n.left!= null && (n.data + n.left.data == tgt)) result++; if (n.right!= null && (n.data + n.right.data == tgt)){ result++; result += help(n.left, tgt) + help(n.right, tgt); return result; create helper method and start at root node, 2 points correct base case for null or leaf (can handle elsewhere), 5 points non base case, check if left child exists and if sum of parent and child equals target, 2 points (Can handle this possible with parameter) non base case, check if right child exists and if sum of parent and child equals target, 2 points correct recursive calls to left and right child (can skip if don't exist), 5 points return correct value, 4 points (lose if try to store in a parameter only) Others: altering tree, -8 new data structure, -8 early return -5 not handling case when root == null, empty tree, -4 not summing two correct elements, -4 5. Comments: An interesting recursive problem. Note, the choices were what truck to put an item on. The question said no other classes, and this included creating new arrays. Very easy to do this in place. not making success base case all capacity used not returning as soon as answer known (after undoing changes) CS314 Exam 2 - Fall 2017 - Suggested Solution and Criteria 4

not checking option of leaving item off of all trucks no base case for all items tried nested loop in recursive method. Just one loop for truck options not filling in arguments for method call (question said to complete arguments, but not to add any other code) public static boolean canship(int[] trucks, int[] items) { return canshiphelp(trucks, items, 0); private static boolean canshiphelp(int[] trucks, int[] items, int index) { if (allzeros(trucks)) else if (index == items.length) // never found a solution int item = items[index]; for (int i = 0; i < trucks.length; i++) { if (trucks[i] >= item) { // item will fit on truck i trucks[i] -= item; // did we do it? boolean solved = canshiphelp(trucks, items, index + 1); // take item off truck trucks[i] += item; // if we solved it, stop!!! if (solved) // one last chance, don't put item on any truck! return canshiphelp(trucks, items, index + 1); // saw a very nice solution that determined total capacity and // sent and altered that instead of contsantly summing private static boolean allzeros(int[] trucks) { for (int capacityleft : trucks) if (capacityleft > 0) call helper with two arrays and index of current item, 2 points base case when solved problem (no capacity left), 3 points base case when no items left, 2 points recursive case, loop through all the trucks, 3 points only put item on truck if capacity exists, 2 points recursive call if item fits, 3 points remove item from truck after result of recursive call, 2 points (necessary as array must be unchanged) return true when solution found, 2 point return false after trying all choices, 1 points Other: early return, -7, other objects including arrays, -6, not stopping when answer known, -4, stack overflow -7 CS314 Exam 2 - Fall 2017 - Suggested Solution and Criteria 5