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

Similar documents
CS 315 Data Structures mid-term 2

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

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

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

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

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

Exam Data structures DIT960/DAT036

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

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

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

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

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

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

UNIT III BALANCED SEARCH TREES AND INDEXING

Practice Midterm Exam Solutions

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

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

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

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

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?

CS 223: Data Structures and Programming Techniques. Exam 2

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

Second Examination Solution

Binary Heaps. COL 106 Shweta Agrawal and Amit Kumar

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Computer Science E-22 Practice Final Exam

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

CSE373 Fall 2013, Midterm Examination October 18, 2013

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

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSCI2100B Data Structures Heaps

Topics for CSCI 151 Final Exam Wednesday, May 10

CSCE 2014 Final Exam Spring Version A

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

Readings. Priority Queue ADT. FindMin Problem. Priority Queues & Binary Heaps. List implementation of a Priority Queue

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

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Midterm solutions. n f 3 (n) = 3

Priority Queues Heaps Heapsort

Data Structures in Java

Algorithms and Data Structures

Exam Data structures DAT036/DAT037/DIT960

Q1 Q2 Q3 Q4 Q5 Q6 Total

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Binary Heaps. CSE 373 Data Structures Lecture 11

Data Structures and Algorithms 2018

Recall: Properties of B-Trees

Priority Queues. 04/10/03 Lecture 22 1

CS301 - Data Structures Glossary By

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

) $ f ( n) " %( g( n)

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Data Structures and Algorithms

Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1

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

CSE332 Summer 2010: Midterm Exam Sample Solutions

list<t>::const_iterator it1 = lst.begin(); // points to first element list<t>::const_iterator it2 = lst.begin(); // points to second element it2++;

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

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

COMP Analysis of Algorithms & Data Structures

Course Review for Finals. Cpt S 223 Fall 2008

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

Major2 Examination Term: 162 Year: 2016/2017

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

Augmenting Data Structures

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

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

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

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

COS 226 Midterm Exam, Spring 2009

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

CS-301 Data Structure. Tariq Hanif

COMP Data Structures

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

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

Priority Queues Heaps Heapsort

ADT Priority Queue. Heaps. A Heap Implementation of the ADT Priority Queue. Heapsort

CSE 373: Practice Final

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

CS 315 April 1. Goals: Heap (Chapter 6) continued review of Algorithms for Insert DeleteMin. algoritms for decrasekey increasekey Build-heap

Data structures. Organize your data to support various queries using little time and/or space

CS 350 : Data Structures Binary Search Trees

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

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

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

About this exam review

Fall, 2015 Prof. Jungkeun Park

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

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

CMSC 341 Lecture 14: Priority Queues, Heaps

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

CMSC 341 Lecture 15 Leftist Heaps

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

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Data Structures. Giri Narasimhan Office: ECS 254A Phone: x-3748

Practice final for EECS 380, 2001: Prof Markov

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Transcription:

CS 315 Data Structures Spring 2012 Final examination Total Points: 80 Name This is an open-book/open-notes exam. Write the answers in the space provided. Answer for a total of 80 points, including at least THREE of the last FOUR questions (17 to 20). 1) The best expression for the worst-case number of operations involved in inserting a key into a binary search tree of size n: 2 points (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) (e) O(n 2 ) 2) Which of the following operations can be performed efficiently in a binary heap in the worst-case? (Efficient means O(log n) or faster.) 3 points 1. find-min 2. delete-min 3. delete(x) for a given key x 4. insert(x) for a given key x Choose the correct answer: (a) all except (4) (b) all except (3) (c) all except (1) (d) all except (2) (e) all of them 3) Sum of the series 1 + 3 + 5 + 7 +... added to N terms is 66049. What is the value of N? 5 points

4) Which of the following are requirements of a good hash function? 3 points (a) it should be easy to compute. (b) it should use all the digits of the input. (c) it should allow the searching for a key to be done in O(log n) in the worst-case. (A) (a) only (B) (a) and (b) (C) (a) and (c) (D) (c) only (E) all of them. 5) What is F(100) where F is defined by the following recursive function? 3 points int F(int x) { if (x == 1) return 1; else return 2*F(x-1); } 6) Which of the following operations can be performed efficiently (i.e., in time O(log n) or constant time) in an AVL tree in the worst-case? 3 points (a) insert (b) deletemin (c) successor (d) findmin Circle the correct answer. (1) (a) and (b) (2) all of them (3) all except (c) (4) (a) and (d) (5) none of them 7) How many AVL trees are there with keys 1, 2 and 3? 2 points 8) The reason for doubling a hash table size when the load factor becomes ~ 0.5 is: 3 points (a) The hash function h becomes unusable when > 0.5 (b) the cost of search becomes high when > 0.5 (c) lazy deletion is not possible for > 0.5 Circle the correct answer: (A) (a) only (B) (b) only (C) (a) and (b) (D) (b) and (c) (E) none of the above.

