CS314 Exam 1 - Fall Suggested Solution and Criteria 1

Similar documents
CS314 Exam 2 - Fall 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 2 - Spring Suggested Solution and Criteria 1

CS314 Exam 2 - Spring Suggested Solution and Criteria 1

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

CS314 Exam 1 - Fall Suggested Solution and Criteria 1

CS314 Final - Fall Suggested Solution and Criteria 1

CS314 Final - Spring Suggested Solution and Criteria 1

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

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 - Spring Suggested Solution and Criteria 1

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

CS314 Fall 2011 Midterm 1 Solution and Grading Criteria.

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 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. 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 Spring

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

CS 312 Midterm 2 Fall 2013

CS 314 Exam 2 Spring 2018

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

Largest Online Community of VU Students

CS61BL Summer 2013 Midterm 2


CS 216 Exam 1 Fall SOLUTION

CS 314 Exam 2 Fall 2017

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

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

We've tried to include the common errors and grading standard for every question.

CS 307 Final Fall 2009

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

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

COMP 202 Recursion. CONTENTS: Recursion. COMP Recursion 1

Summer Final Exam Review Session August 5, 2009

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Principles of Computer Science

void insert( Type const & ) void push_front( Type const & )

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

CS 3114 Data Structures and Algorithms DRAFT Project 2: BST Generic

Project Compiler. CS031 TA Help Session November 28, 2011

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

Data Structure (CS301)

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

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

CS 142 Style Guide Grading and Details

CS 455 Final Exam Fall 2015 [Bono] Dec. 15, 2015

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

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

[2:3] Linked Lists, Stacks, Queues

Computer Science Foundation Exam

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

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

More Data Structures (Part 1) Stacks

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

CSCE 2014 Final Exam Spring Version A

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

CS 314 Midterm 2 Fall 2012

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

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

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

CS165 Practice Midterm Problems Fall 2018

CS 314 Exam 2 Spring 2016

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

CS 3114 Data Structures and Algorithms READ THIS NOW!

CS 307 Midterm 2 Spring 2008

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011

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

Second Examination Solution

CIS 120 Midterm II March 29, 2013 SOLUTIONS

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CSCI E-119 Section Notes. Section 5 Solutions

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

"apple" "grape" "grape" "grape" "apple"

Computer Science Foundation Exam

Model Solutions. COMP 103: Test May, 2013

1) Holiday Lights 30 Points

Graphs & Digraphs Tuesday, November 06, 2007

CS 312 Midterm 2 Fall Jose Stas Aaron

CS 307 Final Spring 2011

ITEC2620 Introduction to Data Structures

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

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

If you took your exam home last time, I will still regrade it if you want.

TREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

(Refer Slide Time: 06:01)

Programming II (CS300)

CS 104 (Spring 2014) Final Exam 05/09/2014

Programming Assignment 2

MIT AITI Lecture 18 Collections - Part 1

CSE 143 Sample Final Exam #5

Csci 102: Sample Exam

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Transcription:

CS314 fall 2016 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. 36 B. 6 5 =4= 3 2 (differences in spaces okay) C. 23 D. -516-8-4-2-1 (ignore dashes) E. O(N 2 ) F. O(N 2 ) G. 15 10 6 (on different or same line) H. 6 I. 40 minutes J. 42 seconds K. 15 7 3 L..88 seconds M. two of: - has one or more abstract methods - implements an interface but doesn't implement all methods of interface - inherits from an abstract class with abstract methods and doesn't implement those methods N. beginning of list should be top of stack O..01 seconds (maketree is O(N) in this case, adding N duplicates) P. 3 Q. 5 0 7 4 8 9 2 R. 0 4 7 8 5 9 2 S. 4 8 7 0 2 9 5 T. 24 / \ 0 30 \ / 10 29 \ 15 / \ 13 19 CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 1

2. Comments. A simple linked list question. Students did quite well on this question using disallowed methods. equals was the only method that could be used not using compareto correctly assuming compareto returns only -1, 0, or 1 public void replacesmaller(linkedlist314<e> otherlist) { Node<E> t1 = first; Node<E> t2 = otherlist.first; while( t1!= null && t2!= null) { if (t1.data.compareto(t2.data) < 0) { t1.data = t2.data; t1 = t1.next; t2 = t2.next; 16 points, Criteria: temp nodes for each list, 1 point while loop correct, 5 points check and replace smaller element in this correctly, 4 points traverse through nodes in list correctly, 6 points Usage errors: using disallowed methods, -6 adds public method to get first, -5 off by one errors, - 3 CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 2

3. Comments: A more difficult LinkedList question. Lots of special cases to worry about. if number to remove is 0, there is nothing to do. Don't waste time moving through the linked list if number is 0 not handling the case when start is 0 and first must be updated off by one errors when removing nodes not guarding against number being larger than the number of nodes we can actually remove using disallowed methods moving to node at position start instead of start - 1. The node at position start is to be removed. public int removenum(int start, int number) { int count = 0; if (number > 0) { // actually have to remove some nodes if (start == 0) { // handle case when must update first while (first!= null && count < number) { first = first.next; count++; else { // general case, must get to start node Node<E> temp = first; for (int i = 1; i < start; i++) temp = temp.next; // temp now on node at position start - 1; while (temp.next!= null && count < number) { temp.next = temp.next.next; count++; return count; efficiency, do nothing if number == 0, 2 points handle case when start = 0 and first must be updated, 3 points got to correct node in list (the one before start), 4 points remove correct nodes, 5 points calculate number of node removed, 1 point return correct result, 1 point Other deductions: CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 3

4. Comments: An interesting Stack problem. Allowing use of Stack or Queue made it harder. In order to solve the problem correctly it is necessary to use a Stack, not a Queue. Part of the question was realizing this. There is also a special case when the Stack is empty and we cannot remove any elements. popping or topping an empty stack using a queue comparing to the original top element only instead of the element above. So for example some people simply stored the top element and compared to that. So top [12, 5, 8] bottom. The 8 must be removed because it is not less than or equal to 5. Comparing it to 12, the original top, is a logic error. Suggested Solution: public void makedescending(stack314<integer> st) { if (!st.isempty()) { Stack314<Integer> temp = new Stack314<Integer>(); temp.push(st.pop()); // we know not empty while (!st.isempty()) { int x = st.pop(); if (x <= temp.top()) { temp.push(x); while (!temp.isempty()) { st.push(temp.pop()); handle empty case correctly, 4 points (lose if possible to top or pop empty stack) process elements in st with while loop, 2 points check if element to be added to temp correctly and push, 3 points restore elements from temp to st, 3 points element in correct order, uses stack, 4 points Others: CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 4

5. Comments: A simple tree problem when a node met the criteria NOT exploring its left child not handling empty tree case using while loops instead of recursion. (not possible without aux data structures) not using equals method to check data not checking all three conditions for counting node met trying to use a parameter to track the count. Recall, value parameters. If we make a copy and increment that it does not alter the original argument. Not passing the value to check as a parameter. Suggested Solution: public int numnodeswithvalueandleftchildonly(e value) { return help(root, value); private int help(bnode<e> n, E value) { if (n == null) { // dead end, nothing to see here return 0; else if (n.left!= null && n.right == null && value.equals(n.data) { // We have a winner! Count this one and check left child. // No need to check right, because it is null return 1 + help(n.left, value); else { // Whelp, this node didn't meet the criteria, just check children return help(n.left, value) + help(n.right, value); create helper method with proper parameters, 3 points handle base case of empty tree / n == null, 4 points check if current node meets criteria correctly and return correct result, 4 points recursive calls correct in all cases, 4 points return correct, int result, 1 point Other: not handling empty tree case / NPE possible, -3 not using.equals -3 major logic error with while loops, -12 CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 5

6. Comments: Not the hardest recursive backtracking question in the world, especially as the magic board class finds all the valid moves for you. It was acceptable to alter the permanently, not undo the correct moves. No helper method was necessary. base case of 0 marbles on the board. This is not possible unless the board starts with 0 marbles. A solution is one marble is left on the board. It is not possible to go from a board with 1 marble to one with 0. Only using the moves from the first board configuration. Trying to track the index to start at for the moves. The moves for each board will be different and so we must start at 0 for each array of moves not undoing the move if a solution no reached. returning early instead of only returning if result is true not returning true as soon as we get that value. If we have solved the puzzle lets not waste any more time. We are done. Pop, pop, pop the champagne corks. Suggested Solution: public boolean canbesolved(board board) { if (board.nummarblesonboard() == 1) { return true; // HOORAY!!! Move[] moves = board.getmoves(); // current choices are the moves for this board for (int i = 0; i < moves.length; i++) { Move m = moves[i]; // make current move board.removemarble(m.sourcerow(), m.sourcecol()); board.removemarble(m.removedrow(), m.removedcol()); board.placemarble(m.destrow(), m.destcol()); if (canbesolved(board)) { // done!!! return true; // that didn't work out, undo it so we can try the next one board.placemarble(m.sourcerow(), m.sourcecol()); board.placemarble(m.removedrow(), m.removedcol()); board.removemarble(m.destrow(), m.destcol()); // never found a solution with these choices. return false; correct base case, 4 points loop through correct choices, 2 points move marbles correctly, 1 point make correct recursive call, 4 points return true if solved with this move, 3 points return false if no moves worked out, 2 points CS314 Exam 1 - Fall 2016 - Suggested Solution and Criteria 6