Prelim 2. CS 2110, 5:30 PM, November 17, 2016

Similar documents
Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2 SOLUTION. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs. Max Score Grader

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

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Total Score /1 /20 /41 /15 /23 Grader

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

Prelim 2. CS 2110, 24 April 2018, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph.

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

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2. CS 2110, 24 April 2018, 5:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2 Solution. CS 2110, 24 April 2018, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph.

Prelim 2 Solution. CS 2110, 24 April 2018, 5:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

Final exam. CS 2110, December 15, 2016, 9:00AM

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Prelim 1, Solution. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

Prelim 1. CS 2110, 14 March 2017, 5:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

Prelim 1. CS 2110, March 15, 2016, 5:30 PM Total Question Name True False. Short Answer

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

Prelim 2, CS2110. SOLUTION

Final Exam. CS2110 Spring May 12, Total. Max Score

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

ext Total Score /20 /20 /15 /20 /25 /5 Grader

Prelim 1. CS 2110, March 15, 2016, 7:30 PM Total Question Name True False. Short Answer

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

Total Score /15 /20 /30 /10 /5 /20 Grader

Total Score /15 /20 /30 /10 /5 /20 Grader

CS211 Spring 2005 Prelim 2 April 19, Instructions

CS/ENGRD2110: Prelim 2 SOLUTION

CS/ENGRD2110: Final Exam

ASYMPTOTIC COMPLEXITY

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

Final Exam in Algorithms and Data Structures 1 (1DL210)

XC Total Max Score Grader

ASYMPTOTIC COMPLEXITY

Second Examination Solution

Recitation 9. Prelim Review

Final Exam CS 251, Intermediate Programming December 13, 2017

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

Questions Total Points Score

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

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

Exam I Principles of Imperative Computation, Summer 2011 William Lovas. May 27, 2011

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

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Final Exam in Algorithms and Data Structures 1 (1DL210)

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

University of New Mexico Department of Computer Science. Midterm Examination. CS 561 Data Structures and Algorithms Fall, 2013

CS61BL. Lecture 5: Graphs Sorting

Final Exam. COMP Summer I June 26, points

CS 251 Intermediate Programming GUIs: Components and Layout

Do not turn to the next page until the start of the exam.

Test 1 SOLUTIONS. June 10, Answer each question in the space provided or on the back of a page with an indication of where to find the answer.

CSE 2123: Collections: Priority Queues. Jeremy Morris

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Sorting and Searching

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

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

CS 2604 Data Structures Midterm Summer 2000 U T. Do not start the test until instructed to do so!

CS Exam 3 - Spring 2010

1 (5pts) 2 (20 pts) 3 (20 pts) 4 (10 pts) 5 (15 pts) 6 (30 pts) Total NAME: CU ID: Recitation instructor/time

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

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

CS 1110 Final, December 8th, Question Points Score Total: 100

CS 1110 Prelim 2 November 14th, 2013

CS 1110 Prelim 2 April 22, 2014

Lecture 5 Sorting Arrays

Sorting and Searching

Prelim CS410, Summer July 1998 Please note: This exam is closed book, closed note. Sit every-other seat. Put your answers in this exam. The or

CS 1110 Prelim 2 November 6th, 2012

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY. Lecture 11 CS2110 Spring 2016

CS Exam 3 - Spring 2010

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

Preliminary Examination I Computer Science 312, Cornell University 6 March 2003

CS 1110, LAB 12: SEQUENCE ALGORITHMS First Name: Last Name: NetID:

CSE wi Final Exam 3/12/18. Name UW ID#

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

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

ECE368 Exam 2 Spring 2016

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

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

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

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

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

MIT AITI Swing Event Model Lecture 17

CISC 320 Midterm Exam

CS 1110 Final, December 8th, Question Points Score Total: 100

UNIVERSITY REGULATIONS

COS 226 Algorithms and Data Structures Spring Midterm Exam

Midterm solutions. n f 3 (n) = 3

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003

Transcription:

Prelim CS 0, 5:30 PM, November 7, 06 Question Short Graphs Complexity Heaps GUIs Spanning Sorting Total Max 8 8 6 4 0 0 4 00 Score Grader The exam is closed book and closed notes. Do not begin until instructed. You have 90 minutes. Good luck! Write your name and Cornell NetID at the top of every page! There are 7questions on 9 numbered pages, front and back. Check that you have all the pages. When you hand in your exam, make sure your pages are still stapled together. If not, please use our stapler to reattach all your pages! We have scrap paper available. If you do a lot of crossing out and rewriting, you might want to write code on scrap paper first and then copy it to the exam so that we can make sense of what you handed in. Write your answers in the space provided. Ambiguous answers will be considered incorrect. You should be able to fit your answers easily into the space provided. In some places, we have abbreviated or condensed code to reduce the number of pages that must be printed for the exam. In others, code has been obfuscated to make the problem more difficult. This does not mean that its good style. Academic Integrity Statement: unauthorized aid on this exam. I pledge that I have neither given nor received any (signature) of 9

