Computer Science Foundation Exam

Similar documents
Computer Science Foundation Exam

Computer Science Foundation Exam

Section I B COMPUTER SCIENCE SOLUTION

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

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

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

Q1 Q2 Q3 Q4 Q5 Q6 Total

Computer Science Foundation Exam

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

Computer Science Foundation Exam

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

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

Computer Science Foundation Exam

Computer Science Foundation Exam

CSE332 Summer 2010: Midterm Exam Sample Solutions

Computer Science Foundation Exam

Computer Science Foundation Exam

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

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

CS 315 Data Structures mid-term 2

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

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

Computer Science. Section 1B

Computer Science Foundation Exam

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

If you are still writing when pens down is called, your exam will be ripped up and not graded sorry to have to be strict on this!

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

Sample Exam 1 Questions

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

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Computer Science Foundation Exam. May 6, Computer Science. Section 1A. No Calculators! KEY. Score: 50

Final Examination CSE 100 UCSD (Practice)

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

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

Computer Science E-22 Practice Final Exam

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

Section 05: Solutions

Second Examination Solution

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

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

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

CSE373 Fall 2013, Midterm Examination October 18, 2013

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

Section 05: Solutions

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

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

EECS 311 Data Structures Midterm Exam Don t Panic!

1. AVL Trees (10 Points)

Section 05: Midterm Review

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

ECE242 Data Structures and Algorithms Fall 2008

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004

CS 2150 (fall 2010) Midterm 2

Friday Four Square! 4:15PM, Outside Gates

CS 223: Data Structures and Programming Techniques. Exam 2

COP Study Union - Fall 2017

CSE373 Winter 2014, Midterm Examination January 29, 2014

Practice Midterm Exam Solutions

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

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Study Union Final Review

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

Hash Tables. Hashing Probing Separate Chaining Hash Function

UNIT III BALANCED SEARCH TREES AND INDEXING

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

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

ECE250: Algorithms and Data Structures Midterm Review

COP 3502 (Computer Science I) Final Exam 12/10/2015. Last Name:, First Name:

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

You must include this cover sheet. Either type up the assignment using theory5.tex, or print out this PDF.

CS 3114 Data Structures and Algorithms READ THIS NOW!

(the bubble footer is automatically inserted in this space)

CSE 214 Computer Science II Searching

PROBLEM 1 : (And the winner is...(12 points)) Assume you are considering the implementation of a priority queue that will always give you the smallest

Data Structures and Algorithms 2018

CS171 Final Practice Exam

INF2220: algorithms and data structures Series 1

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Lecture 16 More on Hashing Collision Resolution

Hash table basics mod 83 ate. ate. hashcode()

Recitation 9. Prelim Review

CS 216 Exam 1 Fall SOLUTION

INSTITUTE OF AERONAUTICAL ENGINEERING

CSE 326: Data Structures Lecture #11 B-Trees

In addition to the correct answer, you MUST show all your work in order to receive full credit.

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Exam Datenstrukturen und Algorithmen D-INFK

CS 261 Data Structures. AVL Trees

CSCE 2014 Final Exam Spring Version A

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

Spring 2002: Fundamental Structures of Computer Science

Implementing Hash and AVL

Exam Data structures DAT036/DAT037/DIT960

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

Transcription:

Computer Science Foundation Exam December 13, 2013 Section I A COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category Passing Score 1 10 DSN 7 2 10 ANL 7 3 10 ALG 7 4 10 ALG 7 5 10 ALG 7 TOTAL 50 You must do all 5 problems in this section of the exam. Problems will be graded based on the completeness of the solution steps and not graded based on the answer alone. Credit cannot be given unless all work is shown and is readable. Be complete, yet concise, and above all be neat. Page 1 of 6

1) (10 pts) DSN (Recursion) Write a function, odddepthsum(node *root), that returns the sum of all values that lie at an odd depth in a binary tree. You may write helper functions as you see fit. For example, your function should return 20 + 30 + 13 = 63 for the following tree: 10 <- depth: 0 (even) // here is the node struct definition: / \ 20 30 <- depth: 1 (odd) typedef struct node { / \ int data; 8 7 <- depth: 2 (even) struct node *left, *right; \ node; 13 <- depth: 3 (odd) int odddepthsum(node *root) { return foo(root, 0); // 2 pts int foo(node *root, int odd) { if (root == NULL) return 0; // 1 pt // 1 pt return (odd? root->data : 0) // 6pts total + foo(root->left,!odd) // 2 pts for each call + foo(root->right,!odd); // 2 pts for the rest Note: There are many solutions. Map the points according to the ideas in the solution above. Most students are likely to use if statements instead of the ternary operator and explicitly keep track of a depth and check its value mod 2. Page 2 of 6

