Docsity

Final Exam Practice Problems - Computer Science II | COP 3503, Exams of Computer Science

Toggle sidebar
bg1
COP 3503 – Final Exam Practice Problems
These problems are similar in nature to those that you will see on the final exam. The final exam
in comprehensive and not every topic that we have covered is represented here so don’t study for
the final based upon this homework only!
1. For the binary tree shown below, show the output of a preorder traversal of the tree. For additional
practice do: inorder, postorder, and level order traversals.
2. Define and explain the following terms:
(1) a greedy algorithm
(2) divide and conquer algorithm
3. Show the contents of a stack after each of the following operations. What is the final value of the
stack?
(1) push (20)
(2) push (15)
(3) push (pop( ) - pop( ))
(4) push (10)
(5) push( pop( ) + pop( ))
(6) top( )
1
A
B E
C F
GD
H I
pf3
pf4
pf5

Partial preview of the text

Download Final Exam Practice Problems - Computer Science II | COP 3503 and more Exams Computer Science in PDF only on Docsity!

COP 3503 – Final Exam Practice Problems

These problems are similar in nature to those that you will see on the final exam. The final exam in comprehensive and not every topic that we have covered is represented here so don’t study for the final based upon this homework only!

  1. For the binary tree shown below, show the output of a preorder traversal of the tree. For additional practice do: inorder, postorder, and level order traversals.
  2. Define and explain the following terms: (1) a greedy algorithm (2) divide and conquer algorithm
  3. Show the contents of a stack after each of the following operations. What is the final value of the stack? (1) push (20) (2) push (15) (3) push (pop( ) - pop( )) (4) push (10) (5) push( pop( ) + pop( )) (6) top( )

A

B E

C F

D G

H I

  1. Shown below is an expression tree that represents a valid infix expression. Convert the expression to a prefix expression. What technique did you use to do this conversion?
  2. Write a pseudocode algorithm that will delete an arbitrary node identified by the pointer del from a doubly linked list.
  3. Shown below is a conjecture. Complete an induction proof that proves the conjecture is true for all integer numbers greater than or equal to 1.

Conjecture: 

n i 1 3

2 i( 2 i 1 )^1 n(n 1 )( 4 n 1 )

  1. Consider the linked lists shown below. Connect the new node into its proper place within the existing list. What are the lists representing? What is the Big-Oh time complexity of this operation? in2 in3 null null in null newnode

c

+ e -

a

f g

b

  1. The product XY can be calculated according to: AC2n^ + [(A – B)(D – C)+ AC + BD]2n/2^ + BD The algorithm to produce this result is: function int multiply (X, Y, n) { //X and Y are positive integers  2 n, n is a power of 2, XY is returned if n == if (X ==1) && (Y ==1) return 1 else return 0 else { //divide X and Y each into two halves of size n/ A = left n/2 digits of X; B = right n/2 digits of X; C = left n/2 digits of Y; D = right n/2 digits of Y; m1 = multiply (A, C, n/2); m2 = multiply (AB, DC, n/2); m3 = multiply (B, D, n/2); return( m1*2n^ + (m1 + m2 + m3) * 2n/2^ + m3)) } } (a) What general problem solving technique has been employed in this algorithm? (b) Assuming that the overhead operations required by this algorithm are linear, what is the Big-Oh running time of this multiplication algorithm? (c) Does this algorithm run faster than the technique you were taught in grade school? If it does, what might be a reason that you weren’t taught this algorithm in grade school?
  2. Produce both a depth-first and a breadth-first traversal of the following tree. Show the contents of the supporting data structures (at each step) as well.

a 5

e

m r s

b

1 3 f 1

n 1

t

x

  1. For the character frequency array shown below, construct the Huffman coding tree. Each internal node stores only an integer and each leaf node stores the letter and its corresponding frequency. Once you have constructed the Huffman coding tree, produce the Huffman code for each character in the frequency array. Notice that since there are six characters which appear in the file to be compressed that the initial uncompressed code would require three bits/character. Once you have determined the Huffman code compute the amount of compression that the code has generated. Letter a b c d e f Frequency 10 15 8 3 7 4 Huffman Code
  2. The linear congruential generator produces random numbers X 1 , X 2 , …Xn , which satisfy the expression: Determine the length of the period of the sequence of random numbers generated by this algorithm assuming the values, A = 5, X 0 = 1, and M = 11. Show your work at each step and show every value in the period of the sequence as well as length of the period. Does this value of A provide a full period?
  3. Given the two functions below, determine which is asymptotically bigger? Show your justification. f(n) = 4n^3 + 3n^2 + 5n + 2 g(n) = 24n^2 + 35n + 10

X i  1 AXi  modM