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

Size: px
Start display at page:

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

Transcription

1 CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Please check your tutorial (TUT) section from the list below: TUT 101: F 11:30, MC 4042 TUT 102: M 10:30, MC 4042 TUT 103: M 11:30, MC 4058 TUT 104: F 10:30, MC 4042 TUT 105: M 12:30, STJ 2009 TUT 106: Th 4:30, MC 4042 TUT 107: M 8:30, MC 4042 Uncertain Cheating is an academic offence. Your signature on this exam indicates that you understand and agree to the University s policies regarding cheating on exams. Signature: 1. The examination starts at 7:00 pm and ends at 9:00 pm. You may not leave for the first half hour or in the last ten minutes. 2. You should have 11 pages in this exam (including the cover page), plus a separate 2- sided reference sheet. 3. No additional materials are permitted. 4. Complete all answers in the spaces provided. 5. Write neatly so that you do not lose marks unnecessarily. 6. Proctors will only confirm or deny the existence of errors on the exam. In the case of perceived ambiguity, state a clear assumption and proceed to answer the question. Your assumption must not trivialize the question. Question # Out Of Marks Marker Total 60

2 Page 2 of 15 Student id: Question I Multiple Choice, True/False, Short Answer [21 Marks - 1 mark per question] There were 21 Multiple Choice/True-False/Short Answer questions on this exam worth a total of 21 marks. Question II Traversals [6 marks] a) [3 marks] Suppose we have the following results from performing an inorder and levelorder traversal on a binary tree: inorder: A, W, L, E, T, R level-order: W, A, T, E, R, L Construct all trees that are consistent with both traversals or show no such tree exists. b) [3 marks] Suppose we have the following results from performing a preorder traversal on a binary search tree containing numeric keys: preorder: 45, 32, 11, 29, 64, 50 Construct all trees that are consistent with the above traversal or show no such tree exists.

3 Question III Binary Search Trees [10 Marks] Page 3 of 15 Student id: a) [2 marks] Beginning with an empty binary search tree, what binary search tree is formed when you insert the following values in the order given: 1, 4, 3, 7, 5, 2, 6. You are only required to draw the final tree for all or nothing credit. If you draw the intermediate trees, you may receive partial credit. b) [2 marks] Show the two possible trees that result after the string kangaroo is removed from the binary search tree below using the binary search tree deletion algorithm.

4 Page 4 of 15 Student id: A perfect binary tree is tree where each node is either a leaf or has two children, and all leaves have the same depth. c) [2 marks] Give a perfect binary search tree with nodes labeled 1,2,3,4,5,6,7. d) [2 marks] You are given a binary search tree T where all nodes are uniquely labeled with integers between 1 and 99 inclusive (not all integers in that range are necessarily used). The root node is 4 and its left and right subtrees have the same height. Draw the tree that has the maximum possible sum over all the nodes? e) [2 marks] What is the worst case performance of searching for a key in a perfect binary search tree containing n keys. Give your answer in order notation in terms of n. Compare this to searching for a key in a possibly non-perfect binary search tree. Perfect: Non-Perfect:

