CSCE 156
Final
Exam
April 30, 2007
Name:
NUID:
This examination consists of 7 questions and you
have 120 minutes to complete the test. Show
all steps (including any computations/explanations) that lead you to the
answers. Since I will not be able to
meet with you to discuss your exam scores before I turn in your course grades,
it is important to provide your answers to the questions clearly.
Please read every question carefully. If you have questions, please raise your hand
and I will come to you.
Since most of the questions are open-ended, that
means you could spend too much time than necessary for some of the
questions. Please manage your time
well. Answer questions that are more
straightforward first.
Including this page, there are 8 pages.
1. (20 points) Pointers.
(a) (10 points) Given the following code, what are the output
statements? Explain.
1. int *p;
2. p = new int;
3. *p = 28;
4. int *q;
5. q =
p;
6. cout
<< q; //??
7. cout
<< *q; //??
8. int x;
9. x = 10;
10. p =
&x;
11. cout << p; //??
12. cout << *p; //??
13. cout << *q; //??
(b) (10 points) For classes with data members, we normally
implement three methods to deal with
potential problems of shallow copy. Identify
these three methods. Describe the
underlying strategies for the implementation of these methods.
2. (20 points) Abstract
Data Type – Linked Lists, Stacks, Queues.
(a) (10 points) Describe how (i) access, (ii) removal, and (iii)
insertion are done in each of the above abstract data types.
(b) (10 points) Breadth-first traversal of a graph can
be implemented using a queue. Describe
how this can be done clearly.
3. (20
points) Search.
(a) (15 points) Find a hash function that will be able to hash UNL students into a hash table of about N buckets, where N is the number of students at UNL. You may use their names, NUID, or other attributes as the key, X, or a combination of those attributes as the key, X. Describe your hash function clearly. (Hint: Keep in mind of the two main objectives of choosing a good hash function.)
(b) (5 points) Since collisions are unavoidable, how do you resolve collisions for your hash function above?
4. (20 points) Sorting
(a) (10 points) Describe the algorithm of
quicksort clearly.
(b) (10 points) Describe the algorithm of
mergesort clearly.
5. (20
points) Binary Trees.
(a) (10 points) What is the definition of a binary search tree?
(b) (10 points) Describe clearly the
algorithm that deletes a node that has nonempty left and right subtrees such
that the binary search tree after deletion is still a binary search tree.
6. (20
points) Graphs.
(a) (15 points) Describe clearly the Prim’s algorithm that finds a minimal spanning tree of a graph.
(b) (5 points) Describe an application or a problem that a minimal spanning tree can be used to solve.
7. (20 points) General. Short answer questions.
(a) (5 points) Explain why AVL (height-balanced) trees are useful.
(b) (5 points) What is the performance lowerbound on comparison-based search algorithms? What is the performance lowerbound on comparison-based sorting algorithms?
(c) (5 points) Draw the directed graph G of the following adjacency matrix.

(d) (5 points) Identify a minimal spanning tree of the following graph and compute the total weights of the edges in the minimal spanning tree.
