Computer Science Foundation Exam

Similar documents
Computer Science Foundation Exam

Section I B COMPUTER SCIENCE SOLUTION

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science. Section 1B

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Q1 Q2 Q3 Q4 Q5 Q6 Total

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

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

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

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

2016 Spring COP 3502 Final Exam. Date: 4/28/2016. Name:

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

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

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

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

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

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

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

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

COP 3502 (Computer Science I) Test #3: Data Structures Date: 11/1/2013 VERSION A

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

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

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

CSL 201 Data Structures Mid-Semester Exam minutes

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Computer Science E-22 Practice Final Exam

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

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

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

CS 216 Exam 1 Fall SOLUTION

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

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

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

ECE264 Fall 2013 Exam 3, November 20, 2013

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

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

Test 2: CPS 100. Owen Astrachan. April 3, Name: Login: (1 pt)

Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3

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

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

CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination

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;

Computer Science Foundation Exam

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

CSCI 104 Log Structured Merge Trees. Mark Redekopp

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

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

COMP Data Structures

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

CSE332 Summer 2010: Midterm Exam Sample Solutions

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

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

CSE 332, Spring 2010, Midterm Examination 30 April 2010

ECE264 Spring 2013 Final Exam, April 30, 2013

Problem Score Maximum MC 34 (25/17) = 50 Total 100

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

CS 223: Data Structures and Programming Techniques. Exam 2

Data Structures Question Bank Multiple Choice

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

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

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

Computer Science Foundation Exam. March 3, Section I A. No Calculators! Name: SSN: In this section of the exam, there are three (3) problems.

// a stack is printed from bottom (leftmost) to top (rightmost) System.out.println(stk);

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CSE373 Fall 2013, Midterm Examination October 18, 2013

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

ECE 190 Final Exam. Practice exam

ECE250: Algorithms and Data Structures Midterm Review

Binary Trees and Binary Search Trees

Trees. A tree is a directed graph with the property

(the bubble footer is automatically inserted into this space)

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

Data Structures and Algorithms 2018

Programming Abstractions

Topics Recursive Sorting Algorithms Divide and Conquer technique An O(NlogN) Sorting Alg. using a Heap making use of the heap properties STL Sorting F

CSE 247 Data Structures and Algorithms Fall Exam I

We can use a max-heap to sort data.

Sample Questions for Midterm Exam 2

CSE373 Winter 2014, Midterm Examination January 29, 2014

Name: UTLN: CS login: Comp 15 Data Structures Midterm 2018 Summer

MLR Institute of Technology

Exercise 1 : B-Trees [ =17pts]

COMP 250 Fall Homework #4

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

Priority Queues Heaps Heapsort

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

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

COMP 250 Midterm #2 March 11 th 2013

Data Structures Brett Bernstein

Transcription:

Computer Science Foundation Exam August 8, 2014 Section I B 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 ANL 7 2 10 ANL 7 3 10 DSN 7 4 10 DSN 7 5 10 ALG 7 TOTAL 50 35 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) (10pts) ANL (Algorithm Analysis) List tight Big-Oh bounds(worst case), in terms of the variables used in the description, for each of the following algortihms/operations. If not specified, assume an efficient implementation. (a) Inserting an element into an AVL tree with n elements. O(lg n) (b) Dequeing an element from a queue of n elements, where the queue is implemented with an array. O(1) (c) Adding an m bit number to a n bit number. O(m+n) (d) Sorting n numbers using a Quick Sort, where the partition element O(n 2 ) is always the left-most item in the designated subarray. (e) Inserting an item into a heap containing n 2 items. O(lg n) (f) Searching for an element in a binary tree of n elements. O(n) (g) Printing out each of the permutations of the numbers 1, 2,..., n. Note: Assume printing one value takes O(1) time. O(n(n!)) (h) Running a floodfill on an n x n array. (Note: an example of a O(n 2 ) floodfill is the recursive clear in Minesweeper.) (i) Searching for a number in a sorted array of n numbers. O(lg n) (j) Deleting the first element of a linked list of n elements. O(1) Grading: 1 pt each per answer Page 2 of 6