5 Question IV Order Notation [10 Marks] Page 5 of 15 Student id: Use order notation to express the worst-case running time of each of the following code fragments in terms of n. Give as tight an asymptotic upper bound as possible. A println statement is considered to be an O(1) operation. a) b) c) d) e) int x = n; System.out.println( x ); for (int i = 1; i <= 10000; i++) { bigarray1[i] = bigarray2[i] + x; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { System.out.println( We want tight bounds! ); for( int i = 1; i <= n; i++ ) { x++; for(int i = 1; i <= n*n*n; i = i + n) { System.out.println( I love CS ); int i = 1; while (i < n) { i = i * 2; System.out.println( Enjoy CS 241 or CS 230! ); for( int i = 1; i <= n; i++ ) { if ( i == (n / 2) ) { for( int j = 0; j <= n* n ) { System.out.println( Halfway there! ); else { System.out.println( Lots to do, yet );

6 Page 6 of 15 Student id: 2 f) [3 marks] Prove by applying the definition of big-oh that f n) 5n 4n O n ( = is ( ) 2 g) [2 marks] Give two reasons that we might prefer an algorithm with an ( n ) over an algorithm with an O( n) running time. O running time

7 Question V Recursive Program [7 Marks] Page 7 of 15 Student id: A heap is a special binary tree which is either empty, or one where the value stored in all parent nodes in the tree is greater than all its children (if they exist). The following tree is a heap: Write the following two methods which could be added to any implementation of the ADT BinaryTreeInterface. You must use recursion whenever you need to traverse the tree. Specifically, you are not allowed to use for, while or do loops in any methods: public int maxvalue() { // pre: this is a heap of positive Integer objects // post: returns the maximum number contained in the heap, // or returns -1 if the tree is empty

8 Page 8 of 15 Student id: public boolean isheap() { // pre: all items in the tree are positive Integer objects // post: returns true if this is a heap

9 Question VI Inductive Proof [6 Marks] Page 9 of 15 Student id: Prove by induction on h that the number of leaves, L, in a tree of height h satisfy: L 2 h 1 For example, the following tree has two leaves and height 3 which satisfies the above relation: Use the space on the next page if you run out of room.

10 Question VI Inductive Proof Continued Page 10 of 15 Student id:

11 Question VII Sorting [12 Marks] Page 11 of 15 Student id: Carefully explain under what circumstances each of the following sorting algorithms would be the best sorting algorithm to use in an application. a) [1 mark] Mergesort b) [1 mark] Quicksort c) [1 mark] Selection sort d) [1 mark] Insertion sort e) [1 mark] Assume the array 20, 10, 80, 40, 15, 75 is sent as input to Selection Sort. Show the contents of the array immediately after the second swap f) [1 mark] Give an example of the best case input of size 6 for Insertion Sort. g) [1 mark] Assume the array 20, 10, 80, 40, 15, 5 is sent as input to Merge Sort. Show the contents of the array immediately before the final merge takes place. h) [1 mark] Assume the array 20, 10, 80, 40, 15, 75 is sent as input to Quick Sort. Show the contents of the array immediately after the first partition operation takes place. Use the first element as the pivot.

12 Page 12 of 15 Student id: i) [4 marks] Professor Dumbledore is developing a course on the Magic of Sorting. He proposes a new sorting algorithm called HogwartsSort based on the ideas of merge and selection sort. Using divide and conquer, we divide a full array (i.e. it is not partially filled) into two equal sized regions as we would for merge sort, until a region has less than n items. At that point each region is sorted using selection sort. Then the regions are merged as normal for merge sort. Complete the body of the HogwartsSort method as described above. Assume the existence of the merge and selectionsort methods described in the Sorting class of the Reference booklet. public static void HogwartsSort(Comparable[] ta, int first, int last){ // pre: 0 <= first <= last < ta.length and // ta and ta[first..last] are non-null // post: ta[first..last] is in ascending order i) [2 bonus marks] Analyze the running time of HogwartsSort. Do not attempt this until you have finished the rest of the exam. Show your work on the back of the previous page, but put your final answer here.

13 Page 13 of 15 Student id: Question VIII Searching Ordered Arrays [9 Marks] [6 marks] Recall that binary search splits the array in half. Suppose we wrote a variation of binary search which narrowed the search range to either the first, middle or last third of the array. Write the recursive body of this trisearch method assuming that it would appear inside of an ordered array implementation of the table ADT. Note the return type of the method. public class OrderedArray implements TableInterface { private KeyedItem[] items; // instance variable holding the sorted array private int size; // number of items in the table private KeyedItem trisearch( int lo, int hi, Comparable key ) { // pre: 0 <= lo < size; 0 <= hi < size; key!= null // post: if key is in items[lo..hi], return the corresponding KeyedItem // otherwise return null

14 Page 14 of 15 Student id: [2 marks] Suppose the initial number of items is N, where N is a power of 3. How many times is the trisearch method called in the worst case (including the original call)? Give the exact answer, and justify your answer. [1 mark] Is this version of searching asymptotically more efficient than binary search? Justify in one sentence.

15 Question IX Iterators [4 Marks] Page 15 of 15 Student id: Write a method which creates a duplicate copy of an existing TableInterface, T. This copy will contain exactly the same set of KeyedItems as the original. You should not alter the contents of T You can assume that the TableInterface defines a method tabletraverse which returns an Iterator for the given table (see the reference sheet) public static TableInterface duplicate ( TableInterface T ) { // pre: T is non-null // post: returns a new TableInterface containing the same set of // KeyedItems as T

CS126 Final Exam Review

CS126 Final Exam Review CS126 Final Exam Review Fall 2007 1 Asymptotic Analysis (Big-O) Definition. f(n) is O(g(n)) if there exists constants c, n 0 > 0 such that f(n) c g(n) n n 0 We have not formed any theorems dealing with

More information

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

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

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

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

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

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001 CPSC 211, Sections 201 203: Data Structures and Implementations, Honors Final Exam May 4, 2001 Name: Section: Instructions: 1. This is a closed book exam. Do not use any notes or books. Do not confer with

More information

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE 332, Spring 2010, Midterm Examination 30 April 2010 CSE 332, Spring 2010, Midterm Examination 30 April 2010 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note. You may use a calculator for basic arithmetic only.

More information

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

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer Prelim 2 CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam is closed

More information

CSE373 Fall 2013, Midterm Examination October 18, 2013

CSE373 Fall 2013, Midterm Examination October 18, 2013 CSE373 Fall 2013, Midterm Examination October 18, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

ECE368 Exam 2 Spring 2016

ECE368 Exam 2 Spring 2016 ECE368 Exam 2 Spring 2016 Thursday, April 7, 2016 15:00-16:15pm ARMS 1010 READ THIS BEFORE YOU BEGIN This is a closed-book, closed-notes exam. Electronic devices are not allowed. The time allotted for

More information

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

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 FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

(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

(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 CPS 100 Exam 2 Solutions Spring 199 Dr Rodger 1 (3 pts) A virtual function in C++ is bound dynamically or statically? dynamic 2 (3 pts) When does one use a class template in C++? Templates are used to

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

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

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader Prelim 2 CS 2110, November 19, 2015, 7:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed

More information

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place? Sorting Binary search works great, but how do we create a sorted array in the first place? Sorting in Arrays Sorting algorithms: Selection sort: O(n 2 ) time Merge sort: O(nlog 2 (n)) time Quicksort: O(n

More information

CSE373 Winter 2014, Midterm Examination January 29, 2014

CSE373 Winter 2014, Midterm Examination January 29, 2014 CSE373 Winter 2014, Midterm Examination January 29, 2014 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

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

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

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

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014 FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CSC3A10 ADVANCED DATA STRUCTURES AND ALGORITHMS CAMPUS APK EXAM EXAMINATION JUNE 2014 DATE 2014-06-03 SESSION 12:30 15:30

More information

ECE250: Algorithms and Data Structures Midterm Review

ECE250: Algorithms and Data Structures Midterm Review ECE250: Algorithms and Data Structures Midterm Review Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012 1 University of Toronto Department of Electrical and Computer Engineering Midterm Examination ECE 345 Algorithms and Data Structures Fall 2012 Print your name and ID number neatly in the space provided

More information

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

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin CS 61B Summer 2005 (Porter) Midterm 2 July 21, 2005 - SOLUTIONS Do not open until told to begin This exam is CLOSED BOOK, but you may use 1 letter-sized page of notes that you have created. Problem 0:

More information

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

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Binary Search Trees Treesort

Binary Search Trees Treesort Treesort CS 311 Data Structures and Algorithms Lecture Slides Friday, November 13, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009

More information

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer Prelim 2 Solutions CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam

More information

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

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You

More information

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

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader Prelim 2 CS 2110, November 19, 2015, 7:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed

More information

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

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1. Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Quiz 1 Quiz 1 Do not open this quiz booklet until you

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00 University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides: none 18 pages Final Examination

More information

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

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

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

Computing Science 115 Final Examination April 23, 2002 Section: B2 BASU. Please put student id on last page. Instructions: Computing Science 115 Final Examination April 23, 2002 Section: B2 BASU Last Name: First Name: Please put student id on last page Instructions: The time for this test is 3 hrs. No references or calculators

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

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

Total Score /1 /20 /41 /15 /23 Grader NAME: NETID: CS2110 Spring 2015 Prelim 2 April 21, 2013 at 5:30 0 1 2 3 4 Total Score /1 /20 /41 /15 /23 Grader There are 5 questions numbered 0..4 on 8 pages. Check now that you have all the pages. Write

More information

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

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader Prelim 2 CS 2110, November 19, 2015, 5:30 PM 1 2 3 4 5 6 Total Question True Short Complexity Searching Trees Graphs False Answer Sorting Invariants Max 20 15 13 14 17 21 100 Score Grader The exam is closed

More information

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010 University of Toronto Department of Electrical and Computer Engineering Midterm Examination ECE 345 Algorithms and Data Structures Fall 2010 Print your name and ID number neatly in the space provided below;

More information

Data Structures and Algorithms Week 4

Data Structures and Algorithms Week 4 Data Structures and Algorithms Week. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Week Divide and conquer Merge

More information

Data Structures and Algorithms Chapter 4

Data Structures and Algorithms Chapter 4 Data Structures and Algorithms Chapter. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Chapter Divide and conquer

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

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

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA   === Homework submission instructions === Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA email: dsa1@csientuedutw === Homework submission instructions === For Problem 1, submit your source code, a Makefile to compile

More information

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please

More information

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 MID YEAR COMP103 Introduction to Data

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

More information

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, January 29/Tuesday, January 30

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, January 29/Tuesday, January 30 CIS 11 Data Structures and Algorithms with Java Spring 018 Code Snippets and Recurrences Monday, January 9/Tuesday, January 30 Learning Goals Practice solving recurrences and proving asymptotic bounds

More information

Data Structures and Algorithms. Roberto Sebastiani

Data Structures and Algorithms. Roberto Sebastiani Data Structures and Algorithms Roberto Sebastiani roberto.sebastiani@disi.unitn.it http://www.disi.unitn.it/~rseba - Week 0 - B.S. In Applied Computer Science Free University of Bozen/Bolzano academic

More information

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum

Table ADT and Sorting. Algorithm topics continuing (or reviewing?) CS 24 curriculum Table ADT and Sorting Algorithm topics continuing (or reviewing?) CS 24 curriculum A table ADT (a.k.a. Dictionary, Map) Table public interface: // Put information in the table, and a unique key to identify

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

CSE 373 Spring Midterm. Friday April 21st

CSE 373 Spring Midterm. Friday April 21st CSE 373 Spring 2006 Data Structures and Algorithms Midterm Friday April 21st NAME : Do all your work on these pages. Do not add any pages. Use back pages if necessary. Show your work to get partial credit.

More information

CS 171: Introduction to Computer Science II. Quicksort

CS 171: Introduction to Computer Science II. Quicksort CS 171: Introduction to Computer Science II Quicksort Roadmap MergeSort Recursive Algorithm (top-down) Practical Improvements Non-recursive algorithm (bottom-up) Analysis QuickSort Algorithm Analysis Practical

More information

Faster Sorting Methods

Faster Sorting Methods Faster Sorting Methods Chapter 9 Contents Merge Sort Merging Arrays Recursive Merge Sort The Efficiency of Merge Sort Iterative Merge Sort Merge Sort in the Java Class Library Contents Quick Sort The Efficiency

More information

Computer Science E-22 Practice Final Exam

Computer Science E-22 Practice Final Exam name Computer Science E-22 This exam consists of three parts. Part I has 10 multiple-choice questions that you must complete. Part II consists of 4 multi-part problems, of which you must complete 3, and

More information

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

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE CSI33 Sample Final Exam NAME Directions: Solve problems 1 through 5 of Part I and choose 5 of the

More information

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings. CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop promptly

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

More information

Sorting and Selection

Sorting and Selection Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element

More information

CS211 Spring 2005 Prelim 2 April 19, Instructions

CS211 Spring 2005 Prelim 2 April 19, Instructions CS211 Spring 2005 Prelim 2 April 19, 2005 Name NetId Instructions Write your name and Cornell netid above. There are 8 questions on 11 numbered pages. Check now that you have all the pages. Write your

More information

Tree Structures. A hierarchical data structure whose point of entry is the root node

Tree Structures. A hierarchical data structure whose point of entry is the root node Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and

More information

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

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

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

Prelim 2. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs. Max Score Grader Prelim 2 5:30 PM, 25 April 2017 1 2 3 4 5 6 Total Question Name Short Search/ Collections Trees Graphs answer sort stuff Max 1 26 18 15 20 20 100 Score Grader The exam is closed book and closed notes.

More information

ECE242 Data Structures and Algorithms Fall 2008

ECE242 Data Structures and Algorithms Fall 2008 ECE242 Data Structures and Algorithms Fall 2008 2 nd Midterm Examination (120 Minutes, closed book) Name: Student ID: Question 1 (10) 2 (20) 3 (25) 4 (10) 5 (15) 6 (20) Score NOTE: Any questions on writing

More information

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014 CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want

More information

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

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs Prelim 2, CS2110 7:30 PM, 25 April 2017 1 2 3 4 5 6 Total Question Name Short Search/ Collections Trees Graphs answer sort stuff Max 1 26 18 15 20 20 100 Score Grader The exam is closed book and closed

More information

CPSC 320 Midterm 2 Thursday March 13th, 2014

CPSC 320 Midterm 2 Thursday March 13th, 2014 CPSC 320 Midterm 2 Thursday March 13th, 2014 [12] 1. Answer each question with True or False, and then justify your answer briefly. [2] (a) The Master theorem can be applied to the recurrence relation

More information

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

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4) CS210 Data Structures (171) Final Exam Name: ID Instructions: This exam contains four questions with multiple parts. Time allowed: 180 minutes Closed Book, Closed Notes. There are 10 pages in this exam

More information

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

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002 CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002 Name: Instructions: 1. This is a closed book exam. Do not use any notes or books, other than your 8.5-by-11 inch review sheet. Do not confer

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science 302 Spring 2007 Practice Final Examination: Part I Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will

More information

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT. Week 10 1 2 3 4 5 6 Sorting 7 8 General remarks We return to sorting, considering and. Reading from CLRS for week 7 1 Chapter 6, Sections 6.1-6.5. 2 Chapter 7, Sections 7.1, 7.2. Discover the properties

More information

c) A perfect ternary tree of height h? (In a ternary tree, each node may have up to three children.)

c) A perfect ternary tree of height h? (In a ternary tree, each node may have up to three children.) Spring 2007 C343 Final Name: Username: Question 1 (10 points): How many nodes can there be in: a) A complete binary tree of height h? b) A perfect binary tree of height h? c) A perfect ternary tree of

