CS473-Algorithms I. Lecture 12b. Dynamic Tables. CS 473 Lecture X 1

Similar documents
Reaction Time VS. Drug Percentage Subject Amount of Drug Times % Reaction Time in Seconds 1 Mary John Carl Sara William 5 4

Collapsing to Sample and Remainder Means. Ed Stanek. In order to collapse the expanded random variables to weighted sample and remainder

10.2 Series. , we get. which is called an infinite series ( or just a series) and is denoted, for short, by the symbol. i i n

PTAS for Bin-Packing

1. Linear second-order circuits

CHAPTER 17 Amortized Analysis

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

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

Econometric Methods. Review of Estimation

Problem Set 3: Model Solutions

REVIEW OF SIMPLE LINEAR REGRESSION SIMPLE LINEAR REGRESSION

Linear Approximating to Integer Addition

Amortized Analysis - Part 2 - Dynamic Tables. Objective: In this lecture, we shall explore Dynamic tables and its amortized analysis in detail.

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

Algorithms Design & Analysis. Hash Tables

Simple Linear Regression Analysis

International Journal of Pure and Applied Sciences and Technology

Basic Structures: Sets, Functions, Sequences, and Sums

CHAPTER 4 RADICAL EXPRESSIONS

ROOT-LOCUS ANALYSIS. Lecture 11: Root Locus Plot. Consider a general feedback control system with a variable gain K. Y ( s ) ( ) K

Quiz 1- Linear Regression Analysis (Based on Lectures 1-14)

Likewise, properties of the optimal policy for equipment replacement & maintenance problems can be used to reduce the computation.

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

1. a. Houston Chronicle, Des Moines Register, Chicago Tribune, Washington Post

Scheduling Jobs with a Common Due Date via Cooperative Game Theory

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

Simulation Output Analysis

Chapter 3 Sampling For Proportions and Percentages

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

Isolated Word Recogniser

1 Onto functions and bijections Applications to Counting

Mu Sequences/Series Solutions National Convention 2014

THE PUBLISHING HOUSE PROCEEDINGS OF THE ROMANIAN ACADEMY, Series A, OF THE ROMANIAN ACADEMY Volume 6, Number 1/2005, pp

Hamilton Cycles in Random Lifts of Graphs

MATH 247/Winter Notes on the adjoint and on normal operators.

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

Multivariate Transformation of Variables and Maximum Likelihood Estimation

Exercises for Square-Congruence Modulo n ver 11

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

Multiple Regression. More than 2 variables! Grade on Final. Multiple Regression 11/21/2012. Exam 2 Grades. Exam 2 Re-grades

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

Lebesgue Measure of Generalized Cantor Set

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

5 Short Proofs of Simplified Stirling s Approximation

Summary of the lecture in Biostatistics

The Mathematical Appendix

On the energy of complement of regular line graphs

Packing of graphs with small product of sizes

A conic cutting surface method for linear-quadraticsemidefinite

Lecture 02: Bounding tail distributions of a random variable

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

Third handout: On the Gini Index

(b) By independence, the probability that the string 1011 is received correctly is

The Occupancy and Coupon Collector problems

13.4 Scalar Kalman Filter

Laboratory I.10 It All Adds Up

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

Some distances and sequences in a weighted graph

Parameter, Statistic and Random Samples

The number of observed cases The number of parameters. ith case of the dichotomous dependent variable. the ith case of the jth parameter

Algorithms Theory, Solution for Assignment 2

Bayes (Naïve or not) Classifiers: Generative Approach

On a Truncated Erlang Queuing System. with Bulk Arrivals, Balking and Reneging

Solving Constrained Flow-Shop Scheduling. Problems with Three Machines

PPCP: The Proofs. 1 Notations and Assumptions. Maxim Likhachev Computer and Information Science University of Pennsylvania Philadelphia, PA 19104

To use adaptive cluster sampling we must first make some definitions of the sampling universe:

u t u 0 ( 7) Intuitively, the maximum principles can be explained by the following observation. Recall

The expected value of a sum of random variables,, is the sum of the expected values:

Lecture 1. (Part II) The number of ways of partitioning n distinct objects into k distinct groups containing n 1,

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

Unsupervised Learning and Other Neural Networks

9 U-STATISTICS. Eh =(m!) 1 Eh(X (1),..., X (m ) ) i.i.d

Chapter 4 (Part 1): Non-Parametric Classification (Sections ) Pattern Classification 4.3) Announcements

