-
Rank the following functions in order of increasing running time (that
is, fastest to slowest.) Indicate which (if any) are identical.
- n2
- n!
- log n
- log log n
- 2 log n
- 5n + 2
- 22n
- nn
- n3/2
- log (n2)
- 2100
- Give the Big-Oh running time for the following function:
void f(unsigned int n)
{
int k = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
k += 1;
}
}
}
- Give the Big-Oh running time for the following function:
void f(unsigned int n)
{
int k = 0;
for (int i = 0; i < n; i++)
{
for (int j = 1; j < n; j *= 2)
{
k += 1;
}
}
}
- Give the Big-Oh running time for the following function:
void f(unsigned int n)
{
int k = 0;
for (int i = 1; i < n; i *= 2)
{
for (int j = 1; j < i; j *= 2 )
{
k += 1;
}
}
}
- Give the Big-Oh running time for the following function:
void f(unsigned int n)
{
if (n == 1) return;
f(n / 2);
f(n / 2);
}