0 Up votes0 Down votes

2 views30 pagesTRY

Sep 15, 2016

© © All Rights Reserved

PDF, TXT or read online from Scribd

TRY

© All Rights Reserved

2 views

TRY

© All Rights Reserved

- Ada Book
- Vectors Problems.pdf
- Date Calculation Algorithms
- LUC
- abcd
- 2008FermatContest
- Ashish
- 17254093 Quantitative
- Some Modification in ID-Based Public Key Cryptosystem Using IFP and DDLP
- 10.1.1.97.2879
- 1997 Paper 1
- paper1k
- Practice Session
- Apty Formulas
- Lesson Plan
- Exam
- MAT117 MAT 117 117.docx
- Algorithms
- Programs
- 018RSA Cryptography Algorithm Using linear Congruence Class.

You are on page 1of 30

Jaehyun Park

CS 97SI

Stanford University

Outline

Algebra

Number Theory

Combinatorics

Geometry

Algebra

Sum of Powers

n

X

k2 =

k=1

k3 =

1

n(n + 1)(2n + 1)

6

X 2

Memorize above!

Algebra

2

1

n(n + 1)

2

Fast Exponentiation

Recursive computation of an :

an =

Algebra

(an/2 )2

a(a(n1)/2 )2

n=0

n=1

n is even

n is odd

Implementation (recursive)

if(n == 0) return 1;

if(n == 1) return a;

double t = pow(a, n/2);

return t * t * pow(a, n%2);

}

Algebra

Implementation (non-recursive)

double ret = 1;

while(n) {

if(n%2 == 1) ret *= a;

a *= a; n /= 2;

}

return ret;

}

Algebra

Linear Algebra

Invert a matrix

Algebra

Outline

Algebra

Number Theory

Combinatorics

Geometry

Number Theory

Some facts:

gcd(a, b) = gcd(a, b a)

gcd(a, 0) = a

gcd(a, b) is the smallest positive number in {ax + by | x, y Z}

Number Theory

Euclidean Algorithm

Example:

gcd(1989, 867) = gcd(1989 2 867, 867)

= gcd(255, 867)

= gcd(255, 102)

= gcd(51, 102)

= gcd(51, 0)

= 51

Number Theory

10

Implementation

while(b){int r = a % b; a = b; b = r;}

return a;

}

Be careful: a % b follows the sign of a

5 % 3 == 2

-5 % 3 == -2

Number Theory

11

when divided by n

Multiplicative inverse

51 3 (mod 7) because 5 3 15 1 (mod 7)

May not exist (e.g., inverse of 2 mod 4)

Exists if and only if gcd(x, n) = 1

Number Theory

12

Multiplicative Inverse

are integer combinations of a and b

Therefore, gcd(a, b) = ax + by for some integers x, y

If gcd(a, n) = 1, then ax + ny = 1 for some x, y

Taking modulo n gives ax 1 (mod n)

Number Theory

13

intermediate numbers as integer combinations of a and b

Exercise: implementation!

Number Theory

14

Solution:

Let m1 be the inverse of m modulo n

Set x = ann1 + bmm1 (check this yourself)

Number Theory

15

Outline

Algebra

Number Theory

Combinatorics

Geometry

Combinatorics

16

Binomial Coefficients

n

is the number of ways to choose k objects out of n

k

distinguishable objects

same as the coefficient of xk y nk in the expansion of

(x + y)n

Hence the name binomial coefficients

Combinatorics

17

!

n

k

n(n 1) (n k + 1)

k!

Combinatorics

18

Fibonacci Sequence

Definition:

F0 = 0, F1 = 1

Fn = Fn1 + Fn2 , where n 2

Combinatorics

19

Closed Form

Fn = (1/ 5)(n n )

There is a more stable way to compute Fn

= (1 + 5)/2

= (1 5)/2

5 are irrational

Combinatorics

20

"

Fn+1

Fn

"

1 1

1 0

#"

Fn

Fn1

"

1 1

1 0

#n "

F1

F0

constant coefficients

Combinatorics

21

Outline

Algebra

Number Theory

Combinatorics

Geometry

Geometry

22

Geometry

Will cover basic stuff today

Geometry

23

If you have to, always use double and never use float

Avoid division whenever possible

Introduce small constant in (in)equality tests

No hacks!

In most cases, randomization, probabilistic methods, small

perturbations wont help

Geometry

24

2D Vector Operations

Counterclockwise rotation by :

"

cos sin

sin cos

x2 + y 2

#"

x

y

Memorize all of them!

Geometry

25

Line-Line Intersection

Write in matrix form:

"

a b

d e

#"

x

y

"

c

f

"

a b

d e

#1

1

=

ae bd

"

e b

d a

Memorize this!

Edge case: ae = bd

The lines coincide or are parallel

Geometry

26

Circumcircle of a Triangle

Instead, do the following:

Compute their intersection

Geometry

27

Area of a Triangle

Cross product:

x

(x1 , y1 ) (x2 , y2 ) = 1

