







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Intro/Poli Sci:Amer Politics; Subject: Political Science; University: University of California - San Diego; Term: Winter 2002;
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








10/1/
CSE 202 - More Math
CSE 202 - More Math
2
GCD stands for “greatest common divisor”.
E.g. GCD(10, 25) = 5.
If GCD(A,B)=1, we say A and B are relatively prime.
Note that GCD(N, 0) = N. (At least for N>0.)
Thm: If A + kB = C and B
∫
0, then GCD(A,B) = GCD(B,C).
Proof. Let g = GCD(A,B) and h = GCD(B,C).Since g divides A and B, it must divide A + kB = C.Since g is a common divisor of B and C, it must be
their
h.
Reversing the roles of A and C, we conclude that h
g.
Thus, g = h. QED
The Euclidean Algorithm finds GCD(A,B).Given A > B > 0, set C = A mod B (so C = A - kB for some k and C<B).
This reduces the problem of finding GCD(A,B) to the smaller problem,
finding GCD(B,C). Eventually, we’ll get to GCD(X,0) = X.
CSE 202 - More Math
4
Example: Find GCD of 38 and 10.38 mod 10 = 810 mod 8 = 28 mod 2 = 0GCD(2,0) = 2
Can write “2” as linear combination of 10 and 38.
8 = 38 - 3x102 = 10 – 1x
= 10 – 1x(38–3x10)
2 = 4x10 – 1x
Lets you write 8 in terms of 38 and 10Lets you write 2 in terms of 10 and 8.
Change 8’s to 10’s
and 38’s
Voila!
Extended
CSE 202 - More Math
5
Solve Diophantine Equations:
4x10 – 1x38),
then multiply by 6/GCD = 3
(6 = 12x10 – 3x38).
Rational approximations:
E.g. 31416 = 3x10000 + 1416
10000 = 7x1416 + 88
Let’s pretend 88
Thus, 31416
3x10000 + 10000/7 = 10000x(3+1/7)
Thus, 3.
We can get all “close” approximations this way.
Linear equations over integers
CSE 202 - More Math
7
CSE 202 - More Math
8
Standard method for multiplying long numbers:
(1000a+b)x(1000c+d) = 1,000,000 ac
1000 (ad + bc)
bd
Clever trick:(1000a+b)x(1000c+d) = 1,000,000 ac
1000 ( (a+b)(c+d) – ac - bd)
bd
One length-k multiply = 3 length-k/2 multiplies and a
bunch of additions and shifting.
On computer, might use 2
16
in place of 1000
Fine print: If “a+b”
has 17 bits, drop the top bit, but add extra c+d in the right
place. Handle overflow for c+d similarly.
4 multiplies: ac, ad, bc, bd
3 multiplies:
ac, (a+b)(c+d), bd
CSE 202 - More Math
10
c n
c n/
c n/
c n/
c n/
c n/
c n/
c n/
c n/
1 depth-0 node 3 depth-1 nodes
9 depth-2 nodes
...
3
lg n
depth-lg nnodes
...
...
c
c
c
...
c
c
c
...
...
c
c
c
CSE 202 - More Math
11
T(n) < cn ( 1 + 3(1/2) + 9(1/4) + ... + 3
lg n
(1/ 2
lg n
) )
< cn ( 1 + 3/2 + (3/2)
2
lg n
).
Lemma 1: For a
∫
1, a
k
k-
k+
Proof:
(a
k
k-
a
k+
It’s obvious! (Multiply it out – middle terms cancel.)
By lemma 1, T(n) < cn ( (3/2)
(lg n + 1)
-
< cn ( (3/2)
lg n
(3/2) – 0) / (1/2)
= c n (3/2)
lg n
(3/2)/(1/2)
= 3 c n (3/2)
lg n
.
CSE 202 - More Math
13
advantage.
recurrence equations.