Math Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Similar documents
Why do we need math in a data structures course?

Cpt S 223. School of EECS, WSU

CS 331 DESIGN AND ANALYSIS OF ALGORITHMS DYNAMIC PROGRAMMING. Dr. Daisy Tang

Dynamic Programming! CSE 417: Algorithms and Computational Complexity!

Exercises. 18 Algorithms

Calculation of time complexity (3%)

Outline and Reading. Dynamic Programming. Dynamic Programming revealed. Computing Fibonacci. The General Dynamic Programming Technique

Problem Set 9 Solutions

THE CHINESE REMAINDER THEOREM. We should thank the Chinese for their wonderful remainder theorem. Glenn Stevens

College of Computer & Information Science Fall 2009 Northeastern University 20 October 2009

Foundations of Arithmetic

CHAPTER 17 Amortized Analysis

a b a In case b 0, a being divisible by b is the same as to say that

IS 709/809: Computational Methods for IS Research. Math Review: Algorithm Analysis

Some Consequences. Example of Extended Euclidean Algorithm. The Fundamental Theorem of Arithmetic, II. Characterizing the GCD and LCM

Multilayer Perceptron (MLP)

Dynamic Programming 4/5/12. Dynamic programming. Fibonacci numbers. Fibonacci: a first attempt. David Kauchak cs302 Spring 2012

Example: (13320, 22140) =? Solution #1: The divisors of are 1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18, 20, 27, 30, 36, 41,

Exercises of Chapter 2

First day August 1, Problems and Solutions

Math 2534 Final Exam Review Answer Key 1. Know deþnitions for the various terms: a. Modus Ponens b. Modus Tollens c. divides d. rational e.

Dynamic Programming. Preview. Dynamic Programming. Dynamic Programming. Dynamic Programming (Example: Fibonacci Sequence)

Section 8.3 Polar Form of Complex Numbers

Math 261 Exercise sheet 2

find (x): given element x, return the canonical element of the set containing x;

Yong Joon Ryang. 1. Introduction Consider the multicommodity transportation problem with convex quadratic cost function. 1 2 (x x0 ) T Q(x x 0 )

Design and Analysis of Algorithms

Introduction to Algorithms

Anti-van der Waerden numbers of 3-term arithmetic progressions.

Structure and Drive Paul A. Jensen Copyright July 20, 2003

VQ widely used in coding speech, image, and video

= z 20 z n. (k 20) + 4 z k = 4

Finding Primitive Roots Pseudo-Deterministically

18.781: Solution to Practice Questions for Final Exam

Module 3 LOSSY IMAGE COMPRESSION SYSTEMS. Version 2 ECE IIT, Kharagpur

Lecture Notes on Linear Regression

CS 770G - Parallel Algorithms in Scientific Computing

Attacks on RSA The Rabin Cryptosystem Semantic Security of RSA Cryptology, Tuesday, February 27th, 2007 Nils Andersen. Complexity Theoretic Reduction

Digital Signal Processing

Review of Taylor Series. Read Section 1.2

NUMERICAL DIFFERENTIATION

International Mathematical Olympiad. Preliminary Selection Contest 2012 Hong Kong. Outline of Solutions

6. Stochastic processes (2)

Problem Solving in Math (Math 43900) Fall 2013

6. Stochastic processes (2)

arxiv: v1 [math.co] 12 Sep 2014

THE ARIMOTO-BLAHUT ALGORITHM FOR COMPUTATION OF CHANNEL CAPACITY. William A. Pearlman. References: S. Arimoto - IEEE Trans. Inform. Thy., Jan.

A new Approach for Solving Linear Ordinary Differential Equations

Advanced Algebraic Algorithms on Integers and Polynomials

CHAPTER 5 NUMERICAL EVALUATION OF DYNAMIC RESPONSE

System in Weibull Distribution

The Minimum Universal Cost Flow in an Infeasible Flow Network

Introduction to Vapor/Liquid Equilibrium, part 2. Raoult s Law:

Lecture 4: November 17, Part 1 Single Buffer Management

Speeding up Computation of Scalar Multiplication in Elliptic Curve Cryptosystem

APPENDIX A Some Linear Algebra

Combining Constraint Programming and Integer Programming

Learning Theory: Lecture Notes

U.C. Berkeley CS294: Spectral Methods and Expanders Handout 8 Luca Trevisan February 17, 2016

Computing Correlated Equilibria in Multi-Player Games

Basic Regular Expressions. Introduction. Introduction to Computability. Theory. Motivation. Lecture4: Regular Expressions

arxiv: v1 [math.ho] 18 May 2008

SL n (F ) Equals its Own Derived Group

Interactive Bi-Level Multi-Objective Integer. Non-linear Programming Problem

A PROBABILITY-DRIVEN SEARCH ALGORITHM FOR SOLVING MULTI-OBJECTIVE OPTIMIZATION PROBLEMS

Approximate Smallest Enclosing Balls

An (almost) unbiased estimator for the S-Gini index

Line Drawing and Clipping Week 1, Lecture 2

Expected Value and Variance

COMPLEX NUMBERS AND QUADRATIC EQUATIONS

arxiv: v1 [math.co] 1 Mar 2014

Ensemble Methods: Boosting

LOW BIAS INTEGRATED PATH ESTIMATORS. James M. Calvin

2.3 Nilpotent endomorphisms

EEL 6266 Power System Operation and Control. Chapter 3 Economic Dispatch Using Dynamic Programming

Introduction to Algorithms

Expectation propagation

P R. Lecture 4. Theory and Applications of Pattern Recognition. Dept. of Electrical and Computer Engineering /

NP-Completeness : Proofs

Dirichlet s Theorem In Arithmetic Progressions

Chowla s Problem on the Non-Vanishing of Certain Infinite Series and Related Questions

), it produces a response (output function g (x)

SUCCESSIVE MINIMA AND LATTICE POINTS (AFTER HENK, GILLET AND SOULÉ) M(B) := # ( B Z N)

(2mn, m 2 n 2, m 2 + n 2 )

Beyond Zudilin s Conjectured q-analog of Schmidt s problem

Section 3.6 Complex Zeros

Algorithm for Equal Distribution of Identical Elements on One Dimensional Field

Valuated Binary Tree: A New Approach in Study of Integers

Hila Etzion. Min-Seok Pang

Logistic Regression. CAP 5610: Machine Learning Instructor: Guo-Jun QI

Faster Searching by Elimination

J. Number Theory 130(2010), no. 4, SOME CURIOUS CONGRUENCES MODULO PRIMES

Suggested solutions for the exam in SF2863 Systems Engineering. June 12,

THERE ARE INFINITELY MANY FIBONACCI COMPOSITES WITH PRIME SUBSCRIPTS

Hongyi Miao, College of Science, Nanjing Forestry University, Nanjing ,China. (Received 20 June 2013, accepted 11 March 2014) I)ϕ (k)

The Order Relation and Trace Inequalities for. Hermitian Operators

MERGESORT BBM ALGORITHMS DEPT. OF COMPUTER ENGINEERING ERKUT ERDEM. Mergesort. Feb. 27, 2014

Prof. Dr. I. Nasser Phys 630, T Aug-15 One_dimensional_Ising_Model

Resource Allocation with a Budget Constraint for Computing Independent Tasks in the Cloud

Grover s Algorithm + Quantum Zeno Effect + Vaidman

Transcription:

Math Revew CptS 223 dvanced Data Structures Larry Holder School of Electrcal Engneerng and Computer Scence Washngton State Unversty 1

Why do we need math n a data structures course? nalyzng data structures and algorthms Dervng formulae for tme and memory requrements Wll the soluton scale? Provng algorthm correctness 2

Floors and Celngs floor(x), denoted x, s the greatest nteger x celng(x), denoted x, s the smallest nteger x ormally used to dvde nput nto ntegral parts 2 + 2 3

Example Consder lgorthm1 that dvdes the nput array n half and calls lgorthm2 on each half lgorthm1 (,n) // s an nteger array of sze n x floor(n/2) lgorthm2 (,1,x) lgorthm2 (,x+1,n) ssume lgorthm2(,,j) s runnng tme s proportonal to (j-+1) What s the runnng tme of lgorthm1? 4

Exponents 5 1 2 2 2 2 2 ) ( + + + + B B B B B B

Logarthms log log log log log log lg ln B B log log B < B log log log log B log 2 for all ; ; e, B, C B log + log B; B e C C B B > 0 2.7182... "logarthm of > 0, 1, B > 0 B base " "natural logarthm" In Wess book, log log 2 6

Example How many tmes to halve an array of length n untl ts length s 1? Halve (n) 0 whle n 1 + 1 n floor(n/2) return 7

Factorals n! n! < n n! 1 f n 0 n ( n 1)! f n > 0 n n 2π n ( n / e) (1 +θ (1/ n)) Strlng's approxmaton PermutatonSort (,n) // s an nteger array of length n whle s not n order Permute () 8

9 Seres General Lnearty rthmetc seres + + + f f f f 0 ) (... (1) (0) ) ( + 1 2 1) ( + + g f c g cf 0 0 0 ) ( ) ( )) ( ) ( (

Seres Geometrc seres 0 0 + 1 1 1 0 1 ; 1 f 0 < < 1 Example How many nodes n a complete bnary tree of depth D? 3 15 10 22 12 19 27 10

Modular rthmetc mod ( mod ) " s congruent to B modulo " E.g., 81 If Then + C and D 61 1(mod10) B (mod ) / BD (mod ) ( B mod ) B + C (mod ) "remander" B (mod ) Bass of most encrypton schemes: (Message mod Key) 11

Proofs What do we want to prove? Propertes of a data structure always hold for all operatons lgorthm runnng tme/memory wll never exceed some lmt lgorthm wll always be correct lgorthm wll always termnate Technques Proof by nducton Proof by counterexample Proof by contradcton 12

Proof by Inducton Goal: Prove some hypothess s true Three-step process 1. Base case: Show hypothess s true for some ntal condtons 2. Inductve hypothess: ssume hypothess s true for all values k 3. Show hypothess s true for next larger value (typcally k+1) 13

Example Prove arthmetc seres ( + 1) 1 2 (Step 1) Base case: Show true for 1 1 1(1 + 1) 1 1 2 14

Example (cont.) (Step 2) ssume true for k (Step 3) Show true for k+1 k + 1 1 ( k + 1) + 1 k( k + 1) ( k + 1) + 2 2( k + 1) + k( k + 1) 2 ( k + 1)( k + 2) 2 k 15

More Examples Prove the geometrc seres 0 + 1 1 1 Prove that the number of nodes n a complete bnary tree of depth D s 2 D+1-1 16

Proof by Counterexample Prove hypothess s not true by gvng an example that doesn t work Example: 2 > 2? Proof by example? Proof by lots of examples? Proof by all possble examples? Emprcal proof Hard when nput sze and contents can vary arbtrarly 17

nother Example 100 D 20 100 10 10 Travelng salesman problem Gven ctes and costs for travelng between each par of ctes, fnd the least-cost tour to vst each cty exactly once Hypothess B C 10 Gven a least-cost tour for ctes, the same tour wll be least-cost for (-1) ctes E.g., f B C D s the least-cost tour for ctes {,B,C,D}, then B C wll be the least-cost tour for ctes {,B,C} 18

nother Example (cont.) Counterexample Cost ( B C D) 40 (optmal) Cost ( B C) 30 Cost ( C B) 20 100 D 20 100 10 10 B C 10 19

Proof by Contradcton ssume hypothess s false Show ths assumpton leads to a contradcton (.e., some know property s volated) Can t use specal cases or specfc examples Therefore, hypothess must be true 20

Example Varant of travelng salesman problem Gven ctes and costs for travelng between each par of ctes, fnd the least-cost path to go from cty to cty Y Hypothess 100 D 20 100 100 10 least-cost path from to Y contans least-cost paths from to every cty on the path E.g., f C1 C2 C3 Y s the least-cost path from to Y, then B C 10 C1 C2 C3 s the least-cost path from to C3 C1 C2 s the least-cost path from to C2 C1 s the least-cost path from to C1 21

Example (cont.) ssume hypothess s false I.e., Gven a least-cost path P from to Y that goes through C, there s a better path P from to C than the one n P Show a contradcton But we could replace the subpath from to C n P wth ths lesser-cost path P The path cost from C to Y s the same Thus we now have a better path from to Y But ths volates the assumpton that P s the least-cost path from to Y Therefore, the orgnal hypothess must be true P C Y 22

Recurson recursve functon s defned n terms of tself 1 f n 0 Example: n! n ( n 1)! f n > 0 Factoral (n) f n 0 then return 1 else return (n * Factoral (n-1)) 23

Basc Rules of Recurson Base cases Must always have some base cases, whch can be solved wthout recurson Makng progress Recursve calls must always make progress toward a base case Desgn rule ssume all recursve calls work Compound nterest rule ever duplcate work by solvng the same nstance of a problem n separate recursve calls

Example Fbonacc numbers F(0) 1 F(1) 1 F(n) F(n-1) + F(n-2) Fbonacc (n) f (n 1) then return 1 else return (Fbonacc (n-1) + Fbonacc (n-2)) Dd you know? The number of petals on a flower s usually a Fbonacc number? Ths dasy has F(8)34 petals. 25

Example (cont.) Fbonacc (5) F(5) F(4) F(3) F(3) F(2) F(2) F(1) F(2) F(1) F(1) F(0) F(1) F(0) F(1) F(0) 26

Example (cont.) Show that the runnng tme T(n) of Fbonacc(n) s exponental n n Use mathematcal nducton Show T(n) c2 n for some postve constant c Base case: T(1) c2 n 2c (true for some constant c > 0) Inductve hypothess: T(k) c2 k Show T(k+1) c2 k+1 ctually, only proved that T(n) s no more than exponental eed to also prove T(n) s at least exponental 27

Summary Floors, celngs, exponents, logarthms, seres, and modular arthmetc Proofs by mathematcal nducton, counterexample and contradcton Recurson Tools to help us analyze the performance of our data structures and algorthms 28