2-3-4 Trees and Red- Black Trees



Similar documents
In nite Sequences. Dr. Philippe B. Laval Kennesaw State University. October 9, 2008

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

Infinite Sequences and Series

Soving Recurrence Relations

Example 2 Find the square root of 0. The only square root of 0 is 0 (since 0 is not positive or negative, so those choices don t exist here).

CS103X: Discrete Structures Homework 4 Solutions

Lesson 15 ANOVA (analysis of variance)

LECTURE 13: Cross-validation

Z-TEST / Z-STATISTIC: used to test hypotheses about. µ when the population standard deviation is unknown

GCSE STATISTICS. 4) How to calculate the range: The difference between the biggest number and the smallest number.

Hypothesis testing. Null and alternative hypotheses

Department of Computer Science, University of Otago

THE ARITHMETIC OF INTEGERS. - multiplication, exponentiation, division, addition, and subtraction

Confidence Intervals for One Mean

Your organization has a Class B IP address of Before you implement subnetting, the Network ID and Host ID are divided as follows:

Repeating Decimals are decimal numbers that have number(s) after the decimal point that repeat in a pattern.

Incremental calculation of weighted mean and variance

ODBC. Getting Started With Sage Timberline Office ODBC

CS100: Introduction to Computer Science

Best of security and convenience

Asymptotic Growth of Functions

5 Boolean Decision Trees (February 11)

Determining the sample size

Engineering Data Management

Chapter 5: Inner Product Spaces

5: Introduction to Estimation

Properties of MLE: consistency, asymptotic normality. Fisher information.

BINOMIAL EXPANSIONS In this section. Some Examples. Obtaining the Coefficients

Section 11.3: The Integral Test

Lecture 2: Karger s Min Cut Algorithm

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Solving equations. Pre-test. Warm-up

Project Deliverables. CS 361, Lecture 28. Outline. Project Deliverables. Administrative. Project Comments

FIBONACCI NUMBERS: AN APPLICATION OF LINEAR ALGEBRA. 1. Powers of a matrix

1 Correlation and Regression Analysis

MARTINGALES AND A BASIC APPLICATION

How to use what you OWN to reduce what you OWE

.04. This means $1000 is multiplied by 1.02 five times, once for each of the remaining sixmonth

BaanERP. BaanERP Windows Client Installation Guide

CHAPTER 3 THE TIME VALUE OF MONEY

Lecture 3. denote the orthogonal complement of S k. Then. 1 x S k. n. 2 x T Ax = ( ) λ x. with x = 1, we have. i = λ k x 2 = λ k.

Chapter 14 Nonparametric Statistics

Basic Elements of Arithmetic Sequences and Series

Lecture 16: Address decoding

CHAPTER 7: Central Limit Theorem: CLT for Averages (Means)

Present Value Factor To bring one dollar in the future back to present, one uses the Present Value Factor (PVF): Concept 9: Present Value

Center, Spread, and Shape in Inference: Claims, Caveats, and Insights

Lecture 4: Cauchy sequences, Bolzano-Weierstrass, and the Squeeze theorem

Time Value of Money. First some technical stuff. HP10B II users

Lesson 17 Pearson s Correlation Coefficient

How to set up your GMC Online account

Sampling Distribution And Central Limit Theorem

1. MATHEMATICAL INDUCTION

Desktop Management. Desktop Management Tools

Chapter 7 Methods of Finding Estimators

Analyzing Longitudinal Data from Complex Surveys Using SUDAAN

1. C. The formula for the confidence interval for a population mean is: x t, which was

Analysis Notes (only a draft, and the first one!)

I. Chi-squared Distributions

Listing terms of a finite sequence List all of the terms of each finite sequence. a) a n n 2 for 1 n 5 1 b) a n for 1 n 4 n 2

NATIONAL SENIOR CERTIFICATE GRADE 12

Domain 1: Designing a SQL Server Instance and a Database Solution

A Combined Continuous/Binary Genetic Algorithm for Microstrip Antenna Design

1 Computing the Standard Deviation of Sample Means

where: T = number of years of cash flow in investment's life n = the year in which the cash flow X n i = IRR = the internal rate of return

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies ( 3.1.1) Limitations of Experiments. Pseudocode ( 3.1.2) Theoretical Analysis

5.4 Amortization. Question 1: How do you find the present value of an annuity? Question 2: How is a loan amortized?

