Practice Exam 3 - Algorithms / Data Structures | CP SC 212, Exams of Algorithms and Programming

Material Type: Exam; Class: ALGS/DATA STRUCTURES; Subject: COMPUTER SCIENCE; University: Clemson University; Term: Summer 1 2009;

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-87u
koofers-user-87u 🇺🇸

1

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Some thoughts on Third Practice Test
Q1) In level-order the values are 3, 4, 9, 5, 6, 10, 16
Q2) a) Priority Queue b)
int Tig::returnSecondSmallest( )
{
if( isEmpty() )
return -1;
int min = removeMin();
int toReturn = -1;
if( !isEmpty() )
toReturn = removeMin();
insertItem(min);
return toReturn;
}
Q3) Many answers, all 28 bits. All have T encoded with 2 bits.
Q4) a) O(nlog n) and O(nlog n)
b) O(nlog n) and O(n2)
c) O(1) and O(n)
pf2

Partial preview of the text

Download Practice Exam 3 - Algorithms / Data Structures | CP SC 212 and more Exams Algorithms and Programming in PDF only on Docsity!

Some thoughts on Third Practice Test

Q1) In level-order the values are 3, 4, 9, 5, 6, 10, 16

Q2) a) Priority Queue b)

int Tig::returnSecondSmallest( ) { if( isEmpty() ) return -1; int min = removeMin(); int toReturn = -1; if( !isEmpty() ) toReturn = removeMin(); insertItem(min); return toReturn; }

Q3) Many answers, all 28 bits. All have T encoded with 2 bits.

Q4) a) O(n log n) and O(n log n) b) O(n log n) and O(n^2 ) c) O(1) and O(n)

Q5) a) 3. b) 5. c) 7

Q6) (assuming if even-length array then “middle” element is the central element with smaller index) So: pivot is median(1,3,2)= quicksort([1]) does nothing quicksort([4,7,3,5,8,6]) chooses pivot median(4,3,6)= and so on

Q7)

template Heap::Heap( ) : count(0), A(new T[100]) { }

template void Heap::insertItem(T newVal) { int bubble = count; int parent = (bubble-1)/2; // round down while( bubble>0 && newVal<A[parent] ) { A[bubble] = A[parent]; bubble = parent; parent = (bubble-1)/2; } A[bubble] = newVal; count++; }