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 |
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;
}
Let w(n) and A(n) denote respectively, the worst case and average case running time of an algorithm executed on an input of size n. which of the following is ALWAYS TRUE?
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?
If queue is implemented using arrays, what would be the worst run time complexity of queue and dequeue operations?
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
The number of passes needed to sort the numbers 8, 22, 7, 9, 31 in ascending order, using insertion sort is