Docsity

Homework 1 for Algorithm Design and Analysis | CSE 202, Assignments of Computer Science

Toggle sidebar
bg1
ALG OR IT HM S - CS E 202 - MATH EM ATI CA L PRE LI MI NAR IE S
AND INT RO DU CTO RY PROB LE MS
Homework 1
Writing Style: We suggest the following steps in writing up your solutions, when they are applicable. For a detailed
writing style guidelines, please consult http://cseweb.ucsd.edu/˜paturi/cse202/guide.html.
1. Understand the problem. Take a small concrete example and work it out manually to get a clear idea about the
problem. Do not hesitate to contact us if you do not understand what you are supposed to do.
2. Be prepared to reformulate the problem.
3. Give an informal description (at most 10 lines of english text) of your solution. The informal description should
highlight the key ideas of your solution. Your solution may just be graded by the quality of this informal
description.
4. Write up your design; Use the pseudo programming languge from the book to write your algorithms. Write your
algorithms modularly. Provide sufficient detail as warranted by the problem.
5. Analyze the time complexity.
6. Argue that your algorithm is correct.
7. Think about the structural properties that led to an efficient algorithm and articulate them.
Problem 1: Function order
Rank the following functions by order of growth; that is, find an enumeration f1, f2, . . . of the functions so that
f1= Ω(f2), f2= Ω(f3),.... Also partition your list into equivalence classes such that fand gare in the same class
if and only if f= Θ(g).
(√2)lg n, n0.99, n/ lg n, n3, n!,22n,(3/2)n,1,2n,4lg n, nlg n,lg lg n3n, n2/3,1/√n, 2√lg n
1/n, n1.01, n lg n, 4n/2, n2/log n, n1.99, n2n
Problem 2: Function Order
Is the function 2lg2npolynomially bounded?
Is the function dlog log ne!polynomially bounded?
Is the function dlog ne!polynomially bounded?
Which is asymptotically larger, lg(lg∗n)or lg∗(lg n)?
Justify your answers
1
pf3

Partial preview of the text

Download Homework 1 for Algorithm Design and Analysis | CSE 202 and more Assignments Computer Science in PDF only on Docsity!

ALGORITHMS - CSE 202 - MATHEMATICAL PRELIMINARIES

AND INTRODUCTORY PROBLEMS

Homework 1

Writing Style: We suggest the following steps in writing up your solutions, when they are applicable. For a detailed writing style guidelines, please consult http://cseweb.ucsd.edu/˜ paturi/cse202/guide.html.

  1. Understand the problem. Take a small concrete example and work it out manually to get a clear idea about the problem. Do not hesitate to contact us if you do not understand what you are supposed to do.
  2. Be prepared to reformulate the problem.
  3. Give an informal description (at most 10 lines of english text) of your solution. The informal description should highlight the key ideas of your solution. Your solution may just be graded by the quality of this informal description.
  4. Write up your design; Use the pseudo programming languge from the book to write your algorithms. Write your algorithms modularly. Provide sufficient detail as warranted by the problem.
  5. Analyze the time complexity.
  6. Argue that your algorithm is correct.
  7. Think about the structural properties that led to an efficient algorithm and articulate them.

Problem 1: Function order Rank the following functions by order of growth; that is, find an enumeration f 1 , f 2 ,... of the functions so that f 1 = Ω(f 2 ), f 2 = Ω(f 3 ),.. .. Also partition your list into equivalence classes such that f and g are in the same class if and only if f = Θ(g).

2)lg^ n, n^0.^99 , n/ lg n, n^3 , n!, 22

n , (3/2)n, 1 , 2 n, 4 lg^ n, nlg^ n, lg lg n 3 n, n^2 /^3 , 1 /

n, 2

√ lg n

1 /n, n^1.^01 , n lg n, 4 n/^2 , n^2 / log n, n^1.^99 , n 2 n

Problem 2: Function Order Is the function 2 lg (^2) n polynomially bounded? Is the function dlog log ne! polynomially bounded? Is the function dlog ne! polynomially bounded? Which is asymptotically larger, lg(lg∗^ n) or lg∗(lg n)? Justify your answers

Problem 3: Recurrence relation The running time of an algorithm A is described by the recurrence T (n) = 2T (n/2) + n^2. A competing algorithm has a running time of T ′(n) = aT ′(n/4) + n^2. What is the largest integer value for a such that A′^ is asymptotically faster than A? Justify your answer.

Problem 4: Recurrence relation Find the solution of the following recurrence relation. It is sufficient to find the asymptotic behavior of T (n). You should give convincing evidence that the function f (n) you find satisfies f (n) = Θ(T (n)).

T (n) = 2T (bn/ lg nc) + 3n for n ≥ 3

T (1) = 1, T (2) = 2

Problem 5: Recurrence relations Solve the following recurrence relations and provide a Θ bound for each of them. Assume the initial condition T (1) + 1 in each case. For each case, find an algorithm whose run time behavior can be captured by the recurrence relation.

  1. T (n) = 2T (n/3) + 1
  2. T (n) = 5T (n/4) + n
  3. T (n) = 7T (n/7) + n
  4. T (n) = 9T (n/3) + n^2
  5. T (n) = 8T (n/2) + n^3
  6. T (n) = 49T (n/25) + n^3 /^2 lg n
  7. T (n) = T (n − 1) + 2
  8. T (n) = T (n − 1) + nc^ where c ≥ 1 is a constant
  9. T (n) = T (n − 1) + cn^ where c > 1 is a constant
  10. T (n) = 2T (n − 1) + 1
  11. T (n) = T (

n) + 1

Problem 6: Computing Mode The mode of a set of numbers is the number that occurs most frequently in the set. The set (4,6,2,4,3,1) has a mode of 4.

  1. Give an efficient and correct algorithm to compute the mode of a set of n numbers;
  2. Suppose we know that there is an (unknown) element that occurs n/2 + 1 times in the set. Give a worst-case linear-time algorithm to find the mode. For partial credit, your algorithm may run in expected linear time.