### Test on time complexity

Description: Time complexity is used for analyzing sorting functions, recursive calculations and things which generally take more computing time. This quiz will test you on this knowledge of calculating time complexity of algorithms. | |

Number of Questions: 10 | |

Created by: Swati Sharma | |

Tags: analysis of algorithms aoa time complexity of algorithms |

Attempted
0/10
Correct 0
Score 0

‹
›

What is time complexity of fun()?

```
int fun(int n)
{
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
```

What is time complexity for the following function?

```
public void printAllPossibleOrderedPairs ( int[] arrayOfItems)
{
for (int firstItem : arrayOfItems)
{
for (int secondItem : arrayOfItems)
{
int[] orderedPair = new int[] { firstItem, secondItem};
system.out.print( Arrays.toString(orderedPair));
}
}
}
```

Consider the following two functions. What are time complexities of the functions?

```
int fun1(int n)
{
if (n <= 1) return n;
return 2*fun1(n-1);
}
int fun2(int n)
{
if (n <= 1) return n;
return fun2(n-1) + fun2(n-1);
}
```

What is not true about insertion sort?

For a binary search algorithm to work, it is necessary that the array (list) must be

What is the worst case run-time complexity of binary search algorithm?

Recursion uses more memory space than iteration because