y1

x2

y2

= x1 y2 x2 y1

Geometry

28

Want to compute the area S of P

If P is convex, we can decompose P into triangles:

n1

X

2S = (Pi+1 P1 ) (Pi P1 )

i=2

polygons too

Area is the absolute value of the sum of signed area

n

X

2S = (xi yi+1 xi+1 yi )

i=1

Geometry

29

Conclusion

Have fun with the exercise problems

Geometry

30

- Ada BookUploaded byDheeraj Jain Legay
- Vectors Problems.pdfUploaded byIqbal A Mir
- Date Calculation AlgorithmsUploaded byEddy Chan
- LUCUploaded bysappii10
- abcdUploaded bynguyenthedan
- 2008FermatContestUploaded byRyan Gibson
- AshishUploaded byhktiwari88
- 17254093 QuantitativeUploaded byMohammed Tahoor
- Some Modification in ID-Based Public Key Cryptosystem Using IFP and DDLPUploaded byEditor IJACSA
- 10.1.1.97.2879Uploaded byshrikul_joshi2126
- 1997 Paper 1Uploaded bydocteur
- paper1kUploaded bysolveforz
- Practice SessionUploaded byKamal Lohia
- Apty FormulasUploaded byKumari Priyanka
- Lesson PlanUploaded bysubimathew90
- ExamUploaded byAnis Souissi
- MAT117 MAT 117 117.docxUploaded by116helper
- AlgorithmsUploaded bymohitsuppal
- ProgramsUploaded byAnonymous F0b4RZ5xo
- 018RSA Cryptography Algorithm Using linear Congruence Class.Uploaded byIJAR Journal
- 13 Integers and DivisionUploaded byalice
- algo_lec3_Verifying-correctness-of-algorithm.pdfUploaded byHamza Bhatti
- Mscappmath2013 SolutionsUploaded byEvanora Java
- OutputsUploaded bydipanshu
- Data Analytics in RUploaded byMeliodas Dmo
- M7L1Uploaded byShreesh Kumar
- PRMO_Solutions.pdfUploaded bysamyak
- 1Q Math 7 examsUploaded byNoli Calderon
- IT math functionsUploaded byMadhu Priya Guthi
- EccUploaded byvinodkanna uit

- Sample Website ProposalUploaded byCaksalman Alfarisi
- Aflv 02 Data StructuresUploaded byJuli
- 28 september.txtUploaded byWesley Huang
- 6-00F08-L03 (1)Uploaded byWesley Huang
- Day1 Notice IdUploaded byWesley Huang
- day1-1-enUploaded byWesley Huang
- 3-User_Centered_Design.pptUploaded byWesley Huang
- 04 Dynamic Programming jgUploaded byNikhil Sharma Rayaprolu
- Data StructuresUploaded byThahir Shah
- Beacon 23 - the Complete Novel - Hugh HoweyUploaded byWesley Huang
- Paper PBK- Pengembangan Sistem PBK Studi Kasus Struktur DataUploaded byWesley Huang
- Good Morning EverysoneUploaded byWesley Huang

- Asg Ascii Ebcdic CodingUploaded bymehmood26855
- Geometric Theorems, Diophantine Equations, And Arithmetic FuUploaded bypremsempire
- Chapter 2Uploaded byNikhil Gupta
- 905974762893840382_chapter_8_polynomials-_newUploaded bytina
- Transportation ProblemUploaded bypuneeth h
- optimizationUploaded bylynndong0214
- Hw01 Solution(1)Uploaded bysiddharth1k
- Answer of HW_1 digitalUploaded byMohmed Al Najar
- Error Correction and DetectionUploaded byLince Sebastian
- iopc2011Uploaded byAmit Chandak
- Busca Em GrafosUploaded byGuilherme
- Error Detection and Correction CodeUploaded byDejiAdebayoOmoniyi
- l9Uploaded byValerie Vallo
- CSC159 Ch2 Numbering SystemUploaded byBebek
- 15-Problems on H.C.F and L.C.MUploaded byHAFIZ IMRAN AKHTER
- k-bonacciUploaded byopenid_AePkLAJc
- binomial_expansions_exam_questions.pdfUploaded byasdawanwuwi
- Class 11th d.p.pUploaded byMukesh Kumar
- 19-RecursiveBacktracking.pdfUploaded byجعفر عباس
- Course Contents BS(Hons)Uploaded bywahabmaths
- Fibonacci HeapUploaded bychainika
- 16. Jacobian Elliptic Functions and Theta FunctionsUploaded byAlexandra Nicoleta Teisi
- Complexity TheoryUploaded bySuraj Rajan
- TJAIMEUploaded byLeon Fone
- Simplex methodUploaded byNakul Ashok
- Computer ScienceUploaded byJagadeesh Jagadish
- syllabus CS6505 gatechUploaded byanncar1987
- 4 DLL Error ControlUploaded byraj25com
- GRE.pdfUploaded byKalyan Naskar
- StackUploaded bySunitha Babu

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.