MA/CSSE 473 Day 27. Dynamic programming

Similar documents
1 Onto functions and bijections Applications to Counting

This lecture and the next. Why Sorting? Sorting Algorithms so far. Why Sorting? (2) Selection Sort. Heap Sort. Heapsort

The Selection Problem - Variable Size Decrease/Conquer (Practice with algorithm analysis)

For combinatorial problems we might need to generate all permutations, combinations, or subsets of a set.

Algorithms Design & Analysis. Hash Tables

Homework 1: Solutions Sid Banerjee Problem 1: (Practice with Asymptotic Notation) ORIE 4520: Stochastics at Scale Fall 2015

CHAPTER 4 RADICAL EXPRESSIONS

MA 524 Homework 6 Solutions

Lecture 3. Sampling, sampling distributions, and parameter estimation

Laboratory I.10 It All Adds Up

8.1 Hashing Algorithms

Ahmed Elgamal. MDOF Systems & Modal Analysis

A tighter lower bound on the circuit size of the hardest Boolean functions

Midterm Exam 1, section 2 (Solution) Thursday, February hour, 15 minutes

Chapter 9 Jordan Block Matrices

PTAS for Bin-Packing

{ }{ ( )} (, ) = ( ) ( ) ( ) Chapter 14 Exercises in Sampling Theory. Exercise 1 (Simple random sampling): Solution:

2006 Jamie Trahan, Autar Kaw, Kevin Martin University of South Florida United States of America

means the first term, a2 means the term, etc. Infinite Sequences: follow the same pattern forever.

hp calculators HP 30S Statistics Averages and Standard Deviations Average and Standard Deviation Practice Finding Averages and Standard Deviations

MATH 371 Homework assignment 1 August 29, 2013

Non-uniform Turán-type problems

Algorithms Theory, Solution for Assignment 2

Taylor s Series and Interpolation. Interpolation & Curve-fitting. CIS Interpolation. Basic Scenario. Taylor Series interpolates at a specific

Descriptive Statistics

AN UPPER BOUND FOR THE PERMANENT VERSUS DETERMINANT PROBLEM BRUNO GRENET

EECE 301 Signals & Systems

Third handout: On the Gini Index

STATISTICAL PROPERTIES OF LEAST SQUARES ESTIMATORS. x, where. = y - ˆ " 1

MEASURES OF DISPERSION

Multivariate Transformation of Variables and Maximum Likelihood Estimation

THE ROYAL STATISTICAL SOCIETY HIGHER CERTIFICATE

Mu Sequences/Series Solutions National Convention 2014

Complex Numbers Primer

d dt d d dt dt Also recall that by Taylor series, / 2 (enables use of sin instead of cos-see p.27 of A&F) dsin

Evaluating Polynomials

18.413: Error Correcting Codes Lab March 2, Lecture 8

Lecture 16: Backpropogation Algorithm Neural Networks with smooth activation functions

Lecture 02: Bounding tail distributions of a random variable

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand DIS 10b

1. A real number x is represented approximately by , and we are told that the relative error is 0.1 %. What is x? Note: There are two answers.

Bounds on the expected entropy and KL-divergence of sampled multinomial distributions. Brandon C. Roy

Midterm Exam 1, section 1 (Solution) Thursday, February hour, 15 minutes

5 Short Proofs of Simplified Stirling s Approximation

Chapter 5 Properties of a Random Sample