More information

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION /08:30-9:50 RCH 105, RCH 110

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION /08:30-9:50 RCH 105, RCH 110 ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION 2009-10-29/08:30-9:50 RCH 105, RCH 110 Instructions: There are 70 marks and the examination will be marked out of 65. No aides. Turn off all

More information

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

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Fall 2015 P. N. Hilfinger Test #2 READ THIS PAGE FIRST. Please do not discuss this exam

More information

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302 ECE 250 Algorithms and Data Structures MIDTERM EXAMINATION Douglas Wilhelm Harder dwharder@uwaterloo.ca EIT 4018 x37023 2013-10-23T09:30:00P1H20M Rooms: RCH-103 and RCH-302 Instructions: Read and initial

More information

ECE 250 Algorithms and Data Structures

ECE 250 Algorithms and Data Structures ECE 250 Algorithms and Data Structures Sections 001 and 002 FINAL EXAMINATION Douglas Wilhelm Harder dwharder@uwaterloo.ca EIT 4018 x37023 2014-04-16T09:00P2H30M Rooms: PAC 7, 8 If you are writing a supplemental

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

COMP 250 Midterm #2 March 11 th 2013

COMP 250 Midterm #2 March 11 th 2013 NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;

More information

CS314 Exam 2 - Spring Suggested Solution and Criteria 1

