hw0_sol - CS 473 Algorithms Spring 2011 HW 0(due Monday...

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

View Full Document Right Arrow Icon
CS 473: Algorithms, Spring 2011 HW 0 (due Monday, 23:59:59, January 24) This homework contains two problems; problem 0 is composed of a number of small problems on campus. Read the instructions for submitting homework on the course webpage . Note, that you have to submit your solution online (no paper submission). Collaboration Policy: For this homework, each student should work independently and write up their own solutions and submit them. Read the course policies before starting the homework. 0. (60pts) HW0 online on compass. 1. (40pts) A somewhat non-standard version of Euclid’s algorithm for finding the greatest com- mon divisor (gcd) of two non-negative integer numbers x and y is the following. WeirdEuclid ( x,y ): if y = 0 then return x if x = 0 then return y if x is even and y is even then return 2 * WeirdEuclid ( x/ 2 ,y/ 2) if x is even and y is odd then return WeirdEuclid ( x/ 2 ,y ) if x is odd and y is even then return WeirdEuclid ( x,y/ 2) if y > x then return WeirdEuclid ( y - x,x ) else return WeirdEuclid ( x - y,y ) Prove via induction that the algorithm correctly computes the gcd of x and y . Also prove that the running time of the algorithm is polynomial in the input size. Note that the input size is Θ(log x + log y ). Assume that basic arithmetic operations take constant time. Hint : Think about the binary representation of x and y . Solution : Recall the following easy properties of the gcd of two non-negative integers x and y . You do not have to prove these basic properties.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 3

hw0_sol - CS 473 Algorithms Spring 2011 HW 0(due Monday...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online