[O5] Characterizing asymptotic behavior (4 pts) [00L6]
Characterize the asymptotic behavior of each of the following in terms of n, using \Theta . Give a brief justification for each answer. For items asking for the time needed to perform some operation or solve some problem, you should describe the worst case running time of the best possible algorithm.
- 1 + 2 + 3 + 4 + \dots + n
- Average number of array lookups needed to find a given element in a sorted array of length n.
- Number of two-element subsets of a set of size n.
- 1 + 2 + 4 + 8 + \dots + 2^n
Total number of nodes in a complete binary tree with n leaves. A complete binary tree is one where every node has two children except for the leaves on the last level. For example, the complete binary tree shown below has 8 leaves.
Number of edges in a graph with n nodes, where every node is connected to every other node.
- Number of different ways to arrange n people in a line.
- Average number of steps needed to find a given element in a sorted linked list of length n.
- Biggest integer that can be represented with n bits.
- Worst-case number of swaps needed to sort an array of length n if you are only allowed to swap adjacent elements.
- Worst-case number of steps needed to check whether two lists, each containing n integers (not necessarily sorted), have any element in common.
- Number of array lookups performed by this Python code:
for i in range(0,n): for j in range (0,i): sum += array[i][j] - Number of addition operations performed by this Java code:
for (int i = 0; i < n; i += 3) { sum = sum + i; } - Total number of calls to
printlnperformed by this Java code:for (int i = 1; i < n; i *= 2) { for (j = 0; j < 20; j++) { System.out.println(i + j); } } - Total number of calls to
printperformed by this Python code:def foo(n): print(n) if n > 0: foo(n-1) foo(n-1)