
Big O homework
Big O homework
1. Choose the Big O for the following definitions
1. Choose the Big O for the following definitions
Constant,
Constant, Logarithmic(lg2 of N): Linear Time( n): Poly-logarithmic (n log n): Polynomial(n
Logarithmic(lg2 of N): Linear Time( n): Poly-logarithmic (n log n): Polynomial(n^2)
^2):
:
________ Very fast. Include no loops
________ Very fast. Include no loops
__________Also very fast. Typical of many algorithms where the size of the input is halved
__________Also very fast. Typical of many algorithms where the size of the input is halved
each iteration of a loop.
each iteration of a loop.
_______Typical of fast algorithms on a single-processor computer, if all the input of size n
_______Typical of fast algorithms on a single-processor computer, if all the input of size n
has to be read.
has to be read.
_________Typical of the best sorting algorithms. The outer loop processes all N, the inner
_________Typical of the best sorting algorithms. The outer loop processes all N, the inner
loop halves the size of items to be processed each iteration
loop halves the size of items to be processed each iteration
____When a problem of size n can be solved in time n^k where k is a constant. Small n's (n
____When a problem of size n can be solved in time n^k where k is a constant. Small n's (n
<= 3) is OK.
<= 3) is OK.
2. What is the Big of the following function
2. What is the Big of the following function
f(N) = N4 +
f(N) = N4 + 100
100N2 +
N2 + 10
10N +
N + 50
50
3. Characterize, using big-Oh notation, the worst-case running time of the following algorithms:
a) A loop that searches a sorted list of numbers using the most efficient algorithm for such an
operation __________________________
b) Creating a spreadsheet ____________
c) Loops like the following:
for(int i = 0; i < N; i = i + 2){} ________
for (int x = N; x > 0; x = x/2)
for(int i = 1; i < N i = i * 2){} __________
d) The add method for the ArrayList(unsorted) ___________________