CSCE 2014 Final Exam Spring Version A

Similar documents
CSCE 2004 Midterm Exam Spring 2017

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

Question Q1 Q2 Q3 Q4 Q5 Q6 Q7 Total

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?

Summer Final Exam Review Session August 5, 2009

2) Which data structure is most suitable for search operations? A) Linked List B) Queue C) Hash table D) Sorted array

Largest Online Community of VU Students

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

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

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

CS-301 Data Structure. Tariq Hanif

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

Data Structures Question Bank Multiple Choice

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

INSTITUTE OF AERONAUTICAL ENGINEERING

Recitation 9. Prelim Review

Computer Science Foundation Exam

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

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

COMP 103 Introduction to Data Structures and Algorithms

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

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

CS 216 Exam 1 Fall SOLUTION

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

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

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

CSCE 2004 Final Exam Spring Version A

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

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)

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

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

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

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

( ) n 3. n 2 ( ) D. Ο

CS301 - Data Structures Glossary By

Basic Data Structures (Version 7) Name:

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012

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

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

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

EXAMINATIONS 2017 TRIMESTER 2

1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010

Question Bank Subject: Advanced Data Structures Class: SE Computer

Second Examination Solution

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II

Solved by: Syed Zain Ali Bukhari (BSCS)

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

Arrays and Linked Lists

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

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

CSL 201 Data Structures Mid-Semester Exam minutes

Final Examination CSE 100 UCSD (Practice)

( D. Θ n. ( ) f n ( ) D. Ο%

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

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

CS171 Final Practice Exam

Computer Science Foundation Exam

CS301 All Current Final Term Paper Subjective 2013 Solved with refernces

CS171 Midterm Exam. October 29, Name:

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Part 1: Multiple Choice Circle only ONE answer. Each multiple choice question is worth 3.5 marks.

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

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

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

n 2 ( ) ( ) + n is in Θ n logn

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

Suppose that the following is from a correct C++ program:

COMP 250 Midterm #2 March 11 th 2013

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

Priority queues. Priority queues. Priority queue operations

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

ECE250: Algorithms and Data Structures Midterm Review

Sample Question Paper

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

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

Fundamentals of Data Structure

Final Exam Solutions PIC 10B, Spring 2016

Data Structure (CS301)

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

Department of Computer Science Admission Test for PhD Program. Part I Time : 30 min Max Marks: 15

DATA STRUCTURES AND ALGORITHMS

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

Final Exam. Name: Student ID: Section: Signature:

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

Hash Table and Hashing

Computer Science 302 Spring 2018 Practice Examination for the Second Examination,

Programming Abstractions

Dynamic Data Structures

Computer Programming II C++ (830)

Transcription:

CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers are not allowed. Reminder: This class is governed by the code of ethics of the College of Engineering and Department of Computer Science and Computer Engineering. Any instances of cheating will result in a grade of zero on the exam and referral to the ethics board. 1

Recursion 20 points Consider the following C++ function. float power(float x, int p) cout << "power " << x << " " << p << endl; } if (p <= 0) return 1; if (p == 1) return x; float temp = power(x, p / 2); if (p % 2 == 0) return temp * temp; else return x * temp * temp; [5 points] What are the terminating conditions for this function? A) if (p <= 0) B) if (p == 1) C) if (p % 2 == 0) D) A) and B) E) A) and B) and C) [5 points] What value will this function return if we call power(4, 2) in the main program? A) 1 B) 4 C) 8 D) 16 E) 42 2

[5 points] How many calls to the power function will take place if we call power(2, 5) in the main program? A) 1 B) 2 C) 3 D) 4 E) 5 Consider the following C++ function. int work(int num) if (num < 0) return 0; else return (work (num - 1) + work (num - 1)); } [5 points] What will happen if we call work(3) in the main program? A) The function will return 0 B) The function will return 2 + 4 = 6 C) The program will run forever adding numbers D) The program will crash with a stack overflow E) None of the above 3

