0% found this document useful (0 votes)
3 views

Assignment 1

The document discusses various functions and their classifications in algorithm analysis, particularly focusing on Big O, Theta, and Omega notations. It includes problems related to proving assertions about the growth rates of functions, listing functions by their order of growth, and analyzing the efficiency of algorithms. Additionally, it touches on algorithm design and empirical observations regarding algorithm performance.

Uploaded by

ralariy472
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 1

The document discusses various functions and their classifications in algorithm analysis, particularly focusing on Big O, Theta, and Omega notations. It includes problems related to proving assertions about the growth rates of functions, listing functions by their order of growth, and analyzing the efficiency of algorithms. Additionally, it touches on algorithm design and empirical observations regarding algorithm performance.

Uploaded by

ralariy472
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

a. n(n + 1)/2 ∈ O(n3) b.

n(n + 1)/2 ∈ O(n2 )


c. n(n + 1)/2 ∈ !(n3)
COMP157-Fall2020 d.Assignment1
n(n + 1)/2 ∈ "(n) Analysis of Algorithms

3. For each of the following functions, indicate the class !(g(n)) the function
1)belongs
Consider
to.the following
(Use functions
the simplest g(n) possible in your answers.) Prove your
assertions. !
a. (n2 + 1)10 b. 10n2 + 7n + 3
c. 2n lg(n + 2)2 + (n + 2)2 lg n2 d. 2n+1 + 3n−1
e. $log
Fundamentals n%Analysis of Algorithm Efficiency
of 2the

4. a. Table 2.1 contains values of several functions that often arise in the analysis
a.of Indicate
algorithms. class Θ(n)
theThese valueseach
certainly suggest
function thatto.
belongs the functions

log n, n,
b. Prove your answers in a using n, n2 ,
n log2limits n3 , 2n , n!
are listed in increasing order of their order of growth. Do these values
prove this fact with mathematical certainty?
b. Prove that the functions are indeed listed in increasing order of their order
of growth.
2) List the following functions according to their order of growth from the lowest
to the highest
5. List the following (justaccording
functions the list, no
to proofs needed)
their order of growth from the lowest
to the highest:

(n − 2)!, 5 lg(n + 100)10, 22n, 0.001n4 + 3n3 + 1, ln2 n, 3 n, 3n.
6. a. Prove that every polynomial of degree k, p(n) = ak nk + ak−1nk−1 + . . . + a0
with ak > 0, belongs to !(nk ).
3)b. AProve
cow is facing
that a fence that
exponential stretches
functions infinitely
a n have in both
different directions.
orders There
of growth foris a
different
holevalues
in theoffence
basethat 0. cow can use to cross to the other side but the
a > the
7. Prove thecow does notassertions
following know how byfar away
using theis definitions
the hole norofinthe
which direction.
notations in-
volved, or We disprove themtoby
would like givingana algorithm
design specific counterexample.
that enables the cow find the hole
a. If t (n)in∈ the fence then
O(g(n)), most∈O(n)
in at g(n) where n is the number of steps between the
"(t (n)).
b. !(αg(n))cow’s initial position
= !(g(n)), whereand
α >the
0. fence hole.
c. !(g(n)) = O(g(n)) ∩ "(g(n)).
a. Any algorithm cannot have the cow walk in one direction because if it is the
d. For any two nonnegative functions t (n) and g(n) defined on the set of
wrong direction it will be infinite steps.The key idea here is to walk
nonnegative integers, either t (n) ∈ O(g(n)), or t (n) ∈ "(g(n)), or both.
intermittently right and left going each time. Let’s stay the cow takes
8. Prove the section’s theorem for
a step left, go back and take a step right, go back and take 2 steps left
a. " notation. b. ! notation.
then back and 2 steps right etc….. Is that algorithm O(n) if not what
9. We mentioned in this
is the classsection
of thisthat one can check whether all elements of an
algorithm?
array are distinct by a two-part algorithm based on the array’s presorting.
a.b.If the
Canpresorting is done
you improve on by
theanalgorithm
algorithminwith
a? a time efficiency in !(n log n),
what will be a time-efficiency class of the entire algorithm?
b. If the sorting algorithm used for presorting needs an extra array of size n,
what will be the space-efficiency class of the entire algorithm?
10. The range of a finite nonempty set of n real numbers S is defined as the differ-
ence between the largest and smallest elements of S. For each representation
of S given below, describe in English an algorithm to compute the range. Indi-
for 1 to 1 do
algorithm’s basic operation is executed.
[]
1
0 andb. [How
COMP157-Fall2020
while ] does
do this Assignment1
algorithm compare withAnalysis
the straightforward
of Algorithms nonrecurs
algorithm
+1 for computing this function?
[ + 1] [ ]
4) Consider4. theConsider
following the
recursive algorithm
following recursive algorithm.
1
[ + 1]
Algorithm ( )
Is the comparison counter
//Input:inserted in the right
A positive place? If you believe it is,
integer
prove it; if you believe it is not, make
if = 1 return 1 an appropriate correction.
2. a. Run the programelse return1, with
of Problem ( a 1) + 2 inserted
properly 1 counter (or
counters) for the number of key comparisons, on 20 random arrays of sizes
1000, 1500, 2000, 2500,...,9000,
a. Set up9500.a recurrence relation for this function’s values and solve
a. Determine
towhat this algorithm
determine computes.
what this algorithm computes.
b. Analyze the data obtained to form a hypothesis about the algorithm’s
b. Set
average-case e up a recurrence relation for the number of multiplications made by this
ciency.
b. Set up
algorithm andasolve
recurrence
it. relation for the number of multiplications made
this ofalgorithm
c. Estimate the number and solve
key comparisons it.
one should expect for a ran-
c. Set uparray
domly generated a recurrence relation
of size 10,000 for the
sorted by number
the sameofalgorithm.
additions/subtractions made
by c.
thisSet up a recurrence
algorithm and solve it.relation for the number of additions/subtractio
3. Repeat Problem 2 by measuring the program’s running time in millisec-
onds.
made by this algorithm and solve it.
5) Hypothesize a likely efficiency class of an algorithm based on the following
empirical
4. Hypothesize a likely observations
e ciency of its
class of an basic operation’s
algorithm count:
based on the following
empirical observations of its basic operation’s count: 32
size 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
count 11,966 24,303 39,992 53,010 67,272 78,692 91,274 113,063 129,799 140,538

5. What scale transformation will make a logarithmic scatterplot look like a


linear one?
6. How can we distinguish a scatterplot for an algorithm in (lg lg ) from
a scatterplot for an algorithm in (lg )?

55

You might also like