University of Illinois at UrbanaChampaign
Department of Computer Science
Final Examination
CS 225 Data Structures and Software Principles
Fall 2009
710p, Tuesday, December 15
Name:
NetID:
Lab Section (Day/Time):
•
This is a
closed book
and
closed notes
exam. No electronic aids are allowed.
•
You should have 9 problems total on 19 pages. The last two sheets are scratch paper; you
may detach them while taking the exam, but must turn them in with the exam when you
leave.
•
Unless the problem speciﬁcally says otherwise, (1) assume the code compiles, and thus any
compiler error is an exam typo (though hopefully there are not any typos), (2) assume you
are NOT allowed to write any helper methods to help solve the problem, nor are you allowed
to use additional arrays, lists, or other collection data structures unless we have said you can,
and (3) assume the best possible design of a particular implementation is being used.
•
Please put your name at the top of each page.
Problem
Points
Score
Grader
1
20
2
10
3
20
4
15
5
20
6
20
7
20
8
15
9
20
Total
160
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
[Choices, Choices! – 20 points].
MC1 (2pts)
Suppose your goal is determine whether or not a graph contains a vertex that is connected to
no other vertices. How long does the best possible algorithm take if the graph is implemented
using adjacency lists? an adjacency matrix? (As always, assume there are
n
vertices and
m
edges.)
(a)
O
(1) for lists and
O
(
n
) for the matrix.
(b)
O
(
deg
(
v
)) for lists and
O
(
n
) for the matrix.
(c)
O
(
n
) for lists and
O
(
n
2
) for the matrix.
(d)
O
(
m
) for lists and
O
(
n
2
) for the matrix.
(e) None of these answers is correct.
MC2 (2pts)
When should a pointer parameter
p
be a reference parameter? (That is, when would it be
more appropriate for a parameter list to be
rather than
(myType * p)
?)
(a) When the function changes
p
, and you want the change to aﬀect the actual pointer
argument.
(b) When the function changes
p
, and you do NOT want the change to aﬀect the actual
pointer argument.
(c) When the function changes
*p
, and you want the change to aﬀect the object that is
pointed at.
(d) When the function changes
*p
, and you do NOT want the change to aﬀect the object
that is pointed at.
(e) When the pointer points to a large object.
MC3 (2pts)
Suppose we have implemented the
Stack
ADT as a singlylinkedlist with head and tail
pointers and no sentinels. Which of the following best describe the running times for the
functions
push
and
pop
, assuming there are
O
(
n
) items in the list, and that the bottom of
the stack is at the head of the list (all pushing and popping occurs at the tail)?
(a)
O
(1) for both functions.
(b)
O
(
n
) for both functions.
(c)
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 ttt
 Data Structures

Click to edit the document details