x z Increasing the size of the sample increases the power (reduces the probability of a Type II error) when the significance level remains fixed.

Section l h l Stem=Tens. 8l Leaf=Ones. 8h l 03. 9h 58

Statistical Inference Procedures

TI-83/84 Calculator Instructions for Math Elementary Statistics

L5 Polynomial / Spline Curves

Lecture 16: Backpropogation Algorithm Neural Networks with smooth activation functions

Lecture 25 Highlights Phys 402

MA/CSSE 473 Day 27. Dynamic programming

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

A New Method for Decision Making Based on Soft Matrix Theory

Statistics: Unlocking the Power of Data Lock 5

18.413: Error Correcting Codes Lab March 2, Lecture 8

Lecture 2 - What are component and system reliability and how it can be improved?

Lecture 07: Poles and Zeros

Lecture 3 Probability review (cont d)

r y Simple Linear Regression How To Study Relation Between Two Quantitative Variables? Scatter Plot Pearson s Sample Correlation Correlation

QR Factorization and Singular Value Decomposition COS 323

Non-uniform Turán-type problems

Computational Geometry

Data Structures and Algorithm. Xiaoqing Zheng

Ideal multigrades with trigonometric coefficients

SPECIAL CONSIDERATIONS FOR VOLUMETRIC Z-TEST FOR PROPORTIONS

Ahmed Elgamal. MDOF Systems & Modal Analysis

Lecture 9: Tolerant Testing

Regression. Chapter 11 Part 4. More than you ever wanted to know about how to interpret the computer printout

INEQUALITIES USING CONVEX COMBINATION CENTERS AND SET BARYCENTERS

LECTURE - 4 SIMPLE RANDOM SAMPLING DR. SHALABH DEPARTMENT OF MATHEMATICS AND STATISTICS INDIAN INSTITUTE OF TECHNOLOGY KANPUR

Transcription:

CS473-Algorthm I Lecture b Dyamc Table CS 473 Lecture X

Why Dyamc Table? I ome applcato: We do't kow how may object wll be tored a table. We may allocate pace for a table But, later we may fd out that t ot eough. The, the table mut be reallocated wth a larger ze. All the object tored the orgal table Mut be coped over to the ew table. CS 473 Lecture X

Why Dyamc Table? Smlarly, f may object are deleted from the table: t may be worthwhle to reallocate the table wth a maller ze. Th problem called Dyamcally Expadg ad Cotractg a table. CS 473 Lecture X 3

Why Dyamc Table? Ug amortzed aaly we wll how that, The amortzed cot of erto ad deleto O(). Eve though the actual cot of a operato large whe t trgger a expao or a cotracto. We wll alo how how to guaratee that The uued pace a dyamc table ever exceed a cotat fracto of the total pace. CS 473 Lecture X 4

Operato TABLE-INSERT: Iert to the table a tem that occupe a gle lot. TABLE-DELETE: Remove a tem from the table & free t lot. CS 473 Lecture X 5

Load Factor Load Factor of a Dyamc Table T ( T) Number of tem tored the table ze( umber of lot ) of the table For a empty table by defto 0 ( T) 0 CS 473 Lecture X 6

Ierto-Oly Dyamc Table Table-Expao: Aumpto: Table allocated a a array of lot A table fll up whe all lot have bee ued equvaletly, whe t load factor become Table-Expao occur whe A tem to be erted to a full table CS 473 Lecture X 7

Ierto-Oly Dyamc Table A Commo Heurtc Allocate a ew table that ha twce a may lot a the old oe. Hece, erto are performed f oly / α(t) CS 473 Lecture X 8

Table Iert TABLE-INSERT (T, x) f ze[t] = 0 the allocate table[t] wth lot ze[t] f um[t] = ze[t] the allocate ew-table wth.ze[t] lot copy all tem table[t] to ew-table free table[t] table[t] ew-table[t] ze[t].ze[t] ert x to table[t] um[t] um[t] + ed table[t] : poter to block of table torage um[t] : umber of tem the table ze[t] : total umber of lot the table Itally, table empty, o um[t] = ze[t] = 0 CS 473 Lecture X 9

Table Expao Rug tme of TABLE-INSERT proportoal to the umber of elemetary ert operato. Ag a cot of to each elemetary erto Aalyze a equece of TABLE-INSERT operato o a tally empty table CS 473 Lecture X 0

