Advanced Algorithmic Problem Solving Le 6 Math and Search

Similar documents
Advanced Algorithmic Problem Solving Le 3 Arithmetic. Fredrik Heintz Dept of Computer and Information Science Linköping University

ICS141: Discrete Mathematics for Computer Science I

Autar Kaw Benjamin Rigsby. Transforming Numerical Methods Education for STEM Undergraduates

GRAPHING LINEAR EQUATIONS. Linear Equations. x l ( 3,1 ) _x-axis. Origin ( 0, 0 ) Slope = change in y change in x. Equation for l 1.

Numerical Methods (CENG 2002) CHAPTER -III LINEAR ALGEBRAIC EQUATIONS. In this chapter, we will deal with the case of determining the values of x 1

Elementary Linear Algebra

M3P14 EXAMPLE SHEET 1 SOLUTIONS

Titus Beu University Babes-Bolyai Department of Theoretical and Computational Physics Cluj-Napoca, Romania

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Divide-and-Conquer

Addendum. Addendum. Vector Review. Department of Computer Science and Engineering 1-1

The Elementary Arithmetic Operators of Continued Fraction

Lesson 4 Linear Algebra

Westchester Community College Elementary Algebra Study Guide for the ACCUPLACER

Numbers (Part I) -- Solutions

Unit 1. Extending the Number System. 2 Jordan School District

The total number of permutations of S is n!. We denote the set of all permutations of S by

Fast Fourier Transform 1) Legendre s Interpolation 2) Vandermonde Matrix 3) Roots of Unity 4) Polynomial Evaluation

Similar idea to multiplication in N, C. Divide and conquer approach provides unexpected improvements. Naïve matrix multiplication

Section 7.3, Systems of Linear Algebraic Equations; Linear Independence, Eigenvalues, Eigenvectors (the variable vector of the system) and

PROGRESSIONS AND SERIES

SOLUTION OF SYSTEM OF LINEAR EQUATIONS. Lecture 4: (a) Jacobi's method. method (general). (b) Gauss Seidel method.

SM2H. Unit 2 Polynomials, Exponents, Radicals & Complex Numbers Notes. 3.1 Number Theory

Lecture 4 Recursive Algorithm Analysis. Merge Sort Solving Recurrences The Master Theorem

Section IV.6: The Master Method and Applications

Chapter System of Equations

Statistics for Financial Engineering Session 1: Linear Algebra Review March 18 th, 2006