2) (10 pts) ANL (Summations) (a) (3 pts) Write a summation that represents the number of times the statement p++ is executed in the following function: int foo(int n) { int i, j, p = 0; for (i = 1; i < n; i++) for (j = i; j <= i + 10; j++) p++; return p; i+ 10 Solution: i= 1 j= i 1 Grading: 1 pt inside, 1 pt inner sum, 1 pt outer sum (b) (5 pts) Determine a simplified, closed-form solution for your summation from part (a), in terms of n. You MUST show your work. Solution: i= 1 i+ 10 i+ 10 i 1 j = i 1 = i= 1 ( j= 1 1 j= 1 1) = i= 1 = i= 1 (11) = 11 i = 1 1 = 11() = 111 ((i+ 10) (i 1)) Grading: 2 pts for 11, 3 pts for rest. (c) (2 pts) Using big-oh notation, what is the runtime of the foo() function from part (a)? Solution: O(n) Grading: All or nothing Page 3 of 6

3) (10 pts) ALG (Binary Search Trees) (a) (3 pts) Using big-oh notation, give the best-, worst-, and average-case runtime of insertion into a binary search tree that already has n elements: Best-case: O(1) Grading: 1 pt each all or nothing Worst-case: O(n) Average-case: O(log n) (b) (2 pts) Using big-oh notation, indicate the minimum and maximum heights that a binary search tree with n elements can have: Minimum height: O(log n) Grading: 1 pt each all or nothing Maximum height: O(n) (c) (5 pts) Draw a binary search tree with 5 positive integers such that inserting the integer 13 will incur the worst-case runtime for BST insertion. There are infinitely many correct solutions. The point is for the BST to devolve into a linked list. For example, here are two possible solutions: 1 58 4 47 7 36 8 25 9 14 Grading: 5 pts for a correct answer, 3 pts if height is correct but 13 doesn t go all the way down, 2 pts if height is short, 0 otherwise Page 4 of 6

4) (10 pts) ALG (AVL Trees) (a) (4 pts) Insert the value 6 into the following AVL tree. Clearly show where the node is inserted initially and what the tree looks like after each rotation that takes place (if any). 27 / \ 19 29 / \ 11 23 28 30 / \ 10 15 Solution: 6 is inserted as the left child of 10. This causes a single right rotation at node 19. During the rotation, 11 moves up to take the place of 19. Node 19 moves down, and the old right child of 11 becomes the new left child of 19. 27 27 / \ 19 29 11 29 / \ 11 23 28 30 => 10 19 28 30 / / \ 10 15 6 15 23 / 6 Grading: 1 pt for keeping 27 1 pt for 11, 19 and 15 (b) (4 pts) List all the integer values that would cause a double rotation if inserted into the following AVL tree. If there are no such values, say so. (Assume we do not allow the insertion of duplicate values into our AVL trees.) 24 / \ Solution: Inserting 29, 30, or 31 would cause a double rotation. 20 32 No other values would cause a double rotation. / 28 // 1 pt for each correct answer 1 pt for not // listing any extra (c) (2 pts) In big-oh notation, what is the worst-case runtime of inserting a single element into an AVL tree that already has n elements? Solution: O(log n) Grading: 2 pts all or nothing Page 5 of 6

5) (10 pts) ALG (Hash Tables) (a) (4 pts) Insert the following elements into the hash table below using separate chaining to resolve collisions. The table is of size 11, so assume that the hash value for a given input, key, is determined by calling hash(key, 11). int hash(char *s, int table_size) { if (s == NULL s[0] == '\0') return 0; else return ((int)(tolower(s[0]) 'a') + 1) % table_size; Keys to insert: abacus, dwindle, fox, goose, bag, beans, ferocious, delicate 0 1 2 3 4 5 6 7 8 9 10 abacus bag dwindle fox goose beans delicate ferocious Grading: ½ pt for each, round down (b) In general, what is the worst-case big-oh runtime for insertion into a hash table that already contains n elements? Briefly describe the specific situation that leads to this worst-case performance. Solution: The worst case is O(n), which happens when there are excessive collisions (possibly as a result of a poor hash function that does not produce evenly distributed hash values, or because of clusters of data that form while using linear or quadratic probing). Grading: 2 pts ans, 1 pt reason (c) Suppose we want to use this hash function to insert a much larger set of strings into our hash table (some arbitrarily large number of strings, n), and so we expand the hash table to be length O(n). Is the hash function in this problem a good hash function for that purpose? Why or why not? Solution: No. The hash function is terrible because it will only ever produce 27 unique hash values, even if we have a huge table. That will lead to lots of collisions for large n. Grading: 1 pt for answer, 2 pts for reason Page 6 of 6