Cot of Table Expao What cot c of the -th operato? If there room the curret table (or th the frt operato) c = (oly oe elemetary ert operato) If the curret table full, a expao occur, the the cot c =. for the elemetary erto of the ew tem - for the tem that mut be coped from the old table to the ew table. CS 473 Lecture X

Cot of Table Expao If operato are performed, The wort cae cot of a operato O() Therefore the total rug tme O( ) Th boud ot tght, becaue Expao doe ot occur o ofte the coure of operato. CS 473 Lecture X

Amortzed Aaly of Iert Table tally empty. Oberve: The Aggregate Method -th operato caue a expao oly whe - a power of. c f a exact power of otherwe CS 473 Lecture X 3

The Aggregate Method Therefore the total cot of TABLE-INSERT operato lg lg j j c 3 j0 j0 3 4 5 6 7 8 9 0 3 4 5 6 7 8 9 0... c 3 5 9 7... Expao cot... 4 8 6 The amortzed cot of a gle operato 3/=3 = O() CS 473 Lecture X 4

The Accoutg Method Ag the followg amortzed cot Table-Expao : 0 Ierto of a ew tem : 3 Ierto of a ew tem a) (a a actual cot) for ertg telf to the table b) (a a credt) for movg telf the ext expao c) (a a credt) for movg aother tem ( the ext expao) that ha already moved the lat expao CS 473 Lecture X 5

Accoutg Method Example Sze of the table: M Immedately after a expao (jut before the erto) um[t] = M/ ad ze[t] = M where M a power of. Table cota o credt. 3 4 5 6 7 8 9 0 3 4 5 6 X X X X X X X X CS 473 Lecture X 6

Accoutg Method Example t erto 3 4 5 6 7 8 9 0 3 4 5 6 X X X X X X X X Z $ $ (c) d erto (b) (a) $ for erto 3 4 5 6 7 8 9 0 3 4 5 6 X X X X X X X X Z Z $ $ $ $ CS 473 Lecture X 7

Accoutg Method Example M/th Ierto 3 4 5 6 7 8 9 0 3 4 5 6 X X X X X X X X Z Z Z Z Z Z Z Z $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Thu, by the tme the table cota M tem ad full each tem the table ha $ of credt to pay for t move durg the ext expao CS 473 Lecture X 8

The Potetal Method Defe a potetal fucto Φ that 0 mmedately after a expao buld to the table ze by the tme table become full Next expao ca be pad for by the potetal. CS 473 Lecture X 9

Defto of Φ Oe poble Φ : Φ(T) = *um[t] ze[t] Immedately after a expao ze[t] = *um[t] Φ(T) = 0 Immedately before a expao ze[t] = um[t] Φ(T) = um[t] The tal value for the potetal 0 CS 473 Lecture X 0

Defto of Φ Sce the table at leat half full (.e. um[t] ze[t] / ) Φ(T) alway oegatve. Thu, the um of the amortzed cot of TABLE-INSERT operato a upper boud o the um of the actual cot. CS 473 Lecture X

Aaly of -th Table Iert : um[t] after the -th operato : ze[t] after the -th operato Φ : Potetal after the -th operato Itally we have = = Φ = 0 Note that, = - + alway hold. CS 473 Lecture X