1. (25 points) Use the limit definition of the definite integral and the sum formulas to compute. [1 x + x2

Section 6.3: Geometric Sequences

Taylor Polynomials. The Tangent Line. (a, f (a)) and has the same slope as the curve y = f (x) at that point. It is the best

MATH 118 HW 7 KELLY DOUGAN, ANDREW KOMAR, MARIA SIMBIRSKY, BRANDEN LASKE

Handout #2. Introduction to Matrix: Matrix operations & Geometric meaning

Accuplacer Elementary Algebra Study Guide

Limit of a function:

ECE 102 Engineering Computation

Linear Programming. Preliminaries

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014

Appendix A Examples for Labs 1, 2, 3 1. FACTORING POLYNOMIALS

Merge Sort. Outline and Reading. Divide-and-Conquer. Divide-and-conquer paradigm ( 4.1.1) Merge-sort ( 4.1.1)

Chapter 7 Infinite Series

DETERMINANT. = 0. The expression a 1. is called a determinant of the second order, and is denoted by : y + c 1

Approximate Integration

Discrete Mathematics I Tutorial 12

5. Solving recurrences

Assessment Center Elementary Algebra Study Guide for the ACCUPLACER (CPT)

Solving Systems of Equations

Eigenfunction Expansion. For a given function on the internal a x b the eigenfunction expansion of f(x):

is an ordered list of numbers. Each number in a sequence is a term of a sequence. n-1 term

ALGEBRA. Set of Equations. have no solution 1 b1. Dependent system has infinitely many solutions

ENGINEERING PROBABILITY AND STATISTICS

Student Success Center Elementary Algebra Study Guide for the ACCUPLACER (CPT)

( ) 2 3 ( ) I. Order of operations II. Scientific Notation. Simplify. Write answers in scientific notation. III.

 n. A Very Interesting Example + + = d. + x3. + 5x4. math 131 power series, part ii 7. One of the first power series we examined was. 2!

CH 39 USING THE GCF TO REDUCE FRACTIONS

10.5 Power Series. In this section, we are going to start talking about power series. A power series is a series of the form

Geometric Sequences. Geometric Sequence. Geometric sequences have a common ratio.

Lincoln Land Community College Placement and Testing Office

Infinite Series Sequences: terms nth term Listing Terms of a Sequence 2 n recursively defined n+1 Pattern Recognition for Sequences Ex:

Content: Essential Calculus, Early Transcendentals, James Stewart, 2007 Chapter 1: Functions and Limits., in a set B.

Notes 17 Sturm-Liouville Theory

Vectors. Vectors in Plane ( 2

Repeated Root and Common Root

Lesson-2 PROGRESSIONS AND SERIES

Surds, Indices, and Logarithms Radical

Linford 1. Kyle Linford. Math 211. Honors Project. Theorems to Analyze: Theorem 2.4 The Limit of a Function Involving a Radical (A4)

Lecture 2. Rational Exponents and Radicals. 36 y. b can be expressed using the. Rational Exponent, thus b. b can be expressed using the

Mathacle. PSet Stats, Concepts In Statistics Level Number Name: Date:

Math 3B Midterm Review

Numerical Solutions of Fredholm Integral Equations Using Bernstein Polynomials

INFINITE SERIES. ,... having infinite number of terms is called infinite sequence and its indicated sum, i.e., a 1

YOUR FINAL IS THURSDAY, MAY 24 th from 10:30 to 12:15

,... are the terms of the sequence. If the domain consists of the first n positive integers only, the sequence is a finite sequence.

Linear Algebra. Lecture 1 September 19, 2011

(1) Functions A relationship between two variables that assigns to each element in the domain exactly one element in the range.

Schrödinger Equation Via Laplace-Beltrami Operator

General properties of definite integrals

Error-free compression

Graphing Review Part 3: Polynomials

Algebra II, Chapter 7. Homework 12/5/2016. Harding Charter Prep Dr. Michael T. Lewchuk. Section 7.1 nth roots and Rational Exponents

On The Homogeneous Quintic Equation with Five Unknowns

Week 13 Notes: 1) Riemann Sum. Aim: Compute Area Under a Graph. Suppose we want to find out the area of a graph, like the one on the right:

Inner Product Spaces (Chapter 5)

MTH 146 Class 16 Notes

FACULTY OF MATHEMATICAL STUDIES MATHEMATICS FOR PART I ENGINEERING. Lectures

( x y ) x y. a b. a b. Chapter 2Properties of Exponents and Scientific Notation. x x. x y, Example: (x 2 )(x 4 ) = x 6.

SUTCLIFFE S NOTES: CALCULUS 2 SWOKOWSKI S CHAPTER 11

Lecture 14. Encryption

11/16/2010 The Inner Product.doc 1/9. The Inner Product. So we now know that a continuous, analog signal v t can be expressed as:

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

A GENERAL METHOD FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS: THE FROBENIUS (OR SERIES) METHOD

Important Facts You Need To Know/Review:

Improving XOR-Dominated Circuits by Exploiting Dependencies between Operands. Ajay K. Verma and Paolo Ienne. csda

(II.G) PRIME POWER MODULI AND POWER RESIDUES

LEVEL I. ,... if it is known that a 1

( a n ) converges or diverges.

Laws of Integral Indices

Project 3: Using Identities to Rewrite Expressions

Chapter 2 Infinite Series Page 1 of 9

Primality Test. Rong-Jaye Chen

Numerical Integration

Frequency-domain Characteristics of Discrete-time LTI Systems

Transcription:

Advced Algorithmic Prolem Solvig Le Mth d Serch Fredrik Heitz Dept of Computer d Iformtio Sciece Liköpig Uiversity

Outlie Arithmetic (l. d.) Solvig lier equtio systems (l. d.) Chiese remider theorem (l.5 d.) Prime umers d fctoriztio (l.7 d.8) Heuristic Serch (eercise )

Arithmetic Rge of defult iteger dt types (C++) usiged it = usiged log: (9 digits) usiged log log: (9 digits) How to represet 777! Opertios o Big Iteger Bsic: dd, sutrct, multiply, divide, etc Use high school method

Arithmetic Gretest Commo Divisor (Euclide Algorithm) GCD(, ) = GCD(, ) = GCD(, mod ) it gcd(it, it ) { retur ( ==? : gcd(, % )); } Lest Commo Multiplier LCM(, ) = * / GCD(, ) it lcm(it, it ) { retur ( / gcd(, ) * ); } // Q: why we write the lcm code this wy? GCD/LCM of more th umers: GCD(,, c) = GCD(, GCD(, c)) Fid d,, y such tht d = + y d d = GCD(,) (Eteded Euclide Algorithm) EGCD(,) = (,,) EGCD(,) (d,,y ) = EGCD(, mod ) (d,,y) = (d,y, /*y )

Arithmetic 5 Represetig rtiol umers. Pirs of itegers, where GCD(,)=. Represetig rtiol umers modulo m. The oly difficult opertio is iverse, = (mod m), where iverse eists if d oly if d m re co prime (gcd(,m)=). C e foud usig the Eteded Euclide Algorithm = (mod m) => = qm => qm= (d,, y) = EGCD(,m) => is the solutio iff d =.

Systems of Lier Equtios Mtri form Stdrd form 7 5.5 7 5.5 i differet forms lier equtios c e preseted A system of

Solutios of Lier Equtios 7 is solutio to the followig equtios : 5 7

Solutios of Lier Equtios 8 A set of equtios is icosistet if there eists o solutio to the system of equtios: 5 These equtios re icosistet 8

9 Solutios of Lier Equtios CISE_Topic 9 Some systems of equtios my hve ifiite umer of solutios solutio for ll is ).5( solutios hve ifiite umer of

Grphicl Solutio of Systems of Lier Equtios 5 Solutio =, = CISE_Topic

Crmer s Rule is Not Prcticl Crmer' s Rule c e used to solve the system 5 5, Crmer' s To solve N y N system requires (N )(N -)N! multiplictios. To solve y system,.8 It c e used if Rule is ot prcticl for lrge systems. the determits re computed i efficiet wy CISE_Topic 5 multiplictios re eeded.

CISE_Topic Nive Gussi Elimitio The method cosists of two steps: Forwrd Elimitio: the system is reduced to upper trigulr form. A sequece of elemetry opertios is used. Bckwrd Sustitutio: Solve the system strtig from the lst vrile. ' ' ' ' '

Elemetry Row Opertios Addig multiple of oe row to other Multiply y row y o zero costt CISE_Topic

CISE_Topic Emple: Forwrd Elimitio 8 7 8,, from equtios Elimite Step: Forwrd Elimitio : Prt 9 8 9 8

5 CISE_Topic 5 Emple: Forwrd Elimitio 9 5 fromequtio Elimite Step: 9 5, from equtios Elimite Step :

CISE_Topic Emple: Forwrd Elimitio 9 5 9 8 9 8 Elimitio : the Forwrd Summry of

7 CISE_Topic 7 Emple: Bckwrd Sustitutio () ) ( (), () ) ( 5 9,,...solve for for solve the, for Solve 9 5

8 CISE_Topic 8 Forwrd Elimitio i j i j i i i j i ij ij i i i j i ij ij ) ( To elimite ) ( To elimite

9 CISE_Topic 9 Forwrd Elimitio is elimited. Cotiue util ) ( To elimite k kk ik i i kj kk ik ij ij k i k j k

CISE_Topic Bckwrd Sustitutio i i i j j j i i i,,,,,,,,

Nive Gussi Elimitio o The method cosists of two steps o Forwrd Elimitio: the system is reduced to upper trigulr form. A sequece of elemetry opertios is used. o Bckwrd Sustitutio: Solve the system strtig from the lst vrile. Solve for,,. CISE_Topic ' ' ' ' '

CISE_Topic Emple 7 7 5 8 7 ) ( 8, from equtios Elimite Elimitio Step: Forwrd : Prt Gussi Elimitio : Nive usig Solve eq eq eq eq eq eq equtio pivot uchged eq

CISE_Topic Emple 8 5 7 7 5 ) ( 8 from equtio Elimite Step : Forwrd Elimitio : Prt eq eq eq equtio pivot uchged eq uchged eq

CISE_Topic Emple : Bckwrd Sustitutio The solutio is 8,,,,,,,

Determit 5 The elemetry opertios do ot ffect the determit Emple: Elemetry opertios A A' det(a) det(a') CISE_Topic 5

