(b)
Without solving the recurrence relation
, prove that the algorithm runs in
O
(
n
2
) time. Hint: use
strong induction.
19. For each statement below, decide whether it is true or false. In each case attach a
very brief
expla
nation of your answer.
(a) In any tree, for any node
x
, the sum between the depth of
x
and the height of
x
equals the
height of the entire tree, true or false?
(b) By implementing lists with doubly linked nodes instead of singly linked nodes we can find the
element at any given index in constant time, true or false?
20. Show the result of inserting 10,12,1,14,6,5,8,15,3,9,7 in this order in an empty binary minheap.
Circle
the final result!
21. Order the following functions by asymptotic growth rate indicating when two or more are bigTheta
of each other:
n
2
√
n,
2
2
n

3
,
√
n
3
,
4
n
log
n
+ 2
n,
3
n
+3
,
1 + 2
2
+
· · ·
+
n
2
,
log
n
n
,
log
n
2
log
n
22. Give a bigOh characterization for the running time of the code fragments belwo, with a short
explanation:
(a)
for( int i = 0; i < n; i++ )
for( int j = i; j <= n; j++ )
for( int k = i; k <= j; k++ )
sum++;
(b)
static int foo(int[] a) {
int s=a[0];
for(int i=2;i<=n;i=i+2)
s=s+a[i];
return s;
}
(c)
for( int p = 0; p < n*n; p++ )
for( int q = 0; q < p; q++ )
sum++;
8