Computer Science Foundation Exam

Similar documents
Section I B COMPUTER SCIENCE SOLUTION

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. Section 1B

Q1 Q2 Q3 Q4 Q5 Q6 Total

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

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

Computer Science Foundation Exam

Computer Science Foundation Exam

Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Computer Science Foundation Exam

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

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)

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

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

CS 216 Exam 1 Fall SOLUTION

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

CMSC351 - Fall 2014, Homework #2

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

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

Solution for Data Structure

Programming Abstractions

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE

Chapter 20: Binary Trees

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

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

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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

CP2 Revision. theme: dynamic datatypes & data structures

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

CSI33 Data Structures

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

! 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)

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

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

COS 226 Algorithms and Data Structures Fall Midterm

MLR Institute of Technology

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

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

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

9/26/2018 Data Structure & Algorithm. Assignment04: 3 parts Quiz: recursion, insertionsort, trees Basic concept: Linked-List Priority queues Heaps

An Introduction to Trees

CS171 Midterm Exam. October 29, Name:

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

12 Abstract Data Types

Binary Trees. Examples:

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

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

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

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CSCE 2014 Final Exam Spring Version A

Ashish Gupta, Data JUET, Guna

CS 223: Data Structures and Programming Techniques. Exam 2

Name CPTR246 Spring '17 (100 total points) Exam 3

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

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

.:: UNIT 4 ::. STACK AND QUEUE

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

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

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

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

Recursion, Trees and Tree Traversal. Module CE System Programming & Computer Control Systems

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

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

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

Name: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.

COS 226 Algorithms and Data Structures Spring Midterm

cameron grace derek cameron

CS 241 Data Organization Binary Trees

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

COMP 250 Midterm #2 March 11 th 2013

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Lecture 16 AVL Trees

CS 455 Final Exam Fall 2013 [Bono] December 12, 2013

FORM 2 (Please put your name and form # on the scantron!!!!)

Lecture 3: Stacks & Queues

ECE264 Spring 2013 Final Exam, April 30, 2013

CMPT 125: Practice Midterm Answer Key

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

UNIVERSITY REGULATIONS

Lecture No. 10. Reference Variables. 22-Nov-18. One should be careful about transient objects that are stored by. reference in data structures.

Computer Science E-22 Practice Final Exam

Final Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. December 10, Name: Andrew ID: Section:

Largest Online Community of VU Students

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

Computer Science Foundation Exam

Matriculation number:

1 Complexity (10 minutes)

Lecture 16 Notes AVL Trees

Transcription:

Computer Science Foundation Exam December 16, 2011 Section I A COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. Name: PID: 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) Recursion. Write a recursive function that deletes every other node in a linked list pointed to by head, which is a parameter to the function. Specifically, make sure you delete the second, fourth, sixth, etc. nodes and return a pointer to the front of the new list. If the list has zero or one item in it, the list should be unchanged and a pointer to its front should be returned. Your function should make use of the following struct node and function prototype: struct node { int data; struct node *left; struct node *right; }; struct node* deleveryother(struct node *head) { // Base case // Grading: 1 point if (head == NULL head->next == NULL) return NULL; // Assign a temp pointer to the node to be deleted struct node* temp = head->next; // Grading: 1 points // Bypass the node to be deleted. head->next = temp->next; // Grading: 2 points // Can also do: head->next = head->next->next; // Free the temp node free(temp); // Grading: 1 points // Recursively call the function on the rest of the list head->next = deleveryother(head->next); // Grading 4 points // Can also do: deleveryother(head->next); // Return the original front of the lis return head; // Grading 1 point } Page 2 of 6

2) (10 pts) Summations. Determine a simplified, closed-form solution for the following summation in terms of n. You MUST show your work. Grading: 4 points for inner summation: Grading: 2 points for changing limits of outer summation: Grading: 2 points for applying sum formula: Grading: 2 points for simplifying: Page 3 of 6

3) (10 pts) Stacks and Queues. Let Q be a queue and S be a stack. The functions dequeue and pop obey the convention that they return whatever they remove. Assume that Q and S are initially empty and that print is a function that prints the value of its argument. Execute, in top-to-bottom order, the operations below and answer the following questions. push(s, O ); enqueue(q, - ); push(s, G ); enqueue(q, F ); enqueue(q, C ); print(dequeue(q)); enqueue(q, U ); push(s, G ); push(s, H ); push(s, dequeue(q)); enqueue(q, K ); push(s, dequeue(q)); enqueue(q, N ); push(s, dequeue(q)); enqueue(q, I ); enqueue(q, T ); a) Show the output from the print statements: Grading: (6pts) 1 point per letter: G O - U C F first output second output third output fourth output fifth output sixth output b) After the above operations are completed, how many items are left in stack S? Grading: 2 points 2 c) After the above operations are completed, how many items are left in queue Q? Grading: 2 points 4 Page 4 of 6

4) (10 pts) AVL Trees. The tree shown below is a valid AVL tree. You must delete the node that has 35 as a data value and rebalance the AVL tree as needed, which will require two restructures. (a) Show the state of the AVL tree after the first rebalancing. (b) Show the state of the AVL tree after the second rebalancing. (a) Grading: 1 pt for deleting 35, 2 points for correct final answer (b) Grading: 1 pt for 45 root, 1 pt for 40, 1 pt for 50, 1 pt for each sub-tree correct. Page 5 of 6

5) (10 pts) Binary Trees a) Write a function that frees the memory for each node in a Binary Tree. In particular, the memory should be freed in the right subtree first, then the left subtree, and finally the root will be freed. Your function should make use of the following struct tree_node and function prototype: struct tree_node { int data; struct tree_node *left; struct tree_node *right; }; void freebintree(struct tree_node *head) { if (head!= NULL) { freebintree(head->right); freebintree(head->left); free(head); } // Grading: 1 pt // Grading: 2 pt // Grading: 2 pt // Grading: 1 pt } b) List the order that the nodes would be freed if the above function is executed on the following tree: Grading: (4pts) 1 pt per mistake 37, 92, 21, 62, 77, 56, 24, 12, 48 Page 6 of 6