2) (10 pts) ANL (Algorithm Analysis) (a) (5 pts) An algorithm for sorting student records runs in θ(n 2 ) time. It takes 20 ms to sort 10,000 student records. How much time will it take, approximately, in ms, to sort 40,000 student records? Let T(n) = cn 2, be the run-time of the algorithm for input size n, for some constant c. We know that T(10000) = c(10000) 2 = 20 ms, so c = 20 = 2 10 8 10 7 ms. (Grading: 2 pts, no need to simplify.) T(40000) = c(40000) 2 = 2 10 7 ms 16 10 8 = 320ms (Grading: 3 pts) (b) (5 pts) An algorithm for finding a valid schedule of n events runs in θ( (n+1)! ) time. For n = 10, the algorithm takes 50 ms. How long will it take, in seconds, approximately, to run on an input with n = 12? Let T(n) = c(n+1)!, be the run-time of the algorithm for input size n, for some constant c. We know that T(10) = c(11!) = 50 ms. (Grading 1 pt) T(12) = c(13!) = c(13)(12)(11!) = (c(11!))(156) = (50 ms)(156) = 7800 ms = 7.8 seconds. (Grading: 3 pts to get 7800 ms, 1 pt to convert to seconds.) Page 3 of 6

3) (10 pts) DSN (Linked Lists) Write a function, getvalue, that takes in a pointer to the front of a linked list storing an integer, with one digit stored in each node and returns the value of the number represented by the linked list. You may assume that the length of the initial linked list passed to the function is in between 0 and 9 items (so no need to worry about overflow), and that the digit field of each struct is in between 0 and 9, inclusive. (Note: An empty linked list has value 0.) Use the struct definition provided below. typedef struct node { int digit; struct node* next; node; int getvalue(node* number) { int total = 0; while (number!= NULL) { total = 10*total + number->digit; number = number->next; return total; // 1 pt // 2 pts // 4 pts // 2 pts // 1 pt // 4 pt line is as follows: 1 pt for 10* 1 pt for + 2 pts for // number->digit. Page 4 of 6

4) (10 pts) DSN (Binary Trees) The depth of a node in a binary tree is the distance of that node from the root. Write a recursive function that takes in a pointer to the root of a binary tree and returns the sum of the depths of the nodes of the tree. (For example, a complete binary tree of 7 nodes has 1 node with depth 0, 2 nodes with depth 1 and 4 nodes with depth 2, for a sum of depths of nodes of 0 + 2(1) + 4(2) = 10. Use the struct definition and function prototype given below. You may also assume that curdepth in sumdepthrec represents the depth of root within the whole binary tree. typedef struct treenode { int data; struct treenode *left; struct treenode *right; treenode; double sumdepth(treenode* root) { return sumdepthrec(root, 0); double sumdepthrec(treenode* root, int curdepth) { // Grading: 3 pts if (root == NULL) return 0; // Grading: 1 pt return, 2 pts curdepth, 2 pts recleft, // 2 pts recright return curdepth + sumdepthrec(root->left, curdepth+1) + sumdepthrec(root->right, curdepth+1); Page 5 of 6

5) (10 pts) ALG (Sorting) (a) (5 pts) Consider sorting the array below using Insertion Sort. Show the contents of the array after each iteration of the outer loop. Original 12 8 9 1 6 4 1 st iteration 8 12 9 1 6 4 2 nd iteration 8 9 12 1 6 4 3 rd iteration 1 8 9 12 6 4 4 th iteration 1 6 8 9 12 4 5 th iteration 1 4 6 8 9 12 Grading: 1 pt per line, to get the point, the line must be perfectly correct. (b) (5 pts) Show the result of running an in-place partition using index 0 as the partition element on the array shown below. (Note: Recall that in this algorithm, we use low and high index variables, sweeping through both sides until the low and high indexes cross over.) Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Values 45 48 83 7 1 77 37 61 39 75 54 23 64 42 65 93 Depending on which in-place partition is used, there are various possible answers. Three are provided below. Follow the grading criteria presented. Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sol 1 37 42 23 7 1 39 45 61 77 75 54 83 64 48 65 93 Sol 2 42 23 39 7 1 37 45 61 83 75 54 48 64 93 65 77 Sol 3 7 1 37 39 23 42 45 61 93 75 54 48 64 77 65 83 Grading: 1 pt for having 45 in the correct location, 2 pts for everything in indexes 0 5 being less than 45 and 2 pts for everything in indexes 7 15 being greater than 45. Page 6 of 6