{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment 10 - NPC (Solution)

# Assignment 10 - NPC (Solution) - The Hong Kong University...

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

COMP 271: Design and Analysis of Algorithms Fall 2007 Assignment 10 Question 1 : Let m and n be two positive integers. Consider the following brute-force algorithm for Fnding the greatest common divider of m and n : GCD( m, n ) let r = 1. for ( k = 1; k < min ( m, n ); k ++ ) if k divides both m and n , r = k . return r . Give a measure for the size of the input to GCD and argue why it is reasonable. And analyze the complexity of GCD in terms of the input size. (You can assume that m n am b for some positive constants a and b .) Solution: A reasonable measure for the size of the input to GCD is I = log 2 m + log 2 n. To present m in terms of I , we have I = log 2 m + log 2 n 2 log 2 m m 2 I 2 The complexity of the brute force GCD algorithm is min( m, n ) × (log 2 n ) 2 m × (log 2 ( am b )) 2 = m × (log 2 a + b log 2 m ) 2 = m (log 2 a ) 2 + 2 b log 2 a × m log 2 m + b 2 m (log 2 m ) 2 2 I 2 (log 2 a ) 2 + 2 b log 2 a · 2 I 2 · log 2 2 I 2 + b 2 2 I 2 (log 2 2 I 2 ) 2 = 2 I 2 (log 2 a ) 2 + b log

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.

{[ snackBarMessage ]}

### Page1 / 3

Assignment 10 - NPC (Solution) - The Hong Kong University...

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

View Full Document
Ask a homework question - tutors are online