Unsolved Midterm Exam #2 - Algorithms and Data Structures | CS 200, Exams of Computer Science

Material Type: Exam; Professor: Howe; Class: Algorithms and Data Structures; Subject: Computer Science; University: Colorado State University; Term: Fall 2007;

Typology: Exams

Pre 2010

Uploaded on 03/19/2009

koofers-user-sca
koofers-user-sca 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS200 Midterm 2
Fall 2007
Name ________________________________
Topic
Possible
Received
Generics, programming
10
Trees
35
Priority Queues, Heaps
30
Graphs
25
TOTAL
100
pf3
pf4
pf5

Partial preview of the text

Download Unsolved Midterm Exam #2 - Algorithms and Data Structures | CS 200 and more Exams Computer Science in PDF only on Docsity!

CS200 Midterm 2 Fall 2007

Name ________________________________

Topic Generics, programming Possible 10 Received

Trees Priority Queues, Heaps 3530

Graphs TOTAL 10025

1. a. Generics/Programming [10 points] [4 points] Why is it important to create a toString method in a new data structure

implementation?

b. [6 points] Spot the bugs in the following code. Underline each problem and suggest a fix for it. Make clear which problem is being fixed by which modification.

ArrayList someN someNums.add(0); ums = new ArrayList(); ArrayList moreNums = someNums; Integer first = moreNums.get(0);

2. a. Trees [35 points] [7 points] Circle T or F for True or False for the following statements.

T F A preorder traversal of a binary sea vertices. rch tree produces a lexicographic ordering of the T F A full (Rosen’s definition) 3-ary tree with 49 vertices has 32 leaves. T F A full (either definition) binary tree with 64 leaves has 63 internal vertices. T F A tree is a graph. T F A preorder traversal of a heap produces a lexicographic ordering of the vertices. T F A binary tree with 256 vertices has a maximum height of 8. T F A balanced tree is a complete tree.

c. [8 points] Draw the binary search tree that results i. from adding, in this order, the letters: M A I B D C T E F R

ii. then draw the tree that results after removing the failing grades: D and F

d. [5 points] Short Answer. Traversals are defined over ordered rooted trees. Why is it necessary to have ordered rooted trees?

3. a. Priority Queues/Heaps [30 points] [6 points] Short Answer. Carrano and Prichard describe a Priority Queue as a special case of

the ADT Table. What is a Table? How can a Priority Queue be a Table?

b. T F[8 points] Circle T or F for True or False for the following statements. A binary search tree implementation of the Table ADT has non-linear Big-O for retrieval

T F in average case.A Table cannot be implemented using a linked list. T F The array [5, 18, 101, 30, 22, 202, 101] is a heap with root as minimum value. T F When a value is removed from the heap [10, 101, 12, 231, 102, 72, 1 becomes [12, 101, 231, 102, 72, 142]. 42], the array T F A semiheap is a complete binary tree. T F The rightmost leaf contains the first item to be removed from a heap implementation of a priority queue. T F Heapsort is O(n * log n) in the worst case. T F Heapsort can be made in place by iteratively constructing larger semi array becomes a heap. -heaps until the c. [10 points] Find and fix any bugs in the following code for maxheap. heapRebuild, assume it is a protected int child void =heapRebuild(int 2 * root; root) { if ( int child rightChild < items.size() = child )+ {1; if (compareItems(items.get(root), T temp = items.get(root); items.get(child)) > 0) { items.set(root, items.set(child, items.get(child)); temp); }^ heapRebuild(root); }^ }

d. [9 points] For the following graph,

i. show how it would be represented as an adjacency matrix.

ii. show the depth first traversal starting from vertex is offered, the alphabetically lower vertex is chosen and 2) the implementation is e, assuming that 1) whenever a choice recursive so that the program stack is used when backtracking.

a b c e d

f^6 (^7982)