7 views

Original Title: 02-mathematics.pdf

Uploaded by i_khandelwal

02-mathematics.pdf

Mathematics for Competitive Coding

Attribution Non-Commercial (BY-NC)

- Graphical Method (linear programming Problem)
- suryadevara-hw4
- The Chinese Remainder Theorem
- Usama Ahmed Assignment Mth202
- Transfer Course Equivalencies at University of Delaware
- Generating Functions - David Rhee - Canada 2008
- GATE 2018 CS Paper (Feb 4)
- gcf and lcm - edited
- Machine Exercise 7
- solhwk2
- 012 Prolog.pptx
- math-gcd
- pen2005.pdf
- m228
- 3q-notes
- ejercicios visual.docx
- DMAT Round1
- Introduction to Discrete Mathematics Ch3
- 14. Comp Sci- IJCSEITR - A Fast Factorization Algorithm for - Noureldien a. Noureldien
- Tree Math Discrete

You are on page 1of 27

Jaehyun Park

Todays Lecture

Sum of Powers

2 =1

1 ( 6

+ 1)(2 + 1)

1 2

+ 1

Fast Exponentiation

=

1,

if = 0 , if = 1

2 /2 ,

if is even

, if is odd

2 (1)/2

Implementation (recursive)

double pow(double a, int n) { if(n == 0) return 1; if(n == 1) return a; double t = pow(a, n/2); return t * t * pow(a, n%2); }

Implementation (non-recursive)

double pow(double a, int n) { double ret = 1; while(n) { if(n%2 == 1) ret *= a; a *= a; n /= 2; } return ret; }

Linear Algebra

Gaussian Elimination

Solve

a system of linear equations Invert a matrix Find the rank of a matrix Compute the determinant of a matrix

Cramers Rule

gcd (, ): greatest integer divides both and Used very frequently in number theoretical problems

Some facts:

gcd

Euclidean Algorithm

Repeated use of gcd , = gcd (, ) gcd 1989, 867 = gcd 1989 2 867, 867 = gcd 255, 867 = gcd 255, 867 3 255 = gcd 255, 102 = gcd 255 2 102, 102 = gcd 51, 102 = gcd 51, 102 2 51 = gcd 51, 0 = 51

Implementation

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

5 % 3 == 2 -5 % 3 == -2

(mod) means and have the same remainder when divided by Multiplicative inverse

is the inverse of modulo if 1 1(mod) 1 5 3(mod7) because 5 3 15 1(mod7) May not exist (e.g. Inverse of 2 mod 4) Exists iff gcd , = 1

Multiplicative Inverse

All intermediate numbers computed by Euclidean algorithm are integer combinations of and

gcd , = + for some integers , If gcd , = 1, then + = 1 for some , Taking modulo gives 1(mod)

Therefore,

Main idea: keep the original algorithm, but write all intermediate numbers as integer combinations of and

Exercise: implementation!

Given , , , such that and are coprime Find such that mod , mod

Solution:

1 be the inverse of modulo 1 be the inverse of modulo Let 1 + 1 (check this yourself) Set =

Let

Binomial Coefficients

or,

Computing

Solution 1: Compute using the following formula ( 1) ( + 1) = ! Solution 2: Use Pascals triangle

Case 1: Both and are small

Use

either solution

Use

Solution 1 (carefully)

Fibonacci sequence

Definition:

0

= 0, 1 = 1 = 1 + 2 , where 2

Closed Form

, where =

1+ 5 2

Bad because and 5 are irrational Cannot compute the exact value of for large

There is a more stable way to compute

+1 1 1 1 1 = = 1 0 1 1 0

1 0

Can be extended to support any linear recurrence with constant coefficients

Geometry

Will cover basic stuff today

Computational

geometry in week 9

If

possible, dont use floating-point numbers If you have to, always use double and never use float Avoid division whenever possible Introduce small constant in (in)equality tests

e.g.

Instead of

if(x == 0),

write if(abs(x)

< EPS)

No hacks!

In

2D Vector Operations

Have a vector (, )

Norm (distance from the origin): 2 + 2 Counterclockwise rotation by : cos sin Left-multiply by sin cos

Make

Normal vectors: (, ), ,

Line-Line Intersection

1 1 = Memorize this!

Edge case: =

Circumcircle of a Triangle

Dont try to solve the system of quadratic equations! Instead, do the following:

the bisectors of and Compute their intersection

Find

Area of a Triangle

Cross product:

2

1 =2

+1 1 1

It turns out that the formula above works for nonconvex polygons too

Area

=1( +1

Alternative formula:

2

+1 )

Conclusion

No need to look for one-line closed form solutions Multi-step algorithms are good enough

This