CS314 Exam 2 - Spring Suggested Solution and Criteria 1 CS314 Spring 2016 Exam 2 Solution and Grading Criteria. Grading acronyms: AIOBE - Array Index out of Bounds Exception may occur BOD - Benefit of the Doubt. Not certain code works, but, can't prove otherwise

More information

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006 Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006 There are 4 problems on this exam. It is 8 pages long, so make sure you have the whole exam. You will have 1 1 hours

More information

TREES. Trees - Introduction

TREES. Trees - Introduction TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures 9//207 ITEC2620 Introduction to Data Structures Lecture b Recursion and Binary Tree Operations Divide and Conquer Break a problem into smaller subproblems that are easier to solve What happens when the

More information

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;

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; 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; } if (n

More information

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT. Week 10 1 Binary s 2 3 4 5 6 Sorting Binary s 7 8 General remarks Binary s We return to sorting, considering and. Reading from CLRS for week 7 1 Chapter 6, Sections 6.1-6.5. 2 Chapter 7, Sections 7.1,

More information

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

Suppose that the following is from a correct C++ program: All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25 Multi-way Search Trees (Multi-way Search Trees) Data Structures and Programming Spring 2017 1 / 25 Multi-way Search Trees Each internal node of a multi-way search tree T: has at least two children contains

More information

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

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

COS 226 Midterm Exam, Spring 2009

COS 226 Midterm Exam, Spring 2009 NAME: login ID: precept: COS 226 Midterm Exam, Spring 2009 This test is 10 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators

More information

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Midterm Examination Douglas Wilhelm Harder 1.5 hrs, 2005/02/17 11 pages Name (last, first):

More information

APCS :: Winter Quarter Exam Review Packet

APCS :: Winter Quarter Exam Review Packet APCS :: Winter Quarter 2007 -- Exam Review Packet O(n 2 ) Sorting algorithms. You should be able to derive the code for any of the three O(n 2 ) sorting algorithms in the following manner: 1. Assume you

More information

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Final Examination Instructors: RESeviora and LTahvildari 3 hrs, Apr, 200 Name: Student ID:

More information

Final Examination Semester 1 / Year 2011

Final Examination Semester 1 / Year 2011 Southern College Kolej Selatan 南方学院 Final Examination Semester 1 / Year 2011 COURSE : DATA STRUCTURE AND ALGORITHM COURSE CODE : PROG2103 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : SO

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions: VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

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

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

Lecture 5: Sorting Part A

Lecture 5: Sorting Part A Lecture 5: Sorting Part A Heapsort Running time O(n lg n), like merge sort Sorts in place (as insertion sort), only constant number of array elements are stored outside the input array at any time Combines

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Sample Exam 1 75 minutes permitted Print your name, netid, and

More information

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

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% Name ID Directions: There are 9 questions in this exam. To earn a possible full score, you must solve all questions. Time allowed: 180 minutes Closed

More information

Chapter 10. Sorting and Searching Algorithms. Fall 2017 CISC2200 Yanjun Li 1. Sorting. Given a set (container) of n elements

Chapter 10. Sorting and Searching Algorithms. Fall 2017 CISC2200 Yanjun Li 1. Sorting. Given a set (container) of n elements Chapter Sorting and Searching Algorithms Fall 2017 CISC2200 Yanjun Li 1 Sorting Given a set (container) of n elements Eg array, set of words, etc Suppose there is an order relation that can be set across

More information