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

Similar documents
CSE 143 Final Part 1, August 18, 2011 Sample Solution

CSE 413 Final Exam. June 7, 2011

CSE 413 Final Exam. December 13, 2012

CSE 303 Midterm Exam

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

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

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

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

CSE 333 Midterm Exam 2/14/14

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

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

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

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

ECE242 Data Structures and Algorithms Fall 2008

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

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

CSE 373 Spring Midterm. Friday April 21st

INF2220: algorithms and data structures Series 1

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering. Program 8 EECE.3220 Data Structures Fall 2017

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

CSE373 Fall 2013, Midterm Examination October 18, 2013

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Computer Science E-22 Practice Final Exam

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

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

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

Hierarchical data structures. Announcements. Motivation for trees. Tree overview

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

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

Binary Trees

* Due 11:59pm on Sunday 10/4 for Monday lab and Tuesday 10/6 Wednesday Lab

Programming Languages ML Programming Project Due 9/28/2001, 5:00 p.m.

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

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

CSE 131 Introduction to Computer Science Fall Exam II

CSE341 Spring 2017, Final Examination June 8, 2017

CSc 372, Fall 2001 Final Examination December 14, 2001 READ THIS FIRST

CSE 303, Spring 2005, Midterm Examination 29 April Please do not turn the page until everyone is ready.

TREES. Trees - Introduction

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

Solution to CSE 250 Final Exam

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:

Cpt S 122 Data Structures. Data Structures Trees

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

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

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

CSE 131 Introduction to Computer Science Fall 2016 Exam I. Print clearly the following information:

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Programming II (CS300)

Part I: Short Answer (12 questions, 65 points total)

CSE413 Midterm. Question Max Points Total 100

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

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

Prelim One Solution. CS211 Fall Name. NetID

Final Examination CSE 100 UCSD (Practice)

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

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

CMSC351 - Fall 2014, Homework #2

Computer Science 302 Spring 2007 Practice Final Examination: Part I

CSE wi: Practice Midterm

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

CSE341 Spring 2016, Midterm Examination April 29, 2016

CSE341 Spring 2017, Final Examination June 8, 2017

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

Data Structures and Algorithms Winter term 2016

Second Examination Solution

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

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

Suppose that the following is from a correct C++ program:

Binary Trees. Height 1

15 210: Parallel and Sequential Data Structures and Algorithms

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

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

B-Trees. Based on materials by D. Frey and T. Anastasio

Prelim 2, CS2110. SOLUTION

CSE 143 Sample Final Exam #3

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

CSE 333 Midterm Exam 5/10/13

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

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

COMP 250 Midterm #2 March 11 th 2013

CSE341 Spring 2016, Midterm Examination April 29, 2016

CSc 451, Spring 2003 Examination #1 February 25, 2003 READ THIS FIRST

CSE 143: Computer Programming II Autumn Sample Solutions

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Chapter 20: Binary Trees

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CSE 333 Midterm Exam 7/25/16. Name UW ID#

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

CSC/MAT-220: Lab 6. Due: 11/26/2018

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins

CSE 247 Data Structures and Algorithms Fall Exam I

Transcription:

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am Name Student ID # Section TA Name The exam is closed book, closed notes, closed devices, except that you may have a 5x8 card with handwritten notes plus the reference sheet handed out with the exam. There are two blank pages at the end of the exam if you need extra scratch space to write. You must show your ID and hand in your exam as you leave the room. You may not come back inside after that. Style and indenting matter, within limits. We re not overly picky about details like an extra or a missing parenthesis, but we do need to be able to follow your code and understand it. A few well-chosen comments can be very helpful. Too many make it hard to read the code. If you have questions during the exam, raise your hand and someone will come to you. Don t leave your seat. Please wait to turn the page until everyone has their exam and you have been told to begin. Advice: The solutions to many of the problems are quite short. Don t be alarmed if there is a lot more room on the page than you actually need for your answer. More gratuitous advice: Be sure to get to all the questions. If you find you are spending a lot of time on a question, move on and try other ones, then come back to the question that was taking the time. 1 Trees / 16 2 Trees / 8 3 BST search / 20 4 Collections / 20 5 Class design / 16 6 Types / 10 Total / 90 Page 1 of 10