How My Solutios Does System of Equtios AX=B Hve? Uique det(a) reduced mtri hs o zero rows No solutio det(a) reduced mtri hs oe or more zero rows correspodig B elemets Ifiite det(a) reduced mtri hs oe or more zero rows correspodig B elemets CISE_Topic

7 CISE_Topic 7 Emples.5!.5 # : solutios ifite # of No solutio Uique X impossile X solutios Ifiite No solutio solutio X X X X X X

Pseudo-Code: Forwrd Elimitio 8 Do k = to Do i = k+ to fctor = i,k / k,k Do j = k+ to i,j = i,j fctor * k,j Ed Do i = i fctor * k Ed Do Ed Do CISE_Topic 8

Pseudo-Code: Bck Sustitutio 9 = /, Do i = dowto sum = i Do j = i+ to sum = sum i,j * j Ed Do i = sum / i,i Ed Do CISE_Topic 9

Prolems with Nive Gussi Elimitio o The Nive Gussi Elimitio my fil for very simple cses. (The pivotig elemet is zero). o Very smll pivotig elemet my result i serious computtio errors CISE_Topic

How Do We Kow If Solutio is Good or Not Give AX=B X is solutio if AX B= Compute the residul vector R= AX B Due to roudig error, R my ot e zero The solutio is cceptle if m i r i CISE_Topic