CS 473 Lecture X 3 Iert wthout Expao If the -th TABLE-INSERT doe ot trgger a expao, = ; c = 3 ) ( ) ) (( ) ( ) ( ˆ c c

CS 473 Lecture X 4 Iert wth Expao If the -th TABLE-INSERT doe trgger a expao, the 3 ) ( ) ) (( ) ( ) ( ) ( ˆ ; ; c c c

CS 473 Lecture X 5

Addg Delete Operato TABLE-DELETE: Remove the pecfed tem from the table. It ofte derable to cotract the table. I table cotracto, we would lke to preerve two properte Load factor of dyamc table bouded below by a cotat Amortzed cot of a table operato bouded above by a cotat We aume that the cot ca be meaured term of elemetary erto ad deleto CS 473 Lecture X 6

Expao ad Cotracto A atural trategy for expao ad cotracto Double the table ze whe a tem erted to a full table Halve the ze whe a deleto would caue (T) < / Th trategy guaratee ( T) Ufortuately, t ca caue the amortzed cot of a operato to be qute large CS 473 Lecture X 7

Wort-Cae for α(t) ½ Coder the followg wort cae cearo We perform operato o a empty table where a power of Frt / operato are all erto, cot a total of Θ() at the ed: we have um[t] = ze[t] = / Secod / operato repeat the equece I D D I that I D D I I D D I I D D I... CS 473 Lecture X 8

Example: =6 Wort-Cae for α(t) ½ :... 7 8 9 0 3 4 5 6 oper: I I... I I I D D I I D D I... 7 8 9 8 7 8 9 8 7 8... 8 8 6 6 8 8 6 6 8 8 I the ecod / operato E C E C The frt INSERT caue a expao Two further DELETE caue cotracto Two further INSERT caue expao... ad o o Hece there are /8 expao ad /8 cotracto The cot of each expao ad cotracto / CS 473 Lecture X 9

Wort-Cae for α(t) ½ Thu the total cot of operato Θ( ) ce Frt / operato : 3 Secod / operato : (/4)*(/)= /8 The amortzed cot of a operato Θ() The dffculty wth th trategy After a expao, we do ot perform eough deleto to pay for a cotracto After a cotracto, we do ot perform eough erto to pay for a expao CS 473 Lecture X 30

Improvg Expao Cotracto We ca mprove upo th trategy by allowg α(t) to drop below ½ We cotue to double the table ze whe a tem erted to a full table But, we halve the table ze (perform cotracto) whe a deleto caue α(t) < ¼ rather tha α(t) < ½, Therefore, ¼ α(t) CS 473 Lecture X 3

Improvg Expao Cotracto Hece after a expao, α(t) = ½, thu at leat half of the tem the table mut be deleted before a cotracto ca occur. Smlarly, after a cotracto α(t) = ½, thu the umber of tem the table mut be doubled by erto before a expao ca occur. CS 473 Lecture X 3

Potetal Method Defe the potetal fucto a follow Φ(T) = 0 mmedately after a expao or cotracto Recall that, α(t) = ½ mmedately after ad expao or cotracto, therefore the potetal hould buld up to um[t] a α(t) creae to or decreae to ¼ So that the ext expao or cotracto ca be pad by the potetal. CS 473 Lecture X 33

Φ(α) w.r.t. α(t) M=um[T] whe a expao or cotracto occur CS 473 Lecture X 34

Decrpto of New Φ Oe uch Φ or ( T) ( T) um[ T] ze[ T] ze[t] um[ T] um[ T]( / ) um[ T](/ ) f (T) f (T) f (T) f (T) CS 473 Lecture X 35

Decrpto of New Φ Φ = 0 whe α = ½ Φ = um[t] whe α = ¼ Φ = 0 for a empty table (um[t] = ze[t]=0, α[t] = 0) Φ alway oegatve CS 473 Lecture X 36

Amortzed Aaly Operato are: TABLE-INSERT TABLE-DELETE c : : Actual Cot um[ T] cˆ : : AmortzedCot ze[ T] : : ( T) ( T) after the -th operato CS 473 Lecture X 37

Table Iert = - + - = Table cotracto may ot occur. α - ½ Aaly detcal to that for table expao Therefore, ĉ = 3 whether the table expad or ot. α - < ½ ad α < ½ Expao may ot occur (ĉ =, = - ) cˆ c (3 / ) ( / ) ( ) 0 CS 473 Lecture X 38

CS 473 Lecture X 39 Table Iert α - < ½ ad α ½ α = ½ Expao may ot occur (c = ; = - ; = / ) 3 / 3 / 3 3 3 / 3 3 3 / 3 3 ) ( / ) ( ) / ( ˆ c c Thu, amortzed cot of a TABLE-INSERT operato at mot 3.

CS 473 Lecture X 40 Table Delete = - - - = + Table expao may ot occur. α - ½ ad ¼ α < ½ (It doe ot trgger a cotracto) = - ad c = ad α < ½ ) ( / / ) / ( ) / ( ˆ c c

CS 473 Lecture X 4 Table Delete α - = ¼ (It doe trgger a cotracto) = - / ; = - /; ad c = + α - > ½ (α ½ ) Cotracto may ot occur (c = ; = - ) / / ) / ( ) / ( ) ( ˆ c c ) ( ) ( ) ( ˆ c c

CS 473 Lecture X 4 Table Delete α - = ½ (α < ½) Cotracto may ot occur c = ; = - ; = - /; ad Φ - =0) ) ( / but / 0 ) / ( ˆ c c

Table Delete Thu, the amortzed cot of a TABLE-DELETE operato at mot Sce the amortzed cot of each operato bouded above by a cotat The actual tme for ay equece of operato o a Dyamc Table O() CS 473 Lecture X 43