. Short Answer [8 pts] (a) [3 pts] In a model/view/controller, Swing is likely to be part of (there may be more than one): i. the model ii. the view iii. the controller (b) [4 pts] Which of the following must be true (there may be more than one)? i. if x.hashcode() == y.hashcode() then x.equals(y) ii. if x.hashcode() == y.hashcode() then x == y iii. if x.equals(y) then x.hashcode() == y.hashcode() iv. if x == y then x.hashcode() == y.hashcode() (c) [4 pts] A traversal of an expression tree produces the string + + 3 5 4. i. What kind of traversal is it? ii. What is the result of evaluating the expression? (d) [7 pts] Let f(n) ::= n + n log n. Then f(n) is O(g(n)) for which of the following g? Note: there may be more than one. g(n) ::= n log n g(n) ::= n g(n) ::= n g(n) ::= log n g(n) ::= (n + n log n)/ g(n) ::= n + n log n g(n) ::= n + n log n of 9

. Graphs [8 pts] Consider the following graph: A 8 B 4 C 4 5 D G F 5 E (a) [5 pts] List the nodes in the order they would be visited by DFS, starting from A. When there are multiple valid options, list the lower-letter nodes first. (e.g. if you can visit either C or F next, visit C next) (b) [5 pts] List the nodes in the order they would be visited by BFS, starting from A. (c) [5 pts] List the nodes in the order they would be visited by Dijkstra s algorithm, starting from A. Write down the resulting path lengths. [TODO clarification: settled instead of visited ] (d) [3 pts] Is the graph planar? 3 of 9

3. Complexity [6 pts] (a) [4 pts] What is the definition of f(n) is O(g(n))? (b) [6 pts] Prove that n + is O(n ). (c) [6 pts] Give the worst-case and expected case run times of quicksort on an array b of size n. Describe a situation in which it will take the worst-case time. 4 of 9

4. Heaps [4 pts] In this question, you will perform operations on a min-heap in which the values are the priorities. When you change the value of a node, cross out the old value and write the new value next to it. For example, after swapping the root with the left child and then swapping the root with the right child, [TODO there is a typo in the example; should be right then left] becomes 3 3 3 3 If you make a mistake, be sure that you differentiate between the mistake and the values that you are crossing out! (a) [7 pts] Perform poll on the following min-heap: 8 6 9 0 7 0 0 (b) [7 pts] Perform add(5) on the following min-heap: 8 6 9 0 7 0 0 5 of 9

5. GUIs [0 pts] Consider the program on the next page. (a) [5 pts] Draw the GUI resulting from running the program on the following page. (b) [5 pts] The code doesn t work: nothing happens when the button is pressed. Explain why not, and fix it. Hint: this requires a one-line change. Don t worry if you don t remember the exact names of any swing methods you may need. 6 of 9

import javax. swing. ; import java. awt. ; import java. awt. event. ; c l a s s GUI extends JFrame { / i n v a r i a n t : l a b e l. g e t T e x t ( ) = c o u n t / p r i v a t e JLabel l a b e l ; p r i v a t e i n t count ; p r i v a t e c l a s s IncrementButton extends JButton implements A c t i o n L i s t e n e r { p u b l i c IncrementButton ( ) { super ( Press to increment ) ; / i n c r e m e n t c o u n t a n d u p d a t e l a b e l. / p u b l i c void actionperformed ( ActionEvent e ) { count = count + ; l a b e l. settext ( + count ) ; p u b l i c GUI( ) { super ( GUI ) ; t h i s. l a b e l = new JLabel ( 0 ) ; t h i s. count = 0 ; setlayout (new FlowLayout ( ) ) ; add ( l a b e l ) ; add ( new IncrementButton ( ) ) ; pack ( ) ; p u b l i c s t a t i c void main ( S t r i n g [ ] args ) { new GUI( ). s e t V i s i b l e ( true ) ; 7 of 9

6. Spanning Trees [0 pts] Recall the following definition: Definition: A spanning tree T of a connected graph G is a subgraph of G containing all the nodes of G and a maximal set of edges, that (a) contains no cycle, and (b) connects all the nodes of G. Based on this definition, describe a high-level algorithm (as done in lecture) to find a spanning tree of G. 8 of 9

7. Sorting [4 pts] In this question we develop a sorting algorithm using loop invariants. Precondition: the array b has length n + (nothing is known about the values). Postcondition: b[0..n] is sorted. Invariant: b[i..n] is sorted and b[0..i ] b[i..n]. (a) [ pts] Give an array diagram that captures this invariant. (b) [ pts] Give the initialization statements that make the invariant true. (c) [ pts] Give the loop condition. (d) [ pts] Give a statement that makes progress towards termination (it may violate the invariant). (e) [3 pts] Describe in English what must be done in the loop body before part (d) to preserve the invariant. Your answer should be roughly one sentence. (f) [3 pts] What is the asymptotic worst-case running time of this algorithm? 9 of 9