- Graphical Method (linear programming Problem)Uploaded bykratikadhoot
- suryadevara-hw4Uploaded byrakkaraul
- The Chinese Remainder TheoremUploaded byna_hariprsad
- Usama Ahmed Assignment Mth202Uploaded byUsAma AhmEd AwAn
- Transfer Course Equivalencies at University of DelawareUploaded bysheranko
- Generating Functions - David Rhee - Canada 2008Uploaded byTaha
- GATE 2018 CS Paper (Feb 4)Uploaded byNishit kumar
- gcf and lcm - editedUploaded byapi-205487403
- Machine Exercise 7Uploaded byBea Ducao
- solhwk2Uploaded bytrue_kanji
- 012 Prolog.pptxUploaded byRashdeep Singh
- math-gcdUploaded bysj314
- pen2005.pdfUploaded byRavi Kumar
- m228Uploaded byMizanur Rahman
- 3q-notesUploaded byArya Chowdhury
- ejercicios visual.docxUploaded byJussefICjop
- DMAT Round1Uploaded byMachodog
- Introduction to Discrete Mathematics Ch3Uploaded byدانية الجبان
- 14. Comp Sci- IJCSEITR - A Fast Factorization Algorithm for - Noureldien a. NoureldienUploaded byTJPRC Publications
- Tree Math DiscreteUploaded byMohd Huzairi Husin
- PublicationsUploaded bysusan george
- Format for Lab11Uploaded byIshwarDattMishra
- 22Uploaded byRR
- ws transformation practice 2Uploaded byapi-334137347
- New Text DocumentUploaded byShubham Birange
- Mth2102tutorial8 SolutionUploaded byDing Ming
- __ Gate Guide by Air 16 __ _ Gate0000Uploaded byNeil Thomson
- Eurosediacatalogo20112012 PDF 35999161Uploaded byCourtney
- Virtual CalcUploaded byNAVEENKUMAR K
- A COMPARATIVE STUDY ON MULTICAST ROUTING USING DIJKSTRA’S, PRIMS AND ANT COLONY SYSTEMSUploaded byIAEME Publication

- Computer Mediated Communication AnalysisUploaded byi_khandelwal
- icpc-solutions2017Uploaded byi_khandelwal
- Time Series ClassificationUploaded byi_khandelwal
- Assignment 1 MarksUploaded byi_khandelwal
- Introduction to Websim 20130905Uploaded byi_khandelwal
- Value Points for Women EmpowermentUploaded byi_khandelwal
- The Best Way to Learn Ja...t - Tuts+ Code TutorialUploaded byi_khandelwal
- fir filterUploaded byputih_138242459
- Answers - Ch. 3Uploaded byi_khandelwal
- Report WritingUploaded byi_khandelwal
- Lecture 5- ElectronicsUploaded byi_khandelwal
- MID SEM 2012-13Uploaded byi_khandelwal
- Stocks 101Uploaded byi_khandelwal
- TimeTable.pdfUploaded byi_khandelwal
- Introprogramming-Tutorial Sheets-Week 4 Tut 1Uploaded byi_khandelwal
- Introprogramming-Tutorial Sheets-Week 4 Tut 2Uploaded byi_khandelwal
- IIT Delhi Internship _ InternshalaUploaded byi_khandelwal
- AFT's 2-Days Workshop - The Wall Street Club BITS PilaniUploaded byi_khandelwal
- Introprogramming-Tutorial Sheets-Week 1 Tut 2Uploaded byi_khandelwal
- Chelsea WolfeUploaded byi_khandelwal
- Batch_113 Mark 6 NovUploaded byi_khandelwal
- 1Uploaded byi_khandelwal
- Batch List WKND B Lot - Copy (2)Uploaded byi_khandelwal
- Projectile MotionUploaded byguptaprabhu

- intpolyUploaded byCristian Zanoci
- Class7_maths1Uploaded byproodoot
- multiples and factors chartUploaded byapi-373222932
- Lectures on Number Theory - LindahlUploaded byNorman DeVaux Reynolds
- Diophantine EquationsUploaded byHazel Clemente Carreon
- 6th Grade Unit 1 Factors and MultiplesUploaded bymrpernice
- Multiplication Long No Tseparator 0302 AllUploaded byekumararaja
- Short Tricks of Multiplication.pdfUploaded byRamesh Kumar
- 9Maths 1 Number SystemsUploaded byManoj Kumar
- Algorithmic Number Theory-IITDUploaded byforwarddump
- IMO2013SLUploaded byHimansu Mookherjee
- Study Material Numerical AbilityUploaded byAshok Kumar
- 31th Imo 1990-FixUploaded byGuffran septiahadi
- CRITERIA FOR ALMOST PERFECT AND DEFICIENT NUMBERSUploaded byBebita-Dris Jose Arnaldo
- Euler, Goldbach and Fermat TheoremUploaded bypajoroc
- Marcus Du Sautoy, Luke Woodward - Zeta FunctionsUploaded byKK-bookslover
- Answers ProofsUploaded byRimsha Majeed
- Bytewise computation of CRC without Look Up TableUploaded byKalpana Das
- DA01Uploaded byenggshant
- A Primer of Analytic Number TheoryUploaded byJames Condori
- Number TheoryUploaded byTirtharaj Basu
- SMARANDACHE NOTIONS (book series), Vol. 10Uploaded byAnonymous 0U9j6BLllB
- 2.5.29_30_31_32_33_34_35Uploaded byAnonymous 7U6OsH
- 8Uploaded byAmit Kumar Jain
- Mas4203 Class Notes1Uploaded bySarita Dudi
- Fun Pack SurdsUploaded byngeekeng
- Ne7207 Nis Unit 3 Question BankUploaded byalgatesgiri
- Paper 3aUploaded byCynthia Amboy
- Lesson 3.4 Zeros of Polynomials.pdfUploaded bymomathtchr
- Cat 8Uploaded byharshsrivastavaalld