More Mathematical Techniques

Slides:



Advertisements
Similar presentations
Dynamic Programming Introduction Prof. Muhammad Saeed.
Advertisements

Factoring Polynomials
Study Guides Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM Mycatstudy.com.
Decimals and Fractions
ACM Workshop Number Theory.
Types of Number
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
1. Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Factoring CHAPTER 6.1Greatest Common Factor and Factoring by Grouping.
Dynamic Programming Technique. D.P.2 The term Dynamic Programming comes from Control Theory, not computer science. Programming refers to the use of tables.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
- ABHRA DASGUPTA Solving Adhoc and Math related problems.
1 Adversary Search Ref: Chapter 5. 2 Games & A.I. Easy to measure success Easy to represent states Small number of operators Comparison against humans.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Applied Discrete Mathematics Week 9: Relations
CSCI 1900 Discrete Structures
Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM
Factoring Polynomials
3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors Let each of a and b be integers. We say that a divides b, in symbols a | b, provided.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Learn to solve systems of equations.
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
CSC401: Analysis of Algorithms CSC401 – Analysis of Algorithms Chapter Dynamic Programming Objectives: Present the Dynamic Programming paradigm.
CS 8833 Algorithms Algorithms Dynamic Programming.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
Mathematics.
Modular (Remainder) Arithmetic n = qk + r (for some k; r < k) eg 37 = (2)(17) + 3 Divisibility notation: 17 | n mod k = r 37 mod 17 = 3.
Dynamic Programming1. 2 Outline and Reading Matrix Chain-Product (§5.3.1) The General Technique (§5.3.2) 0-1 Knapsack Problem (§5.3.3)
A binomial is a polynomial with two terms such as x + a. Often we need to raise a binomial to a power. In this section we'll explore a way to do just.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
Real Zeros of Polynomial Functions
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Copyright © 2011 Pearson Education, Inc. Factoring CHAPTER 6.1Greatest Common Factor and Factoring by Grouping 6.2Factoring Trinomials of the Form x 2.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Problem Solving: Brute Force Approaches
Mathematics of Cryptography
Solving Quadratic Equations by Factoring
Chapter 15 Recursion.
More Mathematical Techniques
Polynomials & Factoring
Modeling with Recurrence Relations
Monte Carlo simulation
Objective The student will be able to:
Welcome to Interactive Chalkboard
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Introducing sequences
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Number Theory (Chapter 7)
Data Structures and Algorithms
Chapter 5 Induction and Recursion
a*(variable)2 + b*(variable) + c
Recursion "To understand recursion, one must first understand recursion." -Stephen Hawking.
Problem Solving: Brute Force Approaches
Dynamic Programming.
a*(variable)2 + b*(variable) + c
4.5 Applications of Pascal’s Triangle
Mathematics Basic Math and Combinatorics
a*(variable)2 + b*(variable) + c
Minimax strategies, alpha beta pruning
Recurrence Relations Discrete Structures.
More Mathematical Techniques
Minimax strategies, alpha beta pruning
Data Structures and Algorithms
Presentation transcript:

More Mathematical Techniques

Special Number Sequences Fibonacci numbers Fib(0) = 0, Fib(1) = 1, Fib(n) = Fib(n-1)+Fib(n-2) Dynamic Programming is usually used But, there are faster methods – matrix powers Sometimes require Java Bigints to use Zeckendorf’s Theorem: Every positive integer can be written as a sum of Fibonacci numbers, no two of which are consecutive. Can determine this greedily – choosing largest possible at each step Pisano Period Last digit/Last 2 digits/Last 3 digits/Last 4 digits repeat with period 60/300/1500/15000

Special Number Sequences Binomial Coefficients Coefficients of powers of a binomial (x+y)n kth coefficient is C(n,k) Can use the ways to compute C, as mentioned earlier Can find with Pascal’s Triangle Row 1 is 1 Row 2 is 1 1 Row 3 is 1 2 1 Row 4 is 1 3 3 1 Each row is 1 longer. End values are 1, those in middle are sum of 2 above it Good if need all numbers

Special Number Sequences Catalan Numbers Cat(n) = C(2n,n)/(n+1) Cat(0) = 1 Cat(n+1) = Cat(n) * [(2n+2)(2n+1)]/[(n+2)(n+1)] Useful for several problems: Number of distinct binary trees with n vertices Number of expressions containing n pairs of parentheses that are correctly matched Number of ways n+1 factors can be parenthesized fully Number of ways a convex polygon with n+2 sides can be triangulated Number of monotonic paths on an nxn grid that don’t pass diagonal

Prime Numbers To test if a number is prime Could check divisibility by all numbers < sqrt(n) Could check divisibility by all ODD numbers < sqrt(n) Could check divisibility by all PRIME numbers < sqrt(n) To generate primes, could repeatedly test, then add on to list as new ones are found Useful if you just are testing one number, and it’s large. Or, use Sieve of Erastothenes to find all primes in some range Mark all numbers as primes to start; start pointer at 1 Repeat: Pick next prime number (on first iteration, this will be 2, then 3, then 5) Mark all multiples of that number as not prime (increment by that amount, marking not prime)

GCD and LCM GCD: gcd(a,b) LCM: lcm(a,b) Use Euclid’s algorithm If b == 0, return a, otherwise: return gcd(b, a%b) Notice that gcd(a,b,c) = gcd(a,gcd(b,c)), etc. LCM: lcm(a,b) calculate lcm(a,b) = a*(b/gcd(a,b)) Notice you wan to divide by gcd first, to avoid intermediate overflow

Extended Euclid Algorithm Can tell x, y in a Diophantine equation: ax + by = c d = gcd(a,b). d must divide c First solution via extended Euclid algorithm Euclid(a,b): If b == 0, x=1, y=0, d = a extendedEuclid(b, a%b) x1 = y y1 = x – (a/b)*y x=x1 y=y1 That gives only the first (of an infinite number) valid solution, x0, y0 Others are x = x0 + (b/d) n; y =y0 + (a/d) n

Finding Repeating Cycles Sometimes you have a sequence in which the sequence begins repeating. Want to find point at which the repeating sequences start: This is m Want to find the length of the sequence. This is l Can store each value computed. Then, when new value is generated, see if you already found it. If you need the actual value when first found, store in a map. Value gives m, can subtract from current value to get l If you just need to know if a repetition exists, store in a set.

Floyd’s Cycle-Finding Notice that if l is the cycle length, then for i > m, xi = xi+kl Just let kl = i. SO, xi = x2i Can iterate two pointers: a lower one that increases by 1 per step, and an upper one that increases by 2 per step When the two values match, you have i, 2i. So kl = i. To find m, start one pointer at i, and one at beginning. Then, increment them both by 1. When they match, the first is at m. Finally, you can get l by setting one pointer to m and one to m+1, then increment the bigger pointer until it matches m. That difference is l.

Game Playing Can determine who will win a (simple) game by exploring the game space. Use a minimax tree. Generate possible moves at each level Player 1 will pick the best from available choices (win if possible) Player 2 will pick the worst move from player 1’s perspective (i.e. make player 1 lose if possible) If each plays optimally, who will win? Can determine if you explore entire tree, or enough to ensure a choice is known at any level In real games (probably not contest), you can use alpha-beta pruning to speed things up.