Computer Science Foundation Exam

Similar documents
Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Section I B COMPUTER SCIENCE SOLUTION

Q1 Q2 Q3 Q4 Q5 Q6 Total

Computer Science. Section 1B

Computer Science Foundation Exam

Computer Science Foundation Exam

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

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

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

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

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)

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

Computer Science Foundation Exam

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

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

Computer Science E-22 Practice Final Exam

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

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

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

CS 216 Exam 1 Fall SOLUTION

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

ECE250: Algorithms and Data Structures Midterm Review

ECE264 Spring 2013 Final Exam, April 30, 2013

CSE 332, Spring 2010, Midterm Examination 30 April 2010

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

CSE332 Summer 2010: Midterm Exam Sample Solutions

PROBLEM 1 : (Vocabulary: 8 points) For each of the words/phrases below, circle the denition that is the best description as it pertains in the context

ECE242 Data Structures and Algorithms Fall 2008

CS171 Midterm Exam. October 29, Name:

CSE373 Fall 2013, Midterm Examination October 18, 2013

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

CSCE 2014 Final Exam Spring Version A

Computer Science E-119 Practice Midterm

UNIVERSITY REGULATIONS

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

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

Code No: R Set No. 1

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

ECE264 Fall 2013 Exam 1, September 24, 2013

COP 3502 Section 2 Exam #2 Version A Spring /23/2017

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011

CS 314 Exam 2 Spring

Foundation Exam - Sample Problems for New Topics

ECE264 Fall 2013 Exam 3, November 20, 2013

Solution to CSE 250 Final Exam

Computer Science Foundation Exam. December 15, Section I A. No Calculators! Name: SSN:

CSE 333 Midterm Exam 2/14/14

COP 3223H Fall 2017 Final Exam. Last Name:, First Name: Directions: Please answer questions 1-5 in C, and questions 6-10 in C++.

CSL 201 Data Structures Mid-Semester Exam minutes

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

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].

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

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

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

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

COMP171 Data Structures and Algorithms Fall 2006 Midterm Examination

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Summer Final Exam Review Session August 5, 2009

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

CS 307 Final Fall 2009

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

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

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

UNIVERSITY REGULATIONS

COMP Data Structures

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

CSE373 Winter 2014, Midterm Examination January 29, 2014

1 Complexity (10 minutes)

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1

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

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

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

Midterm I Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. September 30, 2010

EECS Sample Midterm Exam

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

Bin Sort. Sorting integers in Range [1,...,n] Add all elements to table and then

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

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

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

PROBLEM 1 : (Short Answer: 13 points) Three points each, except for last two which are two points 1. Both bubble-sort and selection sort are O(n 2 ) s

Test 2: CPS 100. Owen Astrachan. November 15, 2000

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

"apple" "grape" "grape" "grape" "apple"

Stacks and Queues. CSE Data Structures April 12, 2002

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Transcription:

Computer Science Foundation Exam January 13, 2018 Section I A DATA STRUCTURES NO books, notes, or calculators may be used, and you must work entirely on your own. Name: UCFID: NID: Question # Max Pts Category Passing Score 1 10 DSN 7 2 5 ANL 3 3 10 DSN 7 TOTAL 25 17 You must do all 3 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. For each coding question, assume that all of the necessary includes (stdlib, stdio, math, string) for that particular question have been made. Page 1 of 4

