CSE373 Fall 2013, Midterm Examination October 18, 2013

Similar documents
CSE373 Winter 2014, Midterm Examination January 29, 2014

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

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

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

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

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

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

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

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

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

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

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

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

CSE332 Summer 2010: Midterm Exam Sample Solutions

CSE wi: Practice Midterm

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Midterm solutions. n f 3 (n) = 3

Practice Midterm Exam Solutions

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

: Fundamental Data Structures and Algorithms. June 06, 2011 SOLUTIONS

CSE373 Midterm I Fall 2009 (Closed book, closed notes)

Exam Data structures DAT036/DAT037/DIT960

CSE341, Fall 2011, Midterm Examination October 31, 2011

CS171 Midterm Exam. October 29, Name:

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

CSE373 Winter 2014, Final Examination March 18, 2014 Please do not turn the page until the bell rings.

CS171 Final Practice Exam

Section 1: True / False (1 point each, 15 pts total)

CSE 373: Practice Final

Section 03: Asymptotic Analysis

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

UNIVERSITY REGULATIONS

Section 05: Midterm Review

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

Priority Queues. 04/10/03 Lecture 22 1

Lecture 23: Binary Search Trees

CSE505, Fall 2012, Midterm Examination October 30, 2012

Test #2. Login: 2 PROBLEM 1 : (Balance (6points)) Insert the following elements into an AVL tree. Make sure you show the tree before and after each ro

Second Examination Solution

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

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

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

CSE331 Winter 2014, Midterm Examination February 12, 2014

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

CSE341, Fall 2011, Midterm Examination October 31, 2011

ECE250: Algorithms and Data Structures Midterm Review

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect).

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

CS 223: Data Structures and Programming Techniques. Exam 2

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

CSE351 Winter 2016, Final Examination March 16, 2016

CSE 332, Spring 2010, Final Examination 8 June 2010

Spring 2002: Fundamental Structures of Computer Science

CSE373 Winter 2014, Final Examination March 18, 2014 Please do not turn the page until the bell rings.

Computer Science 302 Fall 2018 (Practice for) Third Examination, November 14, 2018

CSE332 Summer 2012 Final Exam, August 15, 2012

CSE331 Spring 2015, Final Examination June 8, 2015

CS 315 Data Structures mid-term 2

INF2220: algorithms and data structures Series 4

Suppose we want to create a data structure called DataStore that has the following operations:

Section 05: Solutions

CPSC 35 Midterm Exam

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

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting

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

CSE341 Spring 2016, Midterm Examination April 29, 2016

COS 226 Algorithms and Data Structures Fall Midterm

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

CSE341 Spring 2017, Final Examination June 8, 2017

You must print this PDF and write your answers neatly by hand. You should hand in the assignment before recitation begins.

CSE341 Spring 2017, Midterm Examination April 28, 2017

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014

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

CS171 Final Practice Exam

CSE332, Spring 2012, Final Examination June 5, 2012

CS 61B Asymptotic Analysis Fall 2018

Midterm 2 Exam Principles of Imperative Computation. Tuesday 31 st March, This exam is closed-book with one sheet of notes permitted.

UNIVERSITY REGULATIONS

CS61B Fall 2014 Guerrilla Section 2 This worksheet is quite long. Longer than we ll cover in guerrilla section.

a) For the binary tree shown below, what are the preorder, inorder and post order traversals.

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

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

CS 216 Exam 1 Fall SOLUTION

Section 1: True / False (2 points each, 30 pts total)

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

INSTITUTE OF AERONAUTICAL ENGINEERING

Section 05: Solutions

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

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

CSE331 Fall 2014, Final Examination December 9, 2014 Please do not turn the page until 2:30. Rules:

DIT960 Datastrukturer

CSE 100 Practice Final Exam

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

Data Structures and Programming Spring 2014, Midterm Exam.

Transcription:

CSE373 Fall 2013, Midterm Examination October 18, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop promptly at 3:20. There are 93 points total, distributed unevenly among 7 questions (many with multiple parts): Question Max Earned 1 14 2 15 3 18 4 17 5 5 6 12 7 12 Advice: Read questions carefully. Understand a question before you start writing. Write down thoughts and intermediate steps so you can get partial credit. But clearly circle your final answer. The questions are not necessarily in order of difficulty. Skip around. Make sure you get to all the problems. If you have questions, ask. Relax. You are here to learn.

1. (14 points) For each function f(n) below, give an asymptotic upper bound using big-oh notation. You should give the tightest bound possible (so giving O(2 n ) for every question is unlikely to result in many points). You must choose your answer from the following list. The list is not in any particular order and any item in the list could be the answer for 0, 1, or more than 1 question. O(n), O(n 2 ), O(2 n ), O(n 12 ), O(n 14 ), O(n 3 ), O(n 4 ), O(n 5 ), O(n 6 ), O(n 7 ), O(n 8 ), O(n 9 ), O(log 3 n), O(n 2 log n), O(log 8 n), O(log 4 n), O(n log 3 n), O(log 2 n), O(log n), O(1), O(n 3 log n), O(n n ), O(n log log n), O(n log 2 n), O(log log n), O(n log n) (a) f(n) = 100n 3 7n 3 + 14n 2 (b) f(n) = 100n 3 100n 3 + 7n 2 (c) f(n) = log(7n 2 ) (d) f(n) = 5 log log n + 4 log 2 (n) (e) f(n) =.001n + 100 2 n (f) f(n) = n 3 (1 + 6n + 2014n 2 ) (g) f(n) = (log n)(n + n 2 ) (a) O(n 3 ) (b) O(n 2 ) (c) O(log n) (d) O(log 2 N) (e) O(2 n ) (f) O(n 5 ) (g) O(n 2 log n)

