Docsity

Exam 1 for Data Structures and Algorithms - Spring 2002 | CECS 328, Exams of Discrete Structures and Graph Theory

Toggle sidebar
bg1
CECS 328 Exam 1, Spring 2002, Professor Ebert
Name:___________________
Short Problems; Show all work to receive full-credit; 10 points each
1) Suppose an algorithm has exponential running time T(n) = 2n, where nis the problem
size. Assuming that on the average a computer can execute a step of the algorithm in 10−8
seconds, what is the largest problem size that can be solved in 100 seconds? You may leave
your answer unsimplified.
2) Assuming the same computer in problem 1), how long will it take to run an algorithm
with running time T(n) = 10non an input of size 1000?
3) Give as good a big-O estimate as possible for the running time of the following program,
with input n. Hint: integrate to approximate the resulting sum.
sum = 0
for(i= 1; i≤n;i+ +)
for(j=i;j6= 0; j=j/2)
sum + +
return sum
pf3
pf4
pf5
pf8

Partial preview of the text

Download Exam 1 for Data Structures and Algorithms - Spring 2002 | CECS 328 and more Exams Discrete Structures and Graph Theory in PDF only on Docsity!

CECS 328 Exam 1, Spring 2002, Professor Ebert

Name:___________________

Short Problems; Show all work to receive full-credit; 10 points each

  1. Suppose an algorithm has exponential running time T (n) = 2n, where n is the problem size. Assuming that on the average a computer can execute a step of the algorithm in 10−^8 seconds, what is the largest problem size that can be solved in 100 seconds? You may leave your answer unsimplified.

  2. Assuming the same computer in problem 1), how long will it take to run an algorithm with running time T (n) = 10n on an input of size 1000?

  3. Give as good a big-O estimate as possible for the running time of the following program, with input n. Hint: integrate to approximate the resulting sum.

sum = 0 for(i = 1; i ≤ n; i + +) for(j = i; j 6 = 0; j=j/2) sum + + return sum

  1. Show the result of inserting (in the following order) 6,4,7,9,12,6,5,8,10 into an initially empty binary-search tree, and then deleting the root. Carefully show the sequence of steps.
  1. For nodes A, C, J, and H in the tree below, give their parents, children, siblings, depth, and height.

  2. Give a big-O estimate of the function f (x) = x log(x^4 +1) + x(log x)^2. Your answer should be of the form O(g(x)) where g has the smallest order possible. Explain.

Long Problems: Show all work, and explain when necessary; 20 points each

  1. A node of a binary tree is called full if and only if it has two children. Use mathematical induction to prove that the number of full nodes plus one of a binary tree equals the number of leaves of the tree.

  2. The average number of full nodes (see problem 1 for a definition) on a binary search tree is given by the recurrence relation

f (N ) =

N − 2

N

N

N∑ − 1

i=

(f (i) + f (N − i − 1)).

Use mathematical induction to prove that f (N ) = N^ − 3 2 is a solution for this recurrence relation.

  1. Let a and b be positive integers, and n a nonnegative integer. Using pseudocode or C + +, write an efficient nonrecursive algorithm for computing abn. Give a big-O estimate of the running time and briefly explain why the algorithm is correct.
  1. Keys 1, 2 ,... , 2 k^ −1 are inserted into an initially empty AVL tree. Prove that the resulting tree is perfectly balanced.