Data Structures Exam, Part A 1) (10 pts) DSN (Dynamic Memory Management in C) The struct, datatod, shown below, is used to collect data from different devices connected to the CPU. Every time the data is updated a new buffer containing the structure s data is created and populated. typedef struct datatod { int seconds; // seconds since midnight double data; // data sample char * dataname; // data name (optional) datatod; (a) (8 pts) Write the code necessary to create and initialize the members of datatod in a function named init_datatod that returns a pointer to the newly created buffer. Return NULL in the event a buffer cannot be created. Otherwise, set the seconds and data values according to the corresponding input parameters to init_datatod, dynamically allocate the proper space for dataname and then copy the contents of name into it (not a pointer copy) and a return a pointer to the newly created struct. datatod * init_datatod(int sec, double val, char* name){ (b) (2 pts) Complete the function below so that it frees all the dynamically allocated memory pointed to by its formal parameter zapthis. You may assume that the pointer itself is pointing to a valid struct and its dataname pointer is pointing to a dynamically allocated character array. void free_datatod(datatod *zapthis){ Page 2 of 4

Data Structures Exam, Part A 2) (5 pts) DSN (Linked Lists) Given the linked list structure named node, defined in lines 1 through 4, and the function named efunction defined in lines 6 through 14, answer the questions below. 1 typedef struct node { 2 int data; 3 struct node * next; 4 node; 5 6 node* efunction(node* anode){ 7 if(anode == NULL) return NULL; 8 if(anode->next == NULL) return anode; 9 10 node* rest = efunction(anode->next); 11 anode->next->next = anode; 12 anode->next = NULL; 13 return rest; 14 (a) (1 pt) Is this function recursive? (Circle the correct answer below.) YES NO (b) (2 pts) What does the function efunction do, in general to the list pointed to by its formal parameter, anode? (c) (2 pts) What important task does line 12 perform? Page 3 of 4

Data Structures Exam, Part A 3) (10 pts) ALG (Stacks) Consider evaluating a postfix expression that only contained positive integer operands and the addition and subtraction operators. (Thus, there are no issues with order of operations!) Write a function that evalulates such an expression. To make this question easier, assume that your function takes an array of integers, expr, storing the expression and the length of that array, len. In the array of integers, all positive integers are operands while -1 represents an addition sign and -2 represents a subtraction sign. Assume that you have a stack at your disposal with the following function signatures. Furthermore, assume that the input expression is a valid postfix expression, so you don't have to ever check if you are attempting to pop an empty stack. Complete the evaluate function below. void init(stack* s); // Initializes the stack pointed to by s. void push(stack* s, int item); // Pushes item onto the stack pointed // to by s. int pop(stack* s); // Pops and returns the top value from the stack // pointed to by s. int eval(int* expr, int len) { stack s; init(&s); int i; Page 4 of 4

Computer Science Foundation Exam January 13, 2018 Section I B DATA STRUCTURES NO books, notes, or calculators may be used, and you must work entirely on your own. Name: UCFID: NID: Question # Max Pts Category Passing Score 1 10 DSN 7 2 5 ALG 3 3 10 ALG 7 TOTAL 25 17 You must do all 3 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. For each coding question, assume that all of the necessary includes (stdlib, stdio, math, string) for that particular question have been made. Page 1 of 4

Data Structures Exam, Part B 1) (10 pts) DSN (Binary Search Trees) Write a recursive function to find the leaf node in a binary search tree storing the minimum value. (Thus, of all leaf nodes in the binary search tree, the function must return a pointer to the one that stores the smallest value.) If the pointer passed to the function is NULL (empty tree), the function should return NULL. typedef struct bstnode { int data; struct bstnode *left; struct bstnode *right; bstnode; bstnode* find_min_leaf(bstnode* root) { Page 2 of 4

Data Structures Exam, Part B 2) (5 pts) ALG (Binary Heaps) The array below stores a minimum binary heap. Draw the tree version of the corresponding binary heap. Then, remove the minimum value and show the resulting heap, in tree form. (Note: Index 0 isn't shown because index 1 stores the value at the root/top of heap.) Index 1 2 3 4 5 6 7 8 9 10 11 Value 2 16 3 22 17 12 13 23 30 18 20 Page 3 of 4

Data Structures Exam, Part B 3) (10 pts) ALG (AVL Trees) Show the result of inserting the following values into an initially empty AVL tree: 10, 7, 3, 22, 16, 13, 5, 18, 20 and 19. Draw a box around your result after each insertion. Page 4 of 4

Computer Science Foundation Exam January 13, 2018 Section II A ALGORITHMS AND ANALYSIS TOOLS NO books, notes, or calculators may be used, and you must work entirely on your own. Name: UCFID: NID: Question # Max Pts Category Passing Score 1 10 ANL 7 2 5 ANL 3 3 10 ANL 7 TOTAL 25 17 You must do all 3 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. For each coding question, assume that all of the necessary includes (stdlib, stdio, math, string) for that particular question have been made. Page 1 of 4

Algorithms and Analysis Tools Exam, Part A 1) (10 pts) ANL (Algorithm Analysis) With proof, determine the Big-Oh run time of the function, f, below, in terms of the input parameter n: int f(int array[], int n) { int i, t = 0, a = 0, b = n-1; while (a < b) { for (i=a; i<=b; i++) t += array[i]; if (array[a] < array[(a+b)/2]) b = (a+b)/2-1; else a = (a+b)/2+1; return t; In your work, you may use the following result: ( 1 i=0 2 )i = 2. Page 2 of 4

Algorithms and Analysis Tools Exam, Part A 2) (5 pts) ANL (Algorithm Analysis) An algorithm processing an array of size n runs in O(n 3 ) time. For an array of size 500 the algorithm processes the array in 200 ms. How long would it be expected for the algorithm to take when processing an array of size 1,500? Please express your answer in seconds. Page 3 of 4

Algorithms and Analysis Tools Exam, Part A 3) (10 pts) ANL (Summations and Recurrence Relations) Using the iteration technique, find a tight Big-Oh bound for the recurrence relation defined below: T(n) = 3T ( n ) + 2 n2, for n > 1 T(1) = 1 Hint: You may use the fact that ( 3 i=0 4 )i = 4 and that 3 log2n = n log23, and that log 2 3 < 2. Page 4 of 4

Computer Science Foundation Exam January 13, 2018 Section II B ALGORITHMS AND ANALYSIS TOOLS NO books, notes, or calculators may be used, and you must work entirely on your own. Name: UCFID: NID: Question # Max Pts Category Passing Score 1 10 DSN 7 2 5 ALG 3 3 10 DSN 7 TOTAL 25 17 You must do all 3 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 4

Algorithms and Analysis Tools Exam, Part B 1) (10 pts) DSN (Recursive Coding) Write an efficient recursive function that takes in a sorted array numbers, two integers, low and high, representing indexes into the array, and another integer, value, and returns the index in the array where value is found in the array in between index low and high, inclusive. If value is NOT found in the array in between indexes low and high, inclusive, then the function should return -1. int search(int numbers[], int low, int high, int value) { Page 2 of 4

Algorithms and Analysis Tools Exam, Part B 2) (5 pts) ALG (Sorting) (a) (3 pts) Explain why, in the worst case, Quick Sort runs more slowly than Merge Sort. (b) (2 pts) In practice, Quick Sort runs slightly faster than Merge Sort. This is because the partition function can be run "in place" while the merge function can not. More clearly explain what it means to run the partition function "in place". Page 3 of 4

Algorithms and Analysis Tools Exam, Part B 3) (10 pts) DSN (Backtracking) Consider the problem of placing 8 kings on an 8 x 8 chessboard, so that no two of the kings can attack each other AND no two kings are on the same row or column. (Recall that a King can move one space in each of the eight possible directions of movement: up, down, left, right or any of the four diagonals.) Complete the code skeleton below so that it prints out each solution to the 8 Kings problem. (Note: assume that the function print, which isn't included, prints out the solution that corresponds to a particular permutation of kings. For example, the permutation {2, 4, 6, 1, 3, 5, 7, 0 represents kings at the following locations (0, 2), (1, 4), (2, 6), (3, 1), (4, 3), (5, 5), (6, 7), and (7, 0).) #include <stdio.h> #include <math.h> #define SIZE 8 void go(int perm[], int k, int used[]); void print(int perm[]); int main() { int perm[size]; int used[size]; int i; for (i=0; i<size; i++) used[i] = 0; go(perm, 0, used); return 0; void go(int perm[], int k, int used[]) { if ( ) { print(perm); return; int i; for (i=0; i<size; i++) { if ( ) continue; if ( ) continue; perm[k] = ; used[ ] = 1 ; go(perm,, used); used[ i ] = ; Page 4 of 4