9) State two reasons for choosing the hash-table size to be a prime number. 3 points 10) Name the two sorting algorithms with worst-case time complexity O(n log n). 3 points 11) Consider the partitioning step of Quicksort using the key 9 as pivot. What will be the contents of A after the partition step? The algorithm to be used is the first partition algorithm, not the one that uses median-of-three partition. 5 points Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 A 3 12 7 4 10 6 13 19 5 4 9 3 10 1 left = 4, right = 10 ANSWER: Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 A 12) What is the exact number of key comparisons performed by insertion sorting on the following input? 4 points 12 3 5 8 7 9 4 1 Answer: 13) The reason quick sort switches to insertion sort for small input size are the following: a. Otherwise, the output will be wrong b. Otherwise the pivot will be chosen incorrectly. c. Insertion sort is faster than quick sort when the array size is small.

Choose the correct answer: 3 points (1) (a) and (b) (2) all of them (3) all except (c) (4) (c) only (5) none of them 14) Show the result of inserting the key 64 into the AVL tree shown: 5 points

15) Exhibit the resulting heap if DELETEMIN operation is performed on the heap below: (Assume the algorithm presented in class is used to perform DELETEMIN.) Show the current heap as well as the resulting heap as tree. 5 points index 1 2 3 4 5 6 7 8 9 10 11 12 Heap-array 5 8 6 11 14 7 9 11 14 18 15 8 16) Which of the following operations can be performed efficiently (i.e., in time O(log n) or constant time) on a sorted array A? n denotes the size of the array. 3 points 1) Search(A,x) 2) findmin(a) 3) delete(a,x) Circle the correct answer: (a) 1 and 3 (b) 1 and 2 (c) 2 and 3 (d) all of them (e) 1 only

17) Consider a balanced parenthesis string such as ((a(bc)a)d) that contains alphabetical symbols in addition to parentheses. Write a function calculate_depth that takes such an input string and computes the depth of each alphabetical symbol. For example, the output for the input string x above should be the vector [2 3 3 2 1]. 8 points vector<int> calculate_depth(string x)

18) Consider the following augmented binary search tree in which each node has an extra field that stores the size of the subtree rooted at that node. An example of such a tree is shown below. The first key in the node is the usual key, and the second one is the size. Rewrite the function delete to delete a key from an augmented binary search tree. (Your algorithm should have time complexity O(h)). Assume the fields of a BinaryNode are Left, Right, Key and Size.) 12 points This function returns a pointer to the deleted node. BinaryNode* delete(const Comparable & x, BinaryNode * & t) // delete x from the tree rooted at t

18) Write a function test_heap that takes an array A of size n as input, and outputs k such that k is the largest integer such that the first k keys form a min-heap. For example, if the input array is [8, 11, 19, 20, 9, 23], the output should be 4 since A[1..4] forms a min-heap, but A[1:5] is not a minheap. Obtain the worst-case time complexity of your algorithm in terms of n. 8 points int test_heap(int[] A, int n)

19) Write a function level_print that prints all the nodes of a binary tree in the following order: level 0 (root), level 1 (children of level 0) from left to right, then level 2 (children of level 1) from left to right etc. Thus for the tree shown below, level_print will output the sequence: 15 10 30 5 20 40 4 7. Assume the usual tree representation with each node having a key and pointers to left and right children. 8 points (Hint: Use a queue.) void level_print(tree* T)

20) A closed hash-table is shown below. The table was built using double hashing, with primary hash function h(x) = x % 13, and secondary hash function s(x) = 5 (x % 5). Index key status 0 26 1 1 0 2 0 3 42 1 4 17 1 5 0 6 172 1 7 33 2 8 21 1 9 35 1 10 0 11 0 12 0 12 points a. What is the expected number of probes for a successful search in this hash table? (Calculate the number of probes for each key in the table and average it.) b. Suggest a key that requires the maximum number of probes to insert into the hash table. c. What is the position in which the key 32 will get inserted? d. Is there any problem with using s (x) = x % 5 as the secondary hash function? Explain.