



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Howe; Class: Algorithms and Data Structures; Subject: Computer Science; University: Colorado State University; Term: Fall 2007;
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




1. Software Engineering/ADTS/OO [1 a. [10 points] Match the terms (draw a line between them) in the left column to 5 points] i. verification^ the definitions on the right: a. condition that is always true at a certain ii. invariant point in the programb. what can be accessed from outside a class iii. abstraction iv. interface c. formally confirming some functionalityd. UML link to indicate inheritance v. generalization e. separate implementation from use b. [5 points] Why are generics useful? 2. Grammars [16 points] a. [8 points] Given the alphabet {A, B, C, D, E, F, G, H, I, O} and the = |
b. [5 points] As the last question indicates, specific data structures such as ArrayLists can be used to implement Queues. Explain briefly how this can be done in such that the invariants of the Stack or Queue are not violated.
c. (^) fill in the code for the methods[14 points] For this Stack implementation which is taken from the text, push and pop. (Some code has been public final int^ omitted for space considerations; this is indicated with …) class StackArrayBased implements StackInterfac MAX_STACK = 50; e { private Object private int top; items[]; public public public StackArrayBased() { … }booleanBoolean isEmpty() { … }isFull() { … } public void push(Object newItem) throws StackException {
} public Object pop() throws StackException {
} … }
4. Complexity [13 points] a. [4 points] For the following functions, determine which big-O best characterizes it. Choose from this set:
!
n^2 , log n , 1 , n !, n^3 , n log 2 n , n^4 , n , 2 n i. !
f ( n ) = 2 + 5 + ...+ ( 3 n " 1 ) ii. !
f ( n ) = 12 n + 6 log 2 n b. [9 points] For the following algorithms, determine which big characterizes it for the worst case. Choose from this set: -O best
!
n^2 , log n , 1 , n !, n^3 , n log 2 n , n^4 , n , 2 n i. An algorithm that prints all binary numbers with two zeros in them that are of length n.
ii. An algor students.ithm that calculates the average grade on a midterm with n
iii. (^) forThis algorithm counting i = 1 to n/2 print{ statements: for j for = (^1) k to= 125 to { i { while (n > 0)^ print {^ ijk^ }}} print n--; }n*n;