This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COT5405 Analysis of Algorithms Homework 5 Solutions 1. Since the rate of decrease at each site is different, we need to check all possibilities of spending available battery time. At each site, we calculate the number of pearls collect after each time unit. P [ i,j ] , 1 i n, 1 j m represents the total pearls collected when the robot is at site i and the battery time used is j ( n is number of sites and m is number of hours available). The base values, P [1 ,j ] can be calculated in O ( m ) time. p [ i,j ] represents the number of pearls collected if robot spends j units of time at site i . All p [ i,j ] values can be calculated in O ( nm ) time. The recursive equation is as follows: T [ i,j ] = max t i 1 ,i k j { T [ i 1 ,j k ] + p [ i,k t i 1 ,i ] } i varies from 1 to n , j varies from 1 to m and k also varies from 1 to m (since it depends on j ). So the runtime complexity for this algorithm is O ( nm 2 ). 2. We maintain two arrays to solve this problem. First array P [ i ][ j ] is a boolean array which tells whether the substring a i ......a j is a palindrome or not. If P [ i ][ j ] is true then the substring a i ...a j is a palindrome. Second array Cut [ j ] stores minimum number of cuts in best partition for the substring a 1 ...a j . We can construct the array P [ i ][ j ] using following recurrence P [ i ][ j ] = true , if i == j or P [ i ][ j ] = true , if i == j 1 and a i == a j or P [ i ][ j ] = ( a i == a j ) and P [ i + 1][ j 1]. And, Cut[j] can be constructed as, Cut [ j ] = 0 if P [1][ j ] = true or Cut [ j ] = min j 1 k =0 { Cut [ k ] + 1 if P [ k + 1][ j ] == true } Both the tables can be constructed in O ( n 2 ) time. 1 3. You start with leaf nodes, to root. Take a subtree S, with root node r s . N s be total nodes in S. construct an array conv S [1 ..N s 1] conv S [ i ] stores the maximum conviviality value when i nodes from S are in different lists (invited and uninvited) than r s , the root. If S is leaf, conv S [0] = 0....
View
Full
Document
 Fall '08
 UNGOR
 Algorithms

Click to edit the document details