Spring 2002: Fundamental Structures of Computer Science

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

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

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

CSE332 Summer 2010: Midterm Exam Sample Solutions

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

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

CSE373 Fall 2013, Midterm Examination October 18, 2013

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

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

Midterm solutions. n f 3 (n) = 3

Assignment 8 CSCE 156/156H/RAIK 184H Spring 2017

Practice Midterm Exam Solutions

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

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

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

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

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

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

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

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Computer Science E-22 Practice Final Exam

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

Computer Science Foundation Exam

Exam Datenstrukturen und Algorithmen D-INFK

Exam Data structures DIT960/DAT036

Final Examination. Algorithms & Data Structures II ( )

Computer Science Foundation Exam

COS 226 Midterm Exam, Spring 2009

Course Review for Finals. Cpt S 223 Fall 2008

Course Review. Cpt S 223 Fall 2009

CSE373 Winter 2014, Midterm Examination January 29, 2014

Exam Datenstrukturen und Algorithmen D-INFK

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

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

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Lecture 13: AVL Trees and Binary Heaps

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

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

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

ECE368 Exam 2 Spring 2016

ECE Spring 2018 Problem Set #0 Due: 1/30/18

Second Examination Solution

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

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

Priority Queues and Heaps

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

Sample Exam 1 Questions

Agenda. We ve done Growth of functions Asymptotic Notations (O, o,,!, ) Now Binary search as an example Recurrence relations, solving them

Section 05: Solutions

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

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

Priority Queues Heaps Heapsort

Section 05: Midterm Review

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

CS 310 Advanced Data Structures and Algorithms

Analysis of Algorithms

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

CS 223: Data Structures and Programming Techniques. Exam 2

Problem Set 6 Due: 11:59 Sunday, April 29

CS 315 Data Structures mid-term 2

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

The questions will be short answer, similar to the problems you have done on the homework

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

Recall: Properties of B-Trees

Student number: Datenstrukturen & Algorithmen page 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Section 05: Solutions

Cpt S 223 Fall Cpt S 223. School of EECS, WSU


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

Computer Science E-119 Practice Midterm

COS 226 Algorithms and Data Structures Spring Midterm Exam

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

CSCE 2014 Final Exam Spring Version A

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

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

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

Balanced Search Trees. CS 3110 Fall 2010

University of Waterloo CS240 Spring 2018 Help Session Problems

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

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

Chapter 2: Basic Data Structures

Recall from Last Time: Big-Oh Notation

UNIT III BALANCED SEARCH TREES AND INDEXING

Computer Science Foundation Exam

COMP 250 Midterm #2 March 11 th 2013

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

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

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

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

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

Homework 3. Theory (50 points) Data Structures and Algorithms in JAVA Shlomo Hershkop Department of Computer Science Columbia University Summer 2002

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Balanced Search Trees

Transcription:

Spring 2002: 15-211 Fundamental Structures of Computer Science Midterm Name: Andrew ID: Section or TA name: Instructions Fill out the Name/Andrew ID/Section box above now. This exam is open book, plus 1 sheet of notes allowed. Make sure your test form is complete: It is 9 pages long (8 pages plus one page of scratch paper). There are 8 questions, many of which include several parts. If you make a mess, clearly cross out invalid attempts, and circle the nal answer. In multiple choice questions, pick one answer. The point scores for the questions are shown in the table below. Organize your work accordingly. Advice: If you get stuck onaproblem,move on and go back to it later. Good luck! Question 1 2 3 4 5 6 7 8 Total Points 20 12 15 17 13 16 20 12 125 1

1. Asymptotic Analysis. For (a)-(d), circle the correct expression. For (e)-(h), circle true or false. (a) 24n +4n 2 +7is (log n) (n) (n log n) (n 2 ) (n 100 ) (2 n ) (b) 17 + 7n log n +30n is (c) n + 3n log n + p n is (log n) (n) (n log n) (n 2 ) (n 100 ) (2 n ) (log n) (n) (n log n) (n 2 ) (n 100 ) (2 n ) (d) n 100 +2 n + n log n is (log n) (n) (n log n) (n 2 ) (n 100 ) (2 n ) (e) log n = O(n 2 ): (f) log n =(n 2 ): (g) n=2 =(n): (h) 2 n=2 = (2 n ): True True True True False False False False 2. Algorithm analysis. Suppose an algorithm takes 0.5 milliseconds to run on an input of size 100. How long would it take on an input of size 1,000 (assuming that low-order terms are negligible) if the running time of the algorithm is: running time linear O(nlogn) quadratic (that is, O(n 2 )) cubic (that is, O(n 3 )) 2

