0% 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.

Uploaded by

ayman
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

ayman
Copyright
© © All Rights Reserved
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 )

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy