Exam on Asymptotic Notation, Recurrence, Lists, Sorting, Hashing, BST, Exams of Computer Science

A university exam about various computer science topics such as asymptotic notation, recurrence relations, lists, sorting, hashing, and binary search trees. It includes true or false questions, recurrence relation problems, running time analysis of list operations, sorting algorithms comparison, hashing algorithms with different conflict resolution methods, and binary search tree problems.

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-48g
koofers-user-48g 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 331 Summer 2002 Exam #1 (6/3/02)
Name:
Asymptotic Notation
1. Mark each of the following as True or False.
(a) 8 log n= Ω(n)
(b) 8f(n)·2g(n) = O(f(n)·g(n))
(c) f(n)·g(n) = O(max(f(n), g(n)))
(d) 2nlog n2= Θ(nlog n)
(e) f(n)
g(n)=O(1) if f(n) = Θ(g(n))
Recurrence Relations
2. The following code is used to generate a specific series of numbers:
int F( int N )
{
if ( N == 0 || N == 1 ) return 1;
else return F( N-1 ) * F( N-2 );
}
(a) Write a recurrence relation which represents its running time.
(b) Use a recursion tree to argue a bound for this relation.
1
pf3
pf4
pf5

Partial preview of the text

Download Exam on Asymptotic Notation, Recurrence, Lists, Sorting, Hashing, BST and more Exams Computer Science in PDF only on Docsity!

CSE 331 Summer 2002 Exam #1 (6/3/02)

Name:

Asymptotic Notation

  1. Mark each of the following as True or False.

(a) 8 log n = Ω(

n) (b) 8f (n) · 2 g(n) = O(f (n) · g(n)) (c) f (n) · g(n) = O(max(f (n), g(n))) (d) 2n log n^2 = Θ(n log n) (e) f g^ ((nn)) = O(1) if f (n) = Θ(g(n))

Recurrence Relations

  1. The following code is used to generate a specific series of numbers:

int F( int N ) { if ( N == 0 || N == 1 ) return 1; else return F( N-1 ) * F( N-2 ); }

(a) Write a recurrence relation which represents its running time.

(b) Use a recursion tree to argue a bound for this relation.

  1. Prove an O(log N) bound on the following recurrence relation using the substitution method: T (N) = T (N/2) + 10

Lists

  1. A list can be implemented as an array. Let L be the array. In a list of N items, L[1] always contains the first item in the list, L[N] always contains the last item in the list, and L[k] contains item number k in the list. Use big-Oh notation to describe the running times of the following operations.

(a) Insert at the front of the list.

(b) Insert at the end of the list.

(c) Find the item with value X.

(d) Find item number k in the list.

(e) Delete item number k from the list.

Hashing

  1. A simple algorithm forms an integer from a name by adding the ASCII decimal rep- resentation of every third character in the name (first and last, including any spaces). The following are simple hash functions for use with the above scheme: h 1 (k) = k mod m, and h 2 (k) = 3k mod m. For each of the schemes below assume that the table size, m = 10, draw a hash table (horizontally), label its cells (0-9), and hash each of the following names to the cell appropriate for the scheme. Note that the ASCII values for each character in the name are printed next to the name. The (conflict resolution) schemes are as defined in class.

i. Edgar Kalns (69 100 103 97 114 32 75 97 108 110 115) ii. Frank Northrup (70 114 97 110 107 32 78 111 114 116 104 114 117 112) iii. Honda Shing (72 111 110 100 97 32 83 104 105 110 103) iv. Bill Moore (66 105 108 108 32 77 111 111 114 101) v. Travis Doom (84 114 97 118 105 115 32 68 111 111 109) vi. Jen White (74 101 110 32 87 104 105 116 101)

(a) Open hashing (with a linked list per bin) is used to resolve conflicts. The function h 1 (k), as defined above is used for hashing.

(b) Quadratic probing is used to resolve conflicts. The function h 2 (k), as defined above, is used for hashing.

(c) Double hashing is used to resolve conflicts. Both h 1 (k) and h 2 (k), as defined above, are used.

(d) List one problem with this algorithm and suggest a modification which fixes it.

Binary Search Trees

  1. (a) Insert the values 2, 10, 7, 21, 23, 9, 12 and 16 (in that order) into a simple binary search tree. Draw the resulting tree.

(b) List the preorder traversal of the above tree.