2. (15 points) Describe the worst case running time of the following code in big-oh notation in terms of the variable n. You should give the tightest bound possible. (a) void f1(int n) { for(int i=0; i < n; i++) { for(int j=0; j < n; j++) { for(int k=0; k < n; k++) { for(int m=0; m < n; m++) { System.out.println("!"); (b) void f2(int n) { for(int i=0; i < n; i++) { for(int j=0; j < 10; j++) { for(int k=0; k < n; k++) { for(int m=0; m < 10; m++) { System.out.println("!"); (c) int f3(int n) { int sum = 73; for(int i=0; i < n; i++) { for(int j=i; j >= 5; j--) { sum--; return sum; (d) int f4(int n) { if (n < 10) { System.out.println("!"); return n+3; else { return f4(n-1) + f4(n-1); (e) int f5(int n) { if (n < 10) { System.out.println("!"); return n+3; else { return f5(n-1) + 1; (a) O(n 4 ), (b) O(n 2 ), (c) O(n 2 ), (d) O(2 n ), (e) O(n)

3. (18 points) Assume this tree is a binary search tree even though you cannot see what the keys and values are at the nodes (the letters we write below are just names for the nodes for the purpose of answering the questions). (a) What node is the successor of node A? (b) What node is the successor of node B? (c) What node is the successor of node C? (d) What is the height of the tree? (e) What is the maximum number of nodes that could be added to the tree without increasing its height? (f) Is the tree an AVL tree? (g) If we remove only node H, is the result an AVL tree? (h) If we remove only node J, is the result an AVL tree? (i) If we remove only node K, is the result an AVL tree? (a) J (b) E (c) K (d) 4 (e) 18 (f) yes (g) yes (h) no (i) no

4. (17 points) In this problem, you will write some Java code for simple operations on binary search trees where keys are ints. Assume you already have the following code. Assume the method bodies, even though not shown, are correct and implement the operations as we defined them in class. public class BinarySearchTreeNode { public int key; public SomeType value; public BinarySearchTreeNode left; public BinarySearchTreeNode right; public class BinarySearchTree { private BinarySearchTreeNode root; public void insert(int key, SomeType value) {... public void delete(int key) {... public SomeType find(int key) {... Don t overlook part (c). (a) Add a method public int treeheight() to the BinarySearchTree class that computes the height of the tree. You will need a helper method. (b) Add method public void deletemax() to the BinarySearchTree class that deletes the maximum element in the tree (or does nothing if the tree has no elements). You may want a helper method. (c) For your answers in part (a) and part (b), give a worst-case big-oh running time in terms of n, where n is the number of nodes in the tree. Do not assume the tree is balanced. There is room below and on the next page for solutions.

More space for solutions. (a) public int treeheight() { return nodeheight(root); int nodeheight(binarysearchtreenode n) { if(n==null) return -1; return 1 + Math.max(nodeHeight(n.left),nodeHeight(n.right)); (b) public void deletemax() { if(root == null) return; else if(root.right == null) root is max root = root.left; else deletemaxnode(root); recursive version void deletemaxnode(binarysearchtreenode prev) { if(prev.right.right == null) prev.right = prev.right.left; partial credit: prev.right = null; else deletemaxnode(prev.right); iterative version [helper method not needed] void deletemaxnode(binarysearchtreenode prev) { while(prev.right.right!= null) prev = prev.right; prev.right = prev.right.left; partial credit: prev.right = null; A third version that uses the provided delete method public void deletemax() { if(root == null) return; BinarySearchTreeNode n = root; while(n.right!= null) n = n.right; delete(n.key); (c) Both operations are O(n) in the worst case.

5. (5 points) Below is part of the picture from lecture for how to do the double-rotation when an AVLtree insertion causes the node a to violate the balance property because of an insertion in its left-right grandchild. Complete the picture to show the shape of the tree after the double-rotation. (You can just show the final result.) Include the heights of each nodesubtree in the result similar to how they are included in the picture before the double-rotation.

6. (12 points) Suppose there is a binary min-heap with exactly 4 nodes, containing items with priorities 3, 9, 11, and 15. (a) Show every possible binary min-heap that could match this description. For each, draw the appropriate tree and the array representation. (You can show just the priorities, not the corresponding items.) (b) For one of your answers to part (a), show what happens with 4 deletemin operations. Clearly indicate which heap you are starting with and show the heap after each deletemin. You can just draw the tree (not the array) after each step. (a) Three possibilities: 3 ------------------- 3 --------------------- \ 3 9 11 15 \ 3 11 9 15 9 11 ------------------- 11 9 -------------------- 15 15 11 3 --------------------- \ 3 9 15 11 9 15 --------------------- Explanation: All 4-node heaps must have the shape of the 3 heaps in part (a). The minimum node, 3, must be at the root. The maximum node, 15, must be at a leaf. The only heap meeting these rules and not listed above does not satisfy the heap property because 11 is above 9: 9 3 \ 11 15 (b) 3 9 11 15 <empty tree> \ \ 9 11 ---> 15 11 ---> 15 ---> ---> 15 3 9 11 15 <empty tree> \ \ OR 11 9 ---> 11 15 ---> 15 ---> ---> 15 3 9 11 15 <empty tree> \ \ OR 9 15 ---> 11 15 ---> 15 ---> ---> 11

7. (12 points) Answer each of the following; no explanations required. (a) What is the worst-case asymptotic running-time for the best algorithm for finding something in a dictionary implemented with a sorted array? (b) What is the best-case asymptotic running-time for the best algorithm for finding something in a dictionary implemented with a sorted array? (c) What is the worst-case asymptotic running-time for the best algorithm for finding something in a dictionary implemented with a sorted linked list? (d) What is the best-case asymptotic running-time for the best algorithm for finding something in a dictionary implemented with a sorted linked list? (e) True or false: Every AVL tree is a binary search tree. (f) Complete this table appropriately: 2 10 about a thousand 2 20 2 30 Note: We give answers here with O, but Θ would technically be more precise. (a) O(log n) (b) O(1) (c) O(n) (d) O(1) (e) true 2 10 about a thousand (f) 2 20 about a million 2 30 about a billion