Tutorial 1, Design and Analysis of Algorithms, 2024

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

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.

(a) 50x ≡ 5000( mod 999)


(b) 495x ≡ 5000( mod 999)

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.

(a) What is the smallest such r for p = 13?


(b) What is the smallest such r for p = 17?
(c) Prove that r is a divisor of p − 1.

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

(36, 144, 200) = 36x + 144y + 200z.

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).

10. The following algorithm computes a function f : N → N:


Compute(n)
(1) Set x ← 
n;
 x+ n 
j k 
x ;
 
(2) Set y ←  2
(3) If y < x, set x ← y and go to step 2. Otherwise, output x and terminate the algorithm.

(a) Determine the function f (n).


(b) Find the time complexity of Compute(n).
(c) Prove that Compute(n) correctly computes f (n).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy