CPSC 212 Final Exam Part 1 and 2, Exams of Algorithms and Programming

The final exam questions for a computer science course, cpsc 212. The exam covers various topics including algorithms, graphs, trees, hash tables, and sorting. Students are required to evaluate series, apply dijkstra's algorithm, convert infix to postfix, and implement a remove method for a doubly-linked list. The exam also includes questions related to binary trees, avl trees, and splay trees.

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-j3d
koofers-user-j3d 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 2121 Name: _____________________________
Final Exam, Part 1 August 4, 2003
Closed books. Closed Notes. Calculators OK. 105 points. 90 minutes. Weight of each question in
parentheses. Please use a pencil. If you need more space, use the back of the sheet.
1. (5) Evaluate the following series:
(a) 56 + 63 + 70 + ... + 7*(N+2) =
(b) 16 + 25 + 36 + ... + (N+3)2 =
2. Your friend has analyzed Algorithms A and B, two algorithms which solve the same problem. Her analysis,
which you have checked and verified, shows that the complexity equations are as follows:
Algorithm A: f(n) = n log n Algorithm B: g(n) = 256 log n
Now answer the following questions:
_____ (a) (2) Which algorithm (A or B) would you use if the problem size is n=32?
_____ (b) (2) Which algorithm (A or B) would you use if the problem size is n=128?
(c) (6) Your friend claims that she would use Algorithm A if the problem size is less than or equal to a given value
X, and algorithm B if the problem size is greater than the same value X. Do you agree with her? If so, determine
X. Show how you arrived at your answer. If not, explain why you disagree with her.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CPSC 212 Final Exam Part 1 and 2 and more Exams Algorithms and Programming in PDF only on Docsity!

CPSC 212  1 Name: _____________________________

Final Exam, Part 1 August 4, 2003

Closed books. Closed Notes. Calculators OK. 105 points. 90 minutes. Weight of each question in parentheses. Please use a pencil. If you need more space, use the back of the sheet.

  1. (5) Evaluate the following series: (a) 56 + 63 + 70 + ... + 7*(N+2) = (b) 16 + 25 + 36 + ... + (N+3)^2 =
  2. Your friend has analyzed Algorithms A and B, two algorithms which solve the same problem. Her analysis, which you have checked and verified, shows that the complexity equations are as follows: Algorithm A: f(n) = n log n Algorithm B: g(n) = 256 log n Now answer the following questions: _____ (a) (2) Which algorithm (A or B) would you use if the problem size is n=32? _____ (b) (2) Which algorithm (A or B) would you use if the problem size is n=128? (c) (6) Your friend claims that she would use Algorithm A if the problem size is less than or equal to a given value X, and algorithm B if the problem size is greater than the same value X. Do you agree with her? If so, determine X. Show how you arrived at your answer. If not, explain why you disagree with her.
  1. (10) Consider the graph shown below. Apply Dijkstra’s algorithm starting with node 5. Put your final answer in the table on the right. Node Known dk pk 0 ____ ____ ____ 1 ____ ____ ____ 2 ____ ____ ____ 3 ____ ____ ____ 4 ____ ____ ____ 5 ____ ____ ____ 6 ____ ____ ____
  2. (6) Evaluate the following. Use the letters G, M, K, P, T, E as appropriate. _____ 2^36 _____2^43 _____2^57 _____2^25 _____2^62 _____2^14 (4) Evaluate the following. Assume that all logarithms are base 2. _______ log (2048 / 128) _______ log (32M * 64T / 256P * 16E)
  1. Consider the Splay tree shown on the left. (a) (5) Show how the tree is changed after node 6 is accessed. (b) (5) Show how the original tree changes after node 10 is accessed. splay tree: root: 14 children of 14: 9 18 children of 9: 5 10 children of 5: 3 6 children of 18: 15 __
  2. (10) Insert the following values into an initially empty AVL tree. Ignore duplicates. Show the rotations you perform and indicate the type (S for Single, D for Double). 15 0 1 12 10 25 22 7 16 3 4 9
  3. (10) Apply Kruskal’s algorithm to the graph on the right. Then answer the questions below. a) _____ Which edge is the first edge rejected? b) _____ How many edges are considered and rejected? c) _____ How many edges are not considered? d) _____ What is the total cost of the resulting minimum spanning tree? e) _____ Which edge was the last edge accepted?
  1. (10) Assume (a) that L is a doubly-linked linear list with no dummy head node, (b) that each ListNode holds an int field called value, (c) that fields called prev and next in a ListNode refer to the previous and next nodes in the list, and (d) that L.head and L.tail refer to the first and last nodes in a non-empty list, and are null if the list is empty. Write a Java method public void remove() which removes the ListNode that contains the largest value in the list. Assume that the values in the list are unique (i.e., no duplicates). I will be looking for syntactic , as well as algorithmic, accuracy. If you need more space, use the back of this sheet. Please print clearly. public void remove () { } // remove
  2. (10) Consider the trees below. Then answer the following questions. For each question, there may be more than one answer. __________ (a) Which of the trees are full trees. __________ (b) Which of the trees are complete trees. __________ (c) Which of the trees are AVL trees. __________ (d) Which of the trees are binary search trees. __________ (e) Which of the trees are are k-ary trees.
  1. (10) Insert the following values into a binary maxheap. Use the back of this sheet if you need more space. 24 36 45 12 9 16 47 21 16 15 23 46 39
  2. (10) Given input {371, 323, 173, 195, 344, 679, 989} and a hash function h(x)=x%11, show the final contents of the hash table for each of the following: (a) Open addressing hash table using separate chaining. (b) Open addressing hash table with second hash function h2(x) = 9 – (x % 9).
  1. (10) Consider array C below. Note that only a portion of array C is shown. Also consider the Quicksort algorithm on a separate sheet. How are the values rearranged after the following call: quicksort(C,13,29); Execute statements 1 through 10 only once. i: ... 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ... C: ... 35 23 8 10 35 63 16 14 13 79 32 47 59 16 11 19 75 ... C: ... __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ...
  2. (10) Insert the following into an initially empty Skew maxheap : 2 1 9 7 3 0 12. Show the final tree.
  3. (10) Consider the following Leftist minheap. Remove four values. Show the final tree. leftist minheap root: 4 children of 4: 6 8 children of 6: 7 __ children of 8: 9 __ children of 7: 12 __ children of 9: 10 __ children of 10: 11 __
  1. (10) Consider the following binary minheap. Remove three values. Show the final tree. binary minheap root: 4 children of 4: 9 5 children of 9: 11 10 children of 5: 6 7 children of 11: 15 __
  2. (5) Draw a picture of the graph represented by the following adjacency matrix. The nodes of the graph are provided for you. 5 0 0 1 0 2 0 1 0 7 0 0 1 6 0 2 0 3 0 4 1 0 0 0 0 3 7 0 4 3 0 2 0 0 0 9 6 0 2 3 4 5