Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let n > 0 ( usually n is the size of the input ) and let f ( n ) and g ( n )
Let n usually n is the size of the input and let f n and gn be two
monotone and nonnegative functions. We say that f n Ogn if there
exists a constant c and a constant n such that: f n cgnn n
The exercise asks you to use the definition to prove the following:
Let f nnn Then f n On
Let f nn n log n Then f n On log n
Let f nn log n n Then f n On
Feel free to use standard properties or inequalities for the logarithm without
proof.
Ex Imagine you had an algorithm with runtime T n satisfying the recursion
T n T nand T You have probably seen the binary search
algorithm that exactly obeys that recursion. Prove that T n Olog n Then,
imagine another algorithm with Qn Qn n and Q Prove that
Qn On
Ex Describe an On log ntime algorithm that, given a set S of n integers
and another integer x determines whether or not there exist two elements in S
whose sum is exactly x
Ex Follow the O definition & prove: Is n On Is n On
Ex Imagine you came up with an algorithm that depends on a parameter
k in n you can control. After calculations, the runtime ends up being
Onk n
k What choice of k would you make for your algorithm?
Ex This is from a common coding interview question: Imagine you are given a
list of n integers. Assume they are distinct if that helps you. Give an algorithm
that finds the smallest and the second smallest element in the list, using at most
n log n comparisons, and explain why your algorithm needs at most n log n
comparisons. Hint: think again of the pairing process we saw in class, when
trying to find the max and the min simultaneously; where is the second smallest
element located? Here, thinking about tennis or chess tournaments may help
you.
For asymptotic notation exercises, if it helps you can think that n is a power of
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started