# mar31 - Illinois Institute of Technology Department of...

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

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: Illinois Institute of Technology Department of Computer Science Lecture 17: March 31 CS 330 Discrete Mathematics Spring Semester, 2008 1 Divide-and-conquer algorithms 1.1 Multiplying numbers How do we multiply two n-digit numbers? First we multiply the first number by the rightmost digit of the second number. Then we multiply the first number by the second digit of the second number, and so on. Finally, we add the first result to the second result shifted left one digit, add that to the third result shifted left two digits, and so on. ( ) ( ) ( ) ( ) ( ) . . . ( ) ( ) n numbers n digits Treating additions and multiplications of digits as our atomic operations, we can accomplish this in ( n 2 ) operations. Let us consider a divide-and-conquer algorithm. 1 We divide each n-digit number into two n 2-digit numbers: ( ) ( ) A B ( ) ( ) ( ) ( ) A 1 A B 1 B Since we are dividing A and B in half, we know that A = 10 n 2 A 1 + A and B = 10 n 2 B 1 + B . So: AB = (10 n 2 A 1 + A )(10 n 2 B 1 + B ) = 10 n A 1 B 1 + 10 n 2 ( A 1 B + A B 1 ) + A B This yields four multiplications of n 2-digit numbers, as well as ( n ) additions and shifts. This leads us to the recurrence: T (1) = 1 T ( n ) = 4 T n 2 + kn 1 This is discussed in Rosen, page 475, example 4. CS 330Spring, 2008...
View Full Document

## mar31 - Illinois Institute of Technology Department of...

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

View Full Document
Ask a homework question - tutors are online