The document provides a series of questions about big O notation and the growth rates of different functions. It asks the reader to determine whether certain equations involving functions like n, log n, n^2, etc. are true or false based on their asymptotic growth rates. The questions cover topics like determining the best and worst case time complexity of a simple program, and comparing the growth rates of functions like log n vs. n^2, n vs. sqrt(n), and exponential functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
58 views10 pages
Exercises: Part I: Author: Mala Mitra
The document provides a series of questions about big O notation and the growth rates of different functions. It asks the reader to determine whether certain equations involving functions like n, log n, n^2, etc. are true or false based on their asymptotic growth rates. The questions cover topics like determining the best and worst case time complexity of a simple program, and comparing the growth rates of functions like log n vs. n^2, n vs. sqrt(n), and exponential functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10
Exercises: Part I
Author: Mala Mitra
Question 0 • (A) What is the number of steps it will take to run Program 1 in the best case and worst case? Express your answer in terms of n, the size of the input x. Consider only variable assignments.
• Best case x=0, the second loop will not work
• Worst case when x is very large (inf) Question 0 contd. • def program1(x): – total = 0 – for i in range(1000): • total += i – while x > 0: • x -= 1 • total += x – return total Question 1 • Recall that we write f(n)=O(g(n)) to express the fact that f(n) grows no faster than g(n): there exist constants N and c>0 so that for all n≥N, f(n)≤c⋅g(n). • Is it true that log2n=O(n2)? • No, log2n<O(n2)? Question 2 • True / False? • nlog2n=O(n)
• False (nlogn > n)
Question 3 • n2 = O(n3) • True / False?
• False (n3 > n2)
Question 4 • n=O(√n) • True / False?
• False (n > √n)
Question 5 • 5log2n = O(n2) • True / False?
• False (n2 > 5log2n )
Question 6 • n5 = O(23log2n) • True / False?
• False (23log2n > n5 )
Question 7 • 2n = O(2n+1) • True / False? • I am not sure • False (2n+1> 2n )