Consider the following C++ code. class node public: int Value; node* Next; }; Linked Lists 20 points void save1(node * & head, node * & tail, int value) node * ptr = new node(); ptr->value = value; ptr->next = NULL; if (head == NULL) head = ptr; else tail->next = ptr; tail = ptr; } void save2(node * & head, node * & tail, int value) node * ptr = new node(); ptr->value = value; ptr->next = head; if (head == NULL) tail = ptr; head = ptr; } void save3(node * & head, node * & tail, int value) if ((head!= NULL) && (value < head->value)) save2(head, tail, value); else save1(head, tail, value); } 4

[5 points] Assume that head and tail are initialized to NULL in the main program. Draw a diagram to show what the linked list look like after we call save1 three times with values 4, 2, 5? Remember to include the head and tail pointers. [5 points] Assume that head and tail are initialized to NULL in the main program. Draw a diagram to show what the linked list look like after we call save2 three times with values 0, 4, 8? Remember to include the head and tail pointers. [5 points] Assume that head and tail are initialized to NULL in the main program. Draw a diagram to show what the linked list look like after we call save3 three times with values 6, 5, 7? Remember to include the head and tail pointers. [5 points] Assume you are given a linked list implementation that uses a head pointer but no tail pointer. Which of the following operations will be the fastest? A) insert_head B) insert_tail C) print list D) A and B E) B and C 5

Stacks 20 points [5 points] Assume you are given a stack containing the values [3, 6, 5] where the top of the stack is on the right. What will this stack contain after the following operations are executed? s.push( 4 ); s.push( s.pop() + 1); s.push( s.top() + s.top() ); A) [3, 6, 6, 12] B) [3, 6, 5, 4, 5] C) [3, 6, 5, 4, 5, 9] D) [3, 6, 5, 9] E) None of the above [5 points] Assume you implementing a stack using an array-based approach and the variable size contains the number of values stored in the stack. Which of the following statements could be used to push value onto a stack that is not full? A) data[size] = value; size++; B) size++; data[size] = value; C) data[size+1] = value; size++; D) B or C E) A or C [5 points] Assume you implementing a stack using an array-based approach and the variable size contains the number of values stored in the stack. Which of the following statements could be used to pop value from a stack that is not empty? A) size--; value = data[size]; B) value = data[size-1]; size--; C) value = data[size]; size--; D) A or B E) B or C [5 points] What is the advantage of implementing a stack using an existing linked list class instead of an array? A) It takes less code to implement B) The stack can never get full C) The stack can never get empty D) A and B E) B and C 6

Queues 20 points [5 points] Assume you are given a queue containing the values [7, 2, 6] where the front of the queue is on the left and the back of the queue is on the right. What will this queue contain after the following operations are executed? q.insert( 4 ); q.insert( q.remove() + 1 ); cout << q.remove() << endl; q.insert( 1 ); A) [7, 2, 6, 4, 8, 1] B) [2, 6, 4, 8, 1] C) [6, 4, 8, 1] D) [7, 2, 6] E) None of the above [5 points] Which of the following can be used to implement a queue? A) A linked list with a head pointer B) A double linked list with a head and a tail pointer C) A fixed size array D) A dynamically allocated array E) All of the above [5 points] Assume you implementing a queue using a circular array-based approach and the variable size contains the size of the array, and the variables front and back contain the array locations of the data values at the front of the queue and back of the queue. Which of the following statements could be used to insert value into a queue that is not full? A) front=(front+1) % size; value = data[front]; B) value = data[front]; front=(front+1) % size; C) data[back] = value; back=(back+1) % size; D) back=(back+1) % size; data[back] = value; E) None of the above [5 points] What is the advantage of implementing a queue using a circular array-based approach instead of using an existing linked list class? A) It takes less code to implement B) The queue can never get full C) The queue can never get empty D) Insert and remove operations are faster E) All of the above 7