( q Modal Analysis. Eigenvectors = Mode Shapes? Eigenproblem (cont) = x x 2 u 2. u 1. x 1 (4.55) vector and M and K are matrices.

UNIT 2 SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS

Feature Selection: Part 2. 1 Greedy Algorithms (continued from the last lecture)

Computational Geometry

Department of Agricultural Economics. PhD Qualifier Examination. August 2011

f f... f 1 n n (ii) Median : It is the value of the middle-most observation(s).

CHAPTER 6. d. With success = observation greater than 10, x = # of successes = 4, and

Bayes Decision Theory - II

Summary of the lecture in Biostatistics

Derivation of 3-Point Block Method Formula for Solving First Order Stiff Ordinary Differential Equations

C-1: Aerodynamics of Airfoils 1 C-2: Aerodynamics of Airfoils 2 C-3: Panel Methods C-4: Thin Airfoil Theory

Lecture 9: Tolerant Testing

3. RECURSIVE ALGORITHMS AND RECURRENCE RELATIONS

Introduction to local (nonparametric) density estimation. methods

Investigating Cellular Automata

22 Nonparametric Methods.

F. Inequalities. HKAL Pure Mathematics. 進佳數學團隊 Dr. Herbert Lam 林康榮博士. [Solution] Example Basic properties

Median as a Weighted Arithmetic Mean of All Sample Observations

ENGI 4421 Propagation of Error Page 8-01

Part 4b Asymptotic Results for MRR2 using PRESS. Recall that the PRESS statistic is a special type of cross validation procedure (see Allen (1971))

Overview of the weighting constants and the points where we evaluate the function for The Gaussian quadrature Project two

Transforms that are commonly used are separable

Rademacher Complexity. Examples

Introduction to Matrices and Matrix Approach to Simple Linear Regression

A Markov Chain Competition Model

Assignment 7/MATH 247/Winter, 2010 Due: Friday, March 19. Powers of a square matrix

L5 Polynomial / Spline Curves

General Method for Calculating Chemical Equilibrium Composition

Fibonacci Identities as Binomial Sums

Econometric Methods. Review of Estimation

MOLECULAR VIBRATIONS

A Primer on Summation Notation George H Olson, Ph. D. Doctoral Program in Educational Leadership Appalachian State University Spring 2010

Statistics: Unlocking the Power of Data Lock 5

Maps on Triangular Matrix Algebras

CIS 800/002 The Algorithmic Foundations of Data Privacy October 13, Lecture 9. Database Update Algorithms: Multiplicative Weights

ρ < 1 be five real numbers. The

Chapter 3. Linear Equations and Matrices

EVALUATION OF FUNCTIONAL INTEGRALS BY MEANS OF A SERIES AND THE METHOD OF BOREL TRANSFORM

Solving Constrained Flow-Shop Scheduling. Problems with Three Machines

10.1 Approximation Algorithms

SPECIAL CONSIDERATIONS FOR VOLUMETRIC Z-TEST FOR PROPORTIONS

Lecture 07: Poles and Zeros

Newton s Power Flow algorithm

Assignment 5/MATH 247/Winter Due: Friday, February 19 in class (!) (answers will be posted right after class)

Factorization of Finite Abelian Groups

Ideal multigrades with trigonometric coefficients

Increasing Kolmogorov Complexity

Naïve Bayes MIT Course Notes Cynthia Rudin

Applying the condition for equilibrium to this equilibrium, we get (1) n i i =, r G and 5 i

h-analogue of Fibonacci Numbers

QR Factorization and Singular Value Decomposition COS 323

Log1 Contest Round 2 Theta Complex Numbers. 4 points each. 5 points each

Measures of Central Tendency

Johns Hopkins University Department of Biostatistics Math Review for Introductory Courses

å 1 13 Practice Final Examination Solutions - = CS109 Dec 5, 2018

Transcription:

MA/CSSE 473 Day 7 Dyamc Programmg Bomal Coeffcets Warshall's algorthm (Optmal BSTs) Studet questos? Dyamc programmg Used for problems wth recursve solutos ad overlappg subproblems Typcally, we save (memoze) solutos to the subproblems, to avod recomputg them. Prevously see example: Fb()

Dyamc Programmg Example Bomal Coeffcets: C(, k) s the coeffcet of x k the expaso of (+x) C(,0) = C(, ) =. If 0 < k <, C(, k) = C(, k) + C(, k ) Ca show by ducto that the "usual" factoral formula for C(, k) follows from ths recursve defto. A upcomg homework problem. If we do't cache values as we compute them, ths ca take a lot of tme, because of duplcate (overlappg) computato. Computg a bomal coeffcet Bomal coeffcets are coeffcets of the bomal formula: (a + b) = C(,0)a b 0 +... + C(,k)a k b k +... + C(,)a 0 b Recurrece: C(,k) = C(,k) + C(,k ) for > k > 0 C(,0) =, C(,) = for 0 Value of C(,k) ca be computed by fllg a table: 0... k k 0... C(,k ) C(,k) C(,k)

Computg C(, k): Tme effcecy: Θ(k) Space effcecy: Θ(k) If we are computg C(, k) for may dfferet ad k values, we could cache the table betwee calls. Elemetary Dy. Prog. problems These are Secto 8. of Levt Smple ad straghtforward. I am gog to have you read them o your ow. Co row Chage makg Co Collecto 3

Trastve closure of a drected graph We ask ths questo for a gve drected graph G: for each of vertces, (A,B), s there a path from A to B G? Start wth the boolea adjacecy matrx A for the ode graph G. A[][j] s f ad oly f G has a drected edge from ode to ode j. The trastve closure of G s the boolea matrx T such that T[][j] s ff there s a otrval drected path from ode to ode j G. If we use boolea adjacecy matrces, what does M represet? M 3? I boolea matrx multplcato, + stads for or, ad * stads for ad Trastve closure va multplcato Aga, usg + for or, we get T =M + M + M 3 + Ca we lmt t to a fte operato? We ca stop at M. How do we kow ths? Number of umerc multplcatos for solvg the whole problem? 4

Warshall's Algorthm for Trastve Closure Smlar to bomal coeffcets algorthm Assume that the vertces have bee umbered v, v,, v, Graph represeted by a boolea adjacecy matrx M. Numberg s arbtrary, but s fxed throughout the algorthm. Defe the boolea matrx R (k) as follows: R (k) [][j] s ff there s a path from v to v j the drected graph that has the form v = w 0 w w s = v j, where s >=, ad for all t =,, s, the w t s v m for some m k.e, oe of the termedate vertces are umbered hgher tha k What s R (0)? Note that the trastve closure T s R () R (k) example R (k) [][j] s ff there s a path the drected graph v = w 0 w w s = v j, where s >, ad for all t =,, s, the w t s v m for some m k Example: assumg that the ode umberg s alphabetcal order, calculate R (0), R (), ad R () 5

Quckly Calculatg R (k) Back to the matrx multplcato approach: How much tme dd t take to compute A k [][j], oce we have A k? Ca we do better whe calculatg R (k) [][j] from R (k )? How ca R (k) [][j] be? ether R (k ) [][j] s, or there s a path from v to v k that uses o vertces umbered hgher tha v k, ad a smlar path from v k to v j. Thus R (k) [][j] s R (k ) [][j] or ( R (k ) [][k] ad R (k ) [k][j] ) Note that ths ca be calculated costat tme f we already have the three vales from the rght had sde. Tme for calculatg R (k) from R (k )? Total tme for Warshall's algorthm? Code ad example o ext sldes 6

Floyd's algorthm All pars shortest path A etwork s a graph whose edges are labeled by (usually) o egatve umbers. We store those edge umbers as the values the adjacecy matrx for the graph A shortest path from vertex u to vertex v s a path whose edge sum s smallest. Floyd's algorthm calculates the shortest path from u to v for each par (u, v) od vertces. It s so much lke Warshall's algorthm, that I am cofdet you ca quckly get the detals from the textbook after you uderstad Warshall's algorthm. 7

Dyamc Programmg Example OPTIMAL BINARY SEARCH TREES Warmup: Optmal lked lst order Suppose we have dstct data tems x, x,, x a lked lst. Also suppose that we kow the probabltes p, p,, p that each of these tems s the tem we'll be searchg for. Questos we'll attempt to aswer: What s the expected umber of probes before a successful search completes? How ca we mmze ths umber? What about a usuccessful search? 8

9 Examples p = / for each. What s the expected umber of probes? p = ½, p = ¼,, p = /, p = / expected umber of probes: What f the same tems are placed to the lst the opposte order? The ext slde shows the evaluato of the last two summatos Maple. Good practce for you? prove them by ducto Calculatos for prevous slde

What f we do't kow the probabltes?. Sort the lst so we ca at least mprove the average tme for usuccessful search. Self orgazg lst: Elemets accessed more frequetly move toward the frot of the lst; elemets accessed less frequetly toward the rear. Strateges: Move ahead oe posto (exchage wth prevous elemet) Exchage wth frst elemet Move to Frot (oly effcet f the lst s a lked lst) What we are actually lkely to kow s frequeces prevous searches. Our best estmate of the probabltes wll be proportoal to the frequeces, so we ca use frequeces stead of probabltes. Optmal Bary Search Trees Suppose we have dstct data keys K, K,, K ( creasg order) that we wsh to arrage to a Bary Search Tree Suppose we kow the probabltes that a successful search wll ed up at K ad the probabltes that the key a usuccessful search wll be larger tha K ad smaller tha K + Ths tme the expected umber of probes for a successful or usuccessful search depeds o the shape of the tree ad where the search eds up Geeral prcple? 0

Example For ow we cosder oly successful searches, wth probabltes A(0.), B(0.3), C(0.), D(0.4). How may dfferet ways to arrage these to a BST? Geeralze for N dstct values. What would be the worst case arragemet for the expected umber of probes? For smplcty, we'll multply all of the probabltes by 0 so we ca deal wth tegers. Try some other arragemets: Opposte, Greedy, Better, Best?