OMG! Excessive Texting Tied to Risky Teen Behaviors

CS100: Introduction to Computer Science

THE REGRESSION MODEL IN MATRIX FORM. For simple linear regression, meaning one predictor, the model is. for i = 1, 2, 3,, n

Static revisited. Odds and ends. Static methods. Static methods 5/2/16. Some features of Java we haven t discussed

Simple Efficient Load Balancing Algorithms for Peer-to-Peer Systems

3. Greatest Common Divisor - Least Common Multiple

Class Meeting # 16: The Fourier Transform on R n

Derivation of Annuity and Perpetuity Formulae. A. Present Value of an Annuity (Deferred Payment or Ordinary Annuity)

Investigation of Atwood s machines as Series and Parallel networks

Time Value of Money, NPV and IRR equation solving with the TI-86

Queuing Systems: Lecture 1. Amedeo R. Odoni October 10, 2001

Bond Valuation I. What is a bond? Cash Flows of A Typical Bond. Bond Valuation. Coupon Rate and Current Yield. Cash Flows of A Typical Bond

SEQUENCES AND SERIES

Descriptive Statistics

Measures of Spread and Boxplots Discrete Math, Section 9.4

Topic 5: Confidence Intervals (Chapter 9)

Math C067 Sampling Distributions

CHAPTER 11 Financial mathematics

PROCEEDINGS OF THE YEREVAN STATE UNIVERSITY AN ALTERNATIVE MODEL FOR BONUS-MALUS SYSTEM

Chapter 6: Variance, the law of large numbers and the Monte-Carlo method

Ekkehart Schlicht: Economic Surplus and Derived Demand

Chapter 5 Unit 1. IET 350 Engineering Economics. Learning Objectives Chapter 5. Learning Objectives Unit 1. Annual Amount and Gradient Functions

Integer Factorization Algorithms

Sequences and Series

Annuities Under Random Rates of Interest II By Abraham Zaks. Technion I.I.T. Haifa ISRAEL and Haifa University Haifa ISRAEL.

CHAPTER 3 DIGITAL CODING OF SIGNALS

Definition. A variable X that takes on values X 1, X 2, X 3,...X k with respective frequencies f 1, f 2, f 3,...f k has mean

CS103A Handout 23 Winter 2002 February 22, 2002 Solving Recurrence Relations

I. Why is there a time value to money (TVM)?

Domain 1: Configuring Domain Name System (DNS) for Active Directory

Non-life insurance mathematics. Nils F. Haavardsson, University of Oslo and DNB Skadeforsikring

Week 3 Conditional probabilities, Bayes formula, WEEK 3 page 1 Expected value of a random variable

Notes on exponential generating functions and structures.

Transcription:

2-3-4 Trees ad ed- Black Trees erm 204

2-3-4 Trees evealed Nodes store 1, 2, or 3 keys ad have 2, 3, or 4 childre, respectively All leaves have the same depth k b e h r a c d f i l m p s x 1 -- lo( N + 1) heiht lo( N + 1) 2 erm 205

2-3-4 Tree Nodes Itroductio of odes with more tha 1 key, ad more tha 2 childre 2-ode: same as a biary ode <a >a a b 3-ode: 2 keys, 3 liks <a >b a >a <b 4-ode: 3 keys, 4 liks a b c <a >c >a <b >b <c erm 206

Why 2-3-4? Why ot miimize heiht by maximizi childre i a d-tree? Let each ode have d childre so that we et (lo d N) search time! iht? lo d N = lo N/lo d That meas if d = N 1/2, we et a heiht of 2 However, searchi out the correct child o each level requires (lo N 1/2 ) by biary search 2 lo N 1/2 = (lo N) which is ot as ood as we had hoped for! 2-3-4-trees will uaratee (lo N) heiht usi oly 2, 3, or 4 childre per ode erm 207

Isertio ito 2-3-4 Trees Isert the ew key at the lowest iteral ode reached i the search 2-ode becomes 3-ode d d 3-ode becomes 4-ode f d d f What about a 4-ode? We ca t isert aother key! erm 208

Top ow Isertio I our way dow the tree, wheever we reach a 4-ode, we break it up ito two 2- odes, ad move the middle elemet up ito the paret ode e e f d f d Now we ca perform the isertio usi oe of the previous two cases ice we follow this method from the root dow to the leaf, it is called top dow isertio d e f erm 209