Sorting 20 points [5 points] Consider the following sorting algorithms: Quick Sort, Merge Sort, Selection Sort, and Bubble Sort. Which of these algorithms are the fastest for data that is in random order? A) Merge Sort and Quick Sort. B) Selection Sort and Quick Sort. C) Bubble Sort and Selection Sort. D) Merge Sort and Selection Sort. E) All four sorting algorithms. [5 points] Given an integer array containing 9, 11, 7, 3, 5, 1}, what will the array contain after one pass of Bubble Sort? (Assume we are sorting in ascending order) A) 1, 3, 5, 7, 9, 11} B) 3, 7, 9, 11, 5, 1} C) 9, 7, 3, 5, 1, 11} D) 7, 9, 11, 3, 5, 1} E) None of the above. [5 points] Suppose you are performing Selection Sort on an array of 100 items. After you have completed 45 selection iterations, how many items are guaranteed to be in their final position in the array (never to be moved again)? A) Zero. B) 45 C) 55 D) 50 E) 100 [5 points] Circle true or false for each of the following statements. [true / false] [true / false] Bubble Sort O(N 2 ) in the best case. Heap Sort uses a binary search tree to sort data. [true / false] Selection sort is always O(N 2 ). [true / false] [true / false] Quick Sort is O(N log2n) in the worst case. Merge Sort uses more memory than Quick Sort. 8

Binary Trees 20 points [5 points] Assume that a binary tree with one node has height = 1. What is the largest number of nodes possible with a tree with height = H? A) H B) H 2 C) 2 H - 1 D) 2 H-1-1 E) None of the above [5 points] Assume we are given the following binary search tree. Modify this diagram to show what the tree would look like if we used the standard algorithm to delete the value 83 from this binary search tree. Root 75 60 83 43 80 12 45 81 [5 points] Assume we are given the following binary search tree. Modify this diagram to show what the tree would look like if we used the standard algorithm to insert the value 66 into this binary search tree. Root 75 50 88 24 76 91 42 9

[5 points] Assume that we are given the following C++ declarations for a binary search tree node. Write a function that takes in the pointer to the root of the tree and prints all of the values in the tree in reverse numerical order. class Node public: int value; Node * left; Node * right; }; Heaps 20 points [5 points] Starting with the heap below, draw the heap after inserting the value 79 into the heap. 81 64 71 22 12 13 10

[5 points] Starting with the heap below, draw the heap after deleting one value from the heap. 81 64 71 22 12 13 [10 points] Circle true or false for each of the following statements. [true / false] A heap must be a complete binary tree. [true / false] The value of a parent must be greater than all its children. [true / false] The value of the left child must be less than the right child. [true / false] Insertion into a heap is O(log2N). [true / false] Deletion from a heap is O(N). [true / false] All heaps are also binary search trees. [true / false] Heaps can be used to sort data. [true / false] Heaps can be implemented using an array. [true / false] Heaps are filled from top to bottom, right to left. [true / false] Heaps can be implemented using nodes with 3 pointers. 11

Hash Tables 20 points [5 points] Assume that we have a hash table that uses separate chaining to resolve collisions. If the table is 100 long, what is the maximum number of entries that can be placed in the hash table? A) 100 B) 200 C) 99 D) 101 E) There is no pre-defined maximum. [5 points] Suppose we have implemented a hash table with linear probing to resolve collisions. The key values being stored are positive integers, and the hash function is given by key modulo table size. What will the hash table contain if the table size is 10, and we insert the following sequence of key values 71, 52, 10, 4, 41, 63, 150? Assume the array was initialized to 1. A) 10, 71, 52, 41, 4, 63, 150, -1, -1, -1 } B) 10, 71, 41, 63, 52, 150, 4, -1, -1, -1 } C) 71, 63, 10, 41, 52, 150, 4, -1, -1, -1 } D) 150, 41, 52, 63, 4, 71, 10, -1, -1, -1 } E) 150, 41, 52, 63, 4, -1, -1, -1, -1, -1 } [5 points] When must the size of the hash table be a prime number? A) When the hash table is very large. B) When linear probing is used to resolve collisions. C) When there are a lot of collisions. D) When secondary hashing is used to resolve collisions. E) None of the above. [5 points] Assume that we have an array based hash table of size 1000 and we have inserted 300 items into the hash table. The fraction of the hash table that is filled is alpha = 300 / 1000 = 0.3. What is the formula that will tell us how many collisions we can expect to have when we insert the next value into the hash table? The end! A) 1000 / (300 alpha) B) 1000 / 300 C) (1 alpha) / 1 D) 1 / (1 alpha) E) alpha / (1 + alpha) 12