Midterm2

# Midterm2 - nodes is 2 The example is the tree(1 2(2 3 n-1,n 2(6 points 2.1 Part(a The recurrence relation is T n = T(3 n 4 O n and T n = O n by

This preview shows pages 1–2. Sign up to view the full content.

Solutions to Midterm 2 Peng Du University of California, San Diego 1 (15 points) 1.1 Part (a) Exponential time. Consider a complete graph G with n nodes and an edge of weight one between every pair of nodes. For any permutation σ of 1 , 2 ,...,n , the path ( σ (1) (2)) , ( σ (2) (3)) ,..., ( σ ( n - 1) ( n )) is a minimum spanning tree. Therefore, G has at least n ! / 2 number of minimum spanning trees. 1.2 Part (b) False. Consider a tree with weight one for all its edges. 1.3 Part (c) True. Suppose G has k connected components with n 1 ,n 2 ,...,n k nodes, respec- tively. Since a connected graph with n nodes has at least n - 1 edges, we have | E | ≥ ( n 1 - 1) + ( n 2 - 1) + ··· + ( n k - 1) = ( n 1 + n 2 + ··· + n k ) - k = | V | - k , so k ≥ | V | - | E | . 1.4 Part (d) True. Use the same proof as the cut property. 1.5 Part (e) The largest possible number of leaves for a tree with n nodes is n - 1. The example is the tree (1 , 2) , (1 , 3) ,..., (1 ,n ). The smallest possible number of leaves for a tree with n

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nodes is 2. The example is the tree (1 , 2) , (2 , 3) ,..., ( n-1 ,n ). 2 (6 points) 2.1 Part (a) The recurrence relation is T ( n ) = T (3 n/ 4) + O ( n ) and T ( n ) = O ( n ) by master theorem. 2 2.2 Part (b) The recurrence relation is T ( n ) = 2 T ( n-1)+ O (1) and T ( n ) = 2 n by induction. 2.3 Part (c) The recurrence relation is T ( n ) = 4 T ( n/ 2) + O ( n 2 ) and T ( n ) = n 2 log n by master theorem. 3 (9 points) 3.1 Part (a) S ( n ). 3.2 Part (b) S ( i ) = 10 , 8 , 18 , 33 , 26 , 36 , 56 , 66 , 60 , 70. 3.3 Part (c) S ( i ) = min { S ( j ) + h i : j < i and d i-d j ≤ M } . 3.4 Part (d) S (0) = 0; for i = 1 ...n S ( i ) = ∞ ; for i = 1 ...n for j = 0 ...i-1 if d i-d j ≤ M and S ( j ) + h i < S ( i ) S ( i ) = S ( j ) + h i ; return S ( n ); 3.5 Part (e) O ( n 2 )....
View Full Document

## This note was uploaded on 01/21/2010 for the course CSE 661930 taught by Professor Freund,yoav during the Fall '09 term at UCSD.

### Page1 / 2

Midterm2 - nodes is 2 The example is the tree(1 2(2 3 n-1,n 2(6 points 2.1 Part(a The recurrence relation is T n = T(3 n 4 O n and T n = O n by

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online