Question 1. (16 points) Binary Search Trees. (a) Draw a picture that shows the integer binary search tree that results when the following numbers are inserted into a new, empty binary search tree in the order given: 42 17 10 50 15 20 12 (b) Write down the order in which the nodes in your tree would be visited using the following tree traversal orders: preorder postorder inorder Page 2 of 10

Question 2. (8 points) Binary Search Trees. Draw a picture that shows an integer binary search with minimum height that contains the following numbers. If there is more than one possible way to store the nodes in a binary search tree with minimum height, then you can show any of the possible solutions. 42 17 10 50 15 20 12 (Note: This is exactly the same data as in the previous problem, except that this time you re being asked to construct a minimum height binary search tree that contains the numbers. The numbers can be added to the tree in any order, not necessarily the one given. Hint: in a minimum-height tree, both subtrees of each interior node will have approximately the same number of nodes.) Page 3 of 10

Question 3. (20 points) Tree search. Suppose we have a class that stores a set of integer values with no duplicates. The class uses a binary search tree internally to store the values. For this problem, complete the definition of method numlessthan below so it returns the number of items in the set whose value is less than the method s argument n. You may define additional auxiliary methods if you find them useful. The next page is blank to provide additional space for your answer if needed. You may define as many additional simple variables as you wish, but no additional collections, arrays, or tree nodes, and you may not make any changes to the tree itself. For full credit, your solution must take advantage of the binary search tree organization and not examine any more of the tree than necessary. public class IntTreeSet { // tree nodes private class IntTreeNode { public int val; public IntTreeNode left; public IntTreeNode right; // data value in this node // left subtree with values < val // right subtree with values > val // binary search tree storing contents of this IntTreeSet private IntTreeNode treeroot; // construct new empty IntTreeSet public IntTreeSet() { treeroot = null; // code for other methods omitted to save space... // return number of items in this set with value < n public int numlessthan(int n) { // write your answer below and on the next page if needed. Page 4 of 10

Question 3. (cont.) Additional space for answer if needed. Page 5 of 10

Question 4. (20 points) Collections. Complete the following method so it will scan a list of words, find all of the words in that list that do not appear in a dictionary, and record how many times those words not in the dictionary appear in the original list. The input parameters to the method are a List (words) of strings and a Set (dictionary) of strings. The method should return a Map containing <String,Integer> pairs, where the String in each pair is a word that appears in the input list but not in the dictionary, and the associated integer is the number of times the corresponding word appeared in the list. The entries in the resulting Map do not need to be sorted in any particular order. You may create additional collections if you need them. String values must match exactly to be considered to be the same: i.e., foo, Foo, FOO and FOO are all different. // Return a Map containing a list of <String,Integer> pairs where // each String is a String that appears in the List words but not // in the Set dictionary, and the associated Integer is the number // of times the word appears in the List words Map<String,Integer> countunknownwords(list<string> words, Set<String> dictionary) { Page 6 of 10

Question 5. (16 points) Class design. For an address book application we have created the following class to represent the name and address of each entry in the address book. public class AddressCard { // instance data private String firstname; private String lastname; private String city; private int zipcode; // Create new AddressCard with given data public AddressCard(String fn, String ln, String city, int zip) { firstname = fn; lastname = ln; this.city = city; zipcode = zip; // add any additional code needed below We would like to modify this class so we can compare one AddressCard object to another. If x and y are AddressCard objects, then x.compareto(y) should compare x to y and return an appropriate integer depending on the ordering of x and y. AddressCards are ordered by their lastname fields. If two cards have the same lastnames, then the firstnames are used to decide the ordering. The lastname and firstname strings should be compared using their natural ordering as Strings and should not be modified. In particular, two strings that are similar but differ only in capitalization ( Abc and abc ) are not equal. Make the necessary modifications and additions to the above class to allow AddressCard objects to be compared. Page 7 of 10

Question 6. (10 points) Abstract classes and interfaces. (Brief, to-the-point answers are appreciated) In addition to regular classes, both abstract classes and interfaces can be used in Java programs to define new types. (a) Describe one advantage of defining a new type using an abstract class instead of an interface. (b) Describe one advantage of defining a new type using an interface instead of an abstract class. Page 8 of 10

Additional blank page for scratch paper. If you write an answer to a test question here, be sure to go back to the original page and write a note so the grader can find your answer. Page 9 of 10

Additional blank page for scratch paper. If you write an answer to a test question here, be sure to go back to the original page and write a note so the grader can find your answer. Page 10 of 10