CISE_Topic How Good is the Solutio?....5 Residues :.75.98.9.87 5 8 5 R solutio

Chiese Remider Theorem First foud i ciet Chiese puzzle: There re certi thigs whose umer is ukow. Repetedly divided y, the remider is ; y 5 the remider is ; d y 7 the remider is. Wht will e the umer? I moder ottio = (mod ) = (mod 5) = (mod 7)

Chiese Remider Theorem

Chiese Remider Theorem 5 Why is the solutio correct? = 7 + + 5 (mod 5) otice tht 7 = (mod ) = (mod 5) = (mod 7) = (mod ) = (mod 5) = (mod 7) 5 = (mod ) = (mod 5) = (mod 7)

7

Chiese Remider Theorem 8 For emple, cosider the prolem of fidig iteger such tht A rute force pproch coverts these cogrueces ito sets d writes the elemets out to the product of 5 = (the solutios modulo for ech cogruece): {, 5, 8,,, 7,,,, 9,, 5, 8,,, 7, 5, 5, 5, 59, } {, 7,, 5, 9,, 7,, 5, 9,, 7, 5, 55, 59, } {,,,,,,,,,, 5, 5, } To fid tht stisfies ll three cogrueces, itersect the three sets to get: {, } Which c e epressed s

Chiese Remider Theorem 9 Aother wy to fid solutio is with sic lger, modulr rithmetic, d stepwise sustitutio. We strt y trsltig these cogrueces ito equtios for some t, s, d u: Eq : = + t Eq : = + s Eq : = + 5u Sustitute from equtio ito cogruece : +t = (mod ) = > t = + s Sustitute t ito equtio : = +s Sustitute this ito cogruece : +s = (mod 5) => s = + 5u Filly, = +s = + (5u) = + u

Primes First prime d the oly eve prime: First primes: {,, 5, 7,,, 7, 9,, 9} Primes i rge: to : 5 primes to, : 8 primes to 7,99 :, primes to, :,9 primes Lrgest prime i siged it it =,7,8,7

Prime Testig Algorithms for testig if N is prime: isprime(n) First try: check if N is divisile y i ϵ [.. N ]? O(N) Improved : Is N divisile y i ϵ [.. sqrt(n)]? O(sqrt(N)) Improved : Is N divisile y i ϵ [, 5,.. sqrt(n)]? Oe test for i=, o eed to test other eve umers! O(sqrt(N)/) = O(sqrt(N)) Improved : Is N divisile y i ϵ primes sqrt(n) O(π(sqrt(N))) = O(sqrt(N)/log(sqrt(N))) π(m) = um of primes up to M For this, we eed smller primes eforehd

Prime Geertio Geerte primes etwee [ N]: Use itset of size N, set ll true ecept ide & Strt from i= util k*i > N If itset t ide iis o, cross ll multiple of i (i.e. tur off it t ide i) strtig from i*i Filly, whtever ot crossed re primes Emple:

Prime Testig d Geertio

Fctoriztio A iteger N c e epressed s: N = PF * N, where PF = prime fctor N' = other umer which is N / PF If N' =, stop; otherwise, repet N is reduced every time we fid divisor

Serch 5 Whe prolem is smll or (lmost) ll possiilities hve to e tried complete serch is cdidte pproch. To determie the fesiility of complete serch estimte the umer of clcultios tht hve to e mde i the worst cse. Itertive complete serch uses ested loops to geerte every possile complete solutio d filter out the vlid oes. Itertig over ll permuttios usig et_permuttio Itertig over ll susets usig it set techique Recursive complete serch eteds prtil solutio with oe elemet util complete d vlid solutio is foud. This pproch is ofte clled recursive cktrckig. Pruig is used to sigifictly improve the efficiecy y removig prtil solutios tht c ot led to solutio s soo s possile. I the est cse oly vlid solutios re geerted.

Summry Arithmetic (l. d.) Solvig lier equtio systems (l. d.) Chiese remider theorem (l.5 d.) Prime umers d fctoriztio (l.7 d.8) Heuristic Serch (eercise )