3. Below isjava code for a binary search routine for nding the location of x in array a (copied directly from Figure 5.11 on page 168 of the textbook): public static int binarysearch (Comparable[] a, Comparable x) { int low = 0 int high = a.length - 1 int mid while (low <= high) { mid = (low+high) / 2 if (a[mid].compareto(x) < 0) low = mid + 1 else if (a[mid].compareto(x) > 0) high = mid - 1 else return mid return -1 // The return value if not found (a) The running time of this algorithm is O(log n). However suppose we replace the line, mid = (low+high)/2, with, mid=low. Does this algorithm still work, and if so, what is its running time in O notation? (b) Going back to the original code, what would be the consequence of changing the while-test to be low < high? Works ne. Might run forever. Might not nd x even though it is in a. (c) Going back to the original code, what would be the consequence of changing the statement low = mid + 1 to be low = mid? Works ne. Might run forever. Might not nd x even though it is in a. 3

4. Binary Search Trees. (a) Suppose we use the basic (that is, not AVL or other self-balancing) binary-search tree insertion algorithm. Write down an ordering of the numbers 1,2,3,4,5,6,7 so that if the numbers were inserted in that order, the result would be a completely balanced tree. (b) Consider the tree below. Draw the tree that results from rotating the edge 20-30: 10 5 20 15 30 25 40 35 50 (c) Write down the binary search tree whose PREORDER traversal is 4 2 1 3 5 6 4

5. Min-Heaps (a) Draw the heap that results from performing the remove-min operation on the following heap: 10 20 12 23 30 40 15 25 50 (b) Fill in the array corresponding to the answer you gave for part (a). (c) Suppose we put the root of the heap into arr[0] instead of arr[1]. What would the rules be for the locations of the left child, right child, and parent of the node in arr[i]? left child: right child: parent: (d) The number of elements we need to look at to nd the smallest element in a heap of size n is: O(1) O(log n) O( p n) O(n) (e) The number of elements we need to look at to nd the largest element in a heap of size n is: O(1) O(log n) O( p n) O(n) 5

6. (a) Fill in the following chart with the time it takes each of the following dictionary structures to do the operations: insert, lookup, deletemin, ndnext (ndnext means: given an entry in the data structure (or a reference to it), nd the next largest entry). For hashing, assume you have a good hash function. dictionary insert lookup deletemin ndnext sorted list O( ) O( ) O( ) O( ) hash table O( ) O( ) O( ) O( ) balanced tree O( ) O( ) O( ) O( ) (b) Explain briey why the following would not be a good hash function for hashing 10,000 5-character words into an array of size 10,000: for (i=0, value = 0 i < word.length i++) value += (int) word.charat(i) return value % tablesize 6

7. Each codefragmentbelow has a bug. For each one, either circle the oending statement, or insert extra code to x the bug, or briey explain the problem. (a) /** Compute base^n. */ public static long power (int base, int n) { if (n%2 == 0) // n is even return power (base*base, n/2) else // n is odd return power (base*base, (n-1)/2) * base (b) public int f(int n) { if (n >= 0) return n*(n+1) else return "Bad input to method f." (c)... // names is an array of strings for (int i=0 i<=names.length i++) { System.out.println(i + ": " + names[i]) System.out.println("All done printing") (d) Stack s Stack t s.push("hello") s.push("goodbye") s.pop() 7

8. Induction Consider the following (very slow) code for computing the nth Fibonacci number. (Recall that the Fibonacci numbers are given by the sequence 0, 1, 1, 2, 3, 5, 8,... In particular F 0 =0,F 1 = 1, and for i>1, F i = F i;1 + F i;2.) /** This code appears in Figure 7.6 on page 242 of the textbook. */ public static long fib (int n) { if (n <= 1) return n else return fib(n-1) + fib(n-2) Let C(n) be the number of calls to fib made during the evaluation of fib(n). For n 1, we have C(n) =F n+2 + F n;1 ; 1 where F n is the n th Fibonacci number. Using induction, prove that this equation is valid. answer. Be concise and precise in your 8

scratch paper 9