plitti the Tree As we travel dow the tree, if we ecouter ay 4-ode we will break it up ito 2-odes. This uaratees that we will ever have the problem of iserti the middle elemet of a former 4- ode ito its paret 4-ode. c t a f i l p r x Whoa, cowboy c t a f i l p r x erm 210

c t a f i l p r x c t Whoa, cowboy a f i l p r x erm 211

c t a f i l p r x Whoa, cowboy c i t a f l p r x c i t a f l p r x erm 212

Time omplexity of Isertio i 2-3-4 Trees Time complexity: A search visits (lo N) odes A isertio requires (lo N) ode splits ach ode split takes costat time Hece, operatios earch ad Isert each take time (lo N) Notes: Istead of doi splits top-dow, we ca perform them bottom-up starti at the isertio ode, ad oly whe eeded. This is called bottom-up isertio. A deletio ca be performed by fusi odes (iverse of splitti), ad takes (lo N) time erm 213

Beyod 2-3-4 Trees What do we kow about 2-3-4 Trees? Balaced iskel (lo N) search time bert ifferet ode structures oberto a we et 2-3-4 tree advataes i a biary tree format??? Welcome to the world of ed-black Trees!!! erm 214

ed-black Tree A red-black tree is a biary search tree with the followi properties: edes are colored red or black o two cosecutive red edes o ay root-leaf path same umber of black edes o ay root-leaf path (= black heiht of the tree) edes coecti leaves are black Black de ed de erm 215

2-3-4 Tree volutio Note how 2-3-4 trees relate to red-black trees 2-3-4 ed-black or Now we see red-black trees are just a way of represeti 2-3-4 trees! erm 216

More ed-black Tree Properties N # of iteral odes L # leaves (= N + 1) H heiht B black heiht Property 1: 2 B N + 1 4 B Property 2: Property 3: 1 -- lo( N+ 1) B lo( N + 1) 2 lo( N + 1) H 2 lo( N + 1) This implies that searches take time (lon)! erm 217

Isertio ito ed-black Trees 1.Perform a stadard search to fid the leaf where the key should be added 2.eplace the leaf with a iteral ode with the ew key 3.olor the icomi ede of the ew ode red 4.Add two ew leaves, ad color their icomi edes black 5.If the paret had a icomi red ede, we ow have two cosecutive red edes! We must reoraize tree to remove that violatio. What must be doe depeds o the sibli of the paret. G G erm 218

Isertio - Plai ad imple Let: be the ew ode p be its paret be its radparet ase 1: Icomi ede of p is black No violatio p TP! Pretty easy, huh? Well... it ets messier... erm 219

estructuri ase 2: Icomi ede of p is red, ad its sibli is black Uh oh! p Much Better! p We call this a riht rotatio No further work o tree is ecessary Iorder remais uchaed Tree becomes more balaced No two cosecutive red edes! erm 220

More otatios imilar to a riht rotatio, we ca do a left rotatio... p p imple, huh? erm 221

ouble otatios What if the ew ode is betwee its paret ad radparet i the iorder sequece? We must perform a double rotatio (which is o more difficult tha a sile oe) p p This would be called a left-riht double rotatio erm 222

Last of the otatios Ad this would be called a riht-left double rotatio p p erm 223

Bottom-Up ebalaci ase 3: Icomi ede of p is red ad its sibli is also red p p We call this a promotio Note how the black depth remais uchaed for all of the descedats of This process will cotiue upward beyod if ecessary: reame as ad repeat. erm 224

ummary of Isertio Iftwo red edes are preset, we do either a restructuri (with a simple or double rotatio) ad stop, or apromotio ad cotiue Arestructuri takes costat time ad is performed at most oce. It reoraizes a off-balaced sectio of the tree. Promotios may cotiue up the tree ad are executed (lo N) times. The time complexity of a isertio is (lon). erm 225

A xample tart by iserti ito a empty tree Now, let s isert U B... erm 226

A ool xample erm 227

A Ubelievable xample U h No! What should we do? U erm 228

ouble otatio U U erm 229

B A Beautiful xample U What ow? U B erm 230

otatio U B B U erm 231

A uper xample B U B U Holy osecutive ed des, Batma! We could ve placed it o either side erm 232

B U Use the Bat-Promoter!! BIFF! B U erm 233

otatio B U The UN lab ad ed-bat trees are safe......for ow!!! U B erm 234