CPSC 331 Term Test #2 March 26, 2007

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

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

1. Attempt any three of the following: 15

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

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

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

ECE250: Algorithms and Data Structures Midterm Review

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

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

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

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

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

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

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

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

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

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Quiz 1 Practice Problems

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

Course Review. Cpt S 223 Fall 2009

CSL 201 Data Structures Mid-Semester Exam minutes

Student number: Datenstrukturen & Algorithmen page 1

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

COMP 250 Midterm #2 March 11 th 2013

CSE 373 Spring Midterm. Friday April 21st

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

Elementary Data Structures 2

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

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

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

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

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

Programming II (CS300)

Course Review for Finals. Cpt S 223 Fall 2008

Prelim 2 SOLUTION. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

ECE242 Data Structures and Algorithms Fall 2008

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Final Exam in Algorithms and Data Structures 1 (1DL210)

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

Quiz 1 Practice Problems

Code No: R Set No. 1

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

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;

Friday Four Square! 4:15PM, Outside Gates

Part 1: Written Questions (60 marks):

CS301 - Data Structures Glossary By

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

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

Exam Data structures DAT036/DAT037/DIT960

Final Examination CSE 100 UCSD (Practice)

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

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

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

Module 2: Classical Algorithm Design Techniques

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

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

Summer Final Exam Review Session August 5, 2009

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

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

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?

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

(b) If a heap has n elements, what s the height of the tree?

Exam Data structures DAT036/DAT037/DIT960

a) For the binary tree shown below, what are the preorder, inorder and post order traversals.

CS61B Fall 2014 Guerrilla Section 2 This worksheet is quite long. Longer than we ll cover in guerrilla section.

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Prelim 2, CS2110. SOLUTION

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

AP Computer Science 4325

CSE wi: Practice Midterm

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

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

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

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

Exam Datenstrukturen und Algorithmen D-INFK

Stores a collection of elements each with an associated key value

CSE100. Advanced Data Structures. Lecture 21. (Based on Paul Kube course materials)

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Total Score /1 /20 /41 /15 /23 Grader

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

DATA STRUCTURE. 1- What data structure can be used to check if a syntax has balanced paranthesis? A - queue B - tree C - list D - stack

CSE332 Summer 2010: Midterm Exam Sample Solutions

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CS171 Final Practice Exam

Section 05: Midterm Review

Computer Science 302 Fall 2009 (Practice) Second Examination, October 15, 2009

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

Computing Science 115 Final Examination April 23, 2002 Section: B2 BASU. Please put student id on last page. Instructions:

Transcription:

CPSC 331 Term Test #2 March 26, 2007 Name: Please DO NOT write your ID number on this page. Instructions: Answer all questions in the space provided. Point form answers are acceptable if complete enough to be understood. No Aids Allowed. There are a total of 50 marks available on this test. Duration: 90 minutes

ID Number: Question Score Available 1 10 2 10 3 9 4 14 5 7 Total: 50

ID Number: 1 (10 marks) 1. Short answer questions you do not need to provide any justifications for your answers. Just fill in your answer in the space provided. (a) True or false: binary search is especially well-suited for searching a dictionary that is implemented as an ordered linked list. Answer: (b) True or false: merge sort uses O(n) auxiliary space. Answer: (c) True or false: the insertion sort algorithm is faster than merge sort on data which is nearly sorted. Answer: (d) True or false: the double hashing technique yields hash functions that are useful with the chaining collision resolution mechanism. Answer: (e) Is the level-order traversal of a binary tree best implemented with a stack or a queue? Answer:

ID Number: 2 (f) In the binary tree below, which node follows Simula in a preorder traversal? Which node follows Simula in a postorder traversal? Preorder: Postorder: Java C++ Pascal Smalltalk C Algol Simula Fortran (g) Consider the search function for the dictionary abstract data type. Using big-oh notation, fill in the following table to indicate the worstcase asymptotic running time as a function of n, where n is the number of entries in the dictionary, assuming that the key being searched for is not in the dictionary. Data Structure worst-case running time red-black tree hash table with chaining hash table with open addressing

ID Number: 3 2. Consider the red-black tree data structure. (5 marks) (a) State the five properties satisfied by a binary search tree that is also a red-black tree. (2 marks) (b) Define the black height of a node in a red-black tree.

ID Number: 4 (3 marks) (c) Give an informal description of how black height is used to prove a worstcase bound on the height of a red-black tree.

ID Number: 5 3. Consider hash tables using the open addressing with linear probing collision resolution mechanism, using table size m = 7 and the hash function h(k, i) = k + ci (mod m), c = 2 for which we assume that the key k is an integer. (2 marks) (a) Draw the hash table (with the above table size and hash function) that would be produced by inserting the following values into an initially empty table: 17, 21, 38, 24 Your hash table: 0 1 2 3 4 5 6 (3 marks) (b) Describe an algorithm using pseudocode that can be used to search for a given value in a hash table with open addressing and linear probing using the hash function described above.

ID Number: 6 (2 marks) (c) Give one example of a set of 4 input values that, when inserted into an empty hash table as described above, would cause a search for the key 11 to result in the worst-case number of operations. Explain why your inputs do in fact result in a worst case for the search for 11. (2 marks) (d) What is the expected number of comparisons required for an unsuccessful search in the hash table using open addressing with linear probing and c = 1? Your answer should be given as a function of both n (number of values stored in the hash table) and m (the size of the hash table). Under what assumption(s) does this estimate hold?

ID Number: 7 4. The following questions deal with the Heap Sort algorithm. (2 marks) (a) Draw the binary tree representation of the Max-Heap stored in the following array: 0 1 2 3 4 5 20 10 8 3 5 4 (2 marks) (b) Give an array that represents the Max-Heap obtained after calling DeleteMax on the heap from Question 4a. Your array: 0 1 2 3 4 5

ID Number: 8 (3 marks) (c) Describe the MaxHeapify operation using pseudocode.

ID Number: 9 (3 marks) (d) Give a simple English description (or pseudocode if you prefer) of the DeleteMax algorithm.

ID Number: 10 (4 marks) (e) Give a simple English description (or pseudocode if you prefer) of the heap sort algorithm.

ID Number: 11 5. Consider the following algorithm for sorting an array. Assume that the function inorder(t, B) stores the result of an inorder traversal of a binary search tree T in an array B. TreeSort(A, n) Precondition: A is a array of n 1 integers Postcondition: returns array with the elements of A in increasing order Initialize T to be an empty binary search tree for i from 0 to n 1 do insert(t, A[i]) end for inorder(t, B) return B (3 marks) (a) What is the worst-case running time of this algorithm as a function of n, the number of integers in the array A? Justify your answer, and give a characterization of the input that results in the worst case. (2 marks) (b) What is the average-case running time of this algorithm as a function of n, the number of integers in the array A? Justify your answer.

ID Number: 12 (2 marks) (c) What is the worst-case running time of this algorithm as a function of n, the number of integers in the array A, assuming that a red-black tree is used instead of a binary search tree? Justify your answer.

ID Number: 13 Extra page for rough work.

ID Number: 14 Extra page for rough work.