Unsolved Midterm Exam #1 - 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-wig
koofers-user-wig 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS200 Midterm 1
Fall 2007
Name ________________________________
Topic
Possible
Received
SE/ADTS/OO
15
Grammars
16
Stacks, Queues and
Coding
25
Complexity
13
Recurrence
17
Divide & Conquer
14
TOTAL
100
pf3
pf4
pf5

Partial preview of the text

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

CS200 Midterm 1 Fall 2007

Name ________________________________

Topic SE/ADTS/OO Possible 15 Received

Grammars Stacks, Queues and 16

Coding Complexity 2513

Recurrence Divide & Conquer 1714

TOTAL 100

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 = | ^ following grammar: = B | C | D | F | G | H = A | E | I | O i. Show the top down derivation for BADDOG

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;