Tutorial 1, Design and Analysis of Algorithms, 2024
Tutorial 1, Design and Analysis of Algorithms, 2024
Tutorial 1, Design and Analysis of Algorithms, 2024
1. Using the extended Euclid’s algorithm for GCD, find the gcd (677801, 939871), and also
integers x and y such that (677801, 939871) = 677801x + 939871y, showing all the steps
involved.
2. Lucas numbers are defined as: L1 = 1, L2 = 3, and for n > 2, Ln = Ln−1 + Ln−2 . Prove both
the parts using mathematical induction.
(a) Find the GCD (Ln , Ln−1 ) using Euclid’s GCD algorithm.
(b) Find integers xn and yn so that (Ln , Ln−1 ) = xn Ln + yn Ln−1 using Euclid’s extended GCD
algorithm.
3. Using the extended Euclid’s algorithm for GCD, solve the following congruences, showing
all the steps involved.
4. Show how to compute multiplicative inverses modulo a prime p via a single exponentiation.
Either prove that this also works modulo composite n or give a counterexample.
5. To see if a number, say 562437487, is divisible by 3, you just add up the digits of its decimal
representation, and see if the result is divisible by 3 (5 + 6 + 2 + 4 + 3 + 7 + 4 + 8 + 7 = 46,
so it is not divisible by 3). To see if the same number is divisible by 11, you can do this:
subdivide the number into pairs of digits, from the right hand end (87, 74, 43, 62, 5), add these
numbers, and see if the sum is divisible by 11 (if it is too big, repeat). How about 37? To see
if the number is divisible by 37, subdivide it into triples from the end (487, 437, 562), add
these up, and see if the sum is divisible by 37 . This is true for any prime p other than 2 and
5. That is, for any prime p ̸= 2, 5, there is an integer r such that in order to see if p divides a
decimal number n, we break n into r−tuples of decimal digits (starting from the right-hand
end), add up these r−tuples, and check if the sum is divisible by p.
6. By making use of efficient algorithms, find the last three digits in the decimal expansion of
320232023202320232023 .
7. (a) Find the GCD, (36, 144, 200), and the integers x, y, z such that
1
(b) Prove that there exist integers x1 , . . . , xn such that the GCD of n integers, (a1 , . . . , an ),
can be represented as their linear combination:
n
(a1 , . . . , an ) = ∑ a jx j.
j=1
8. Write an algorithm for computing ab where a and b are positive integers using the repeated
squaring method. Assuming that (1) a = O(n), and b = O(n); (2) you can multiply two m
bit numbers in O(m2 ) time; and (3) you can add two m bit numbers in O(m) time; find the
best possible upper bound on worst case time complexity in O() notation as a function of n.
9. Let IROOT(n, m) be a function that computes the integral part of m’th root of n (m and n are
positive integers):
IROOT(n, m) = ⌊n1/m ⌋
Give a polynomial-time algorithm for IROOT and find its time-complexity in terms of n (you
can assume that m ≤ n).