CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 259] B-Trees

Similar documents
Final Exam : Solutions

Lecture 1: Numerical Integration The Trapezoidal and Simpson s Rule

Ma/CS 6a Class 15: Flows and Bipartite Graphs

On the Derivatives of Bessel and Modified Bessel Functions with Respect to the Order and the Argument

4.1 The Uniform Distribution Def n: A c.r.v. X has a continuous uniform distribution on [a, b] when its pdf is = 1 a x b

CSE 245: Computer Aided Circuit Simulation and Verification

Let s look again at the first order linear differential equation we are attempting to solve, in its standard form:

Homework #2: CMPT-379 Distributed on Oct 2; due on Oct 16 Anoop Sarkar

priority queue ADT heaps 1

UNIT #5 EXPONENTIAL AND LOGARITHMIC FUNCTIONS

The transition:transversion rate ratio vs. the T-ratio.

Microscopic Flow Characteristics Time Headway - Distribution

DEPARTMENT OF ELECTRICAL &ELECTRONICS ENGINEERING SIGNALS AND SYSTEMS. Assoc. Prof. Dr. Burak Kelleci. Spring 2018

Lecture 4: Laplace Transforms

Integrity Control in Nested Certificates

Voltage v(z) ~ E(z)D. We can actually get to this wave behavior by using circuit theory, w/o going into details of the EM fields!

Continous system: differential equations

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

MEM 355 Performance Enhancement of Dynamical Systems A First Control Problem - Cruise Control

The Variance-Covariance Matrix

cycle that does not cross any edges (including its own), then it has at least

Poisson process Markov process

Applied Statistics and Probability for Engineers, 6 th edition October 17, 2016

Spring 2006 Process Dynamics, Operations, and Control Lesson 2: Mathematics Review

SOLUTIONS. 1. Consider two continuous random variables X and Y with joint p.d.f. f ( x, y ) = = = 15. Stepanov Dalpiaz

Elementary Differential Equations and Boundary Value Problems

10. If p and q are the lengths of the perpendiculars from the origin on the tangent and the normal to the curve

Discussion 06 Solutions

4. Which of the following organs develops first?

Boyce/DiPrima 9 th ed, Ch 2.1: Linear Equations; Method of Integrating Factors

GUIDE FOR SUPERVISORS 1. This event runs most efficiently with two to four extra volunteers to help proctor students and grade the student

Transfer function and the Laplace transformation

5. An object moving along an x-coordinate axis with its scale measured in meters has a velocity of 6t

1. Inverse Matrix 4[(3 7) (02)] 1[(0 7) (3 2)] Recall that the inverse of A is equal to:

Chapter 12 Introduction To The Laplace Transform

Midterm exam 2, April 7, 2009 (solutions)

Midterm Examination (100 pts)

EE 434 Lecture 22. Bipolar Device Models

An Indian Journal FULL PAPER. Trade Science Inc. A stage-structured model of a single-species with density-dependent and birth pulses ABSTRACT

Institute of Actuaries of India

Mundell-Fleming I: Setup

3+<6,&6([DP. September 29, SID (last 5 digits): --

LaPlace Transform in Circuit Analysis

Routing in Delay Tolerant Networks

= x. I (x,y ) Example: Translation. Operations depend on pixel s Coordinates. Context free. Independent of pixel values. I(x,y) Forward mapping:

Economics 302 (Sec. 001) Intermediate Macroeconomic Theory and Policy (Spring 2011) 3/28/2012. UW Madison

CHAPTER CHAPTER14. Expectations: The Basic Tools. Prepared by: Fernando Quijano and Yvonn Quijano

Wave Equation (2 Week)

Boyce/DiPrima 9 th ed, Ch 7.8: Repeated Eigenvalues

14.02 Principles of Macroeconomics Problem Set 5 Fall 2005

EXERCISE - 01 CHECK YOUR GRASP

symmetric/hermitian matrices, and similarity transformations

Chemistry 988 Part 1

7.4 QUANTUM MECHANICAL TREATMENT OF FLUCTUATIONS *

C From Faraday's Law, the induced voltage is, C The effect of electromagnetic induction in the coil itself is called selfinduction.

General Article Application of differential equation in L-R and C-R circuit analysis by classical method. Abstract

Circuits and Systems I

Study on the Lightweight checkpoint based rollback recovery mechanism

AR(1) Process. The first-order autoregressive process, AR(1) is. where e t is WN(0, σ 2 )

Chapter 3: Fourier Representation of Signals and LTI Systems. Chih-Wei Liu

The Procedure Abstraction Part II: Symbol Tables and Activation Records

14.02 Principles of Macroeconomics Fall 2005 Quiz 3 Solutions

2.1. Differential Equations and Solutions #3, 4, 17, 20, 24, 35

Jonathan Turner Exam 2-10/28/03

Phys463.nb Conductivity. Another equivalent definition of the Fermi velocity is

Advanced Queueing Theory. M/G/1 Queueing Systems

Spring Ammar Abu-Hudrouss Islamic University Gaza

4.3 Design of Sections for Flexure (Part II)

1 Finite Automata and Regular Expressions

Consider a system of 2 simultaneous first order linear equations

Chapter 5 The Laplace Transform. x(t) input y(t) output Dynamic System

Longest Common Prefixes

Decline Curves. Exponential decline (constant fractional decline) Harmonic decline, and Hyperbolic decline.

On General Solutions of First-Order Nonlinear Matrix and Scalar Ordinary Differential Equations

H is equal to the surface current J S

Lecture 2: Current in RC circuit D.K.Pandey

23.5. Half-Range Series. Introduction. Prerequisites. Learning Outcomes

Review Lecture 5. The source-free R-C/R-L circuit Step response of an RC/RL circuit. The time constant = RC The final capacitor voltage v( )

Math 3301 Homework Set 6 Solutions 10 Points. = +. The guess for the particular P ( ) ( ) ( ) ( ) ( ) ( ) ( ) cos 2 t : 4D= 2

3(8 ) (8 x x ) 3x x (8 )

Mixing time with Coupling

First Lecture of Machine Learning. Hung-yi Lee

Random Access Techniques: ALOHA (cont.)

u x v x dx u x v x v x u x dx d u x v x u x v x dx u x v x dx Integration by Parts Formula

1 Recursive Descent (LL(1) grammars)

FIRST-ORDER SYSTEMS OF ORDINARY DIFFERENTIAL EQUATIONS I: Introduction and Linear Systems

Chapter 2 The Derivative Business Calculus 99

B) 25y e. 5. Find the second partial f. 6. Find the second partials (including the mixed partials) of

On the Speed of Heat Wave. Mihály Makai

ANSWERS TO EVEN NUMBERED EXERCISES IN CHAPTER 11

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Combinatorial Networks Week 1, March 11-12

Section 4.4 Logarithmic Properties

Jonathan Turner Exam 2-12/4/03

Charging of capacitor through inductor and resistor

Math 2142 Exam 1 Review Problems. x 2 + f (0) 3! for the 3rd Taylor polynomial at x = 0. To calculate the various quantities:

Chapter 2. First Order Scalar Equations

Part B: Transform Methods. Professor E. Ambikairajah UNSW, Australia

That is, we start with a general matrix: And end with a simpler matrix:

whereby we can express the phase by any one of the formulas cos ( 3 whereby we can express the phase by any one of the formulas

Transcription:

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 259] B-Trs Th AVL r and rd-black r allowd som variaion in h lnghs of h diffrn roo-o-laf pahs. An alrnaiv ida is o mak sur ha all roo-o-laf pahs hav xacly h sam lngh and allow variaion in h numbr of childrn. Th dfiniion of a B-r uss a paramr m: æ vry laf has h sam dph æ h roo has a mos m childrn æ vry non-roo nod has from m=2 o m childrn Kys ar placd ino nods lik his: æ Each non-laf nod has on fwr kys han i has childrn. Each ky is bwn wo child poinrs. æ Each laf nod has bwn m=2,1 and m,1 kys in i (unlss i is also h roo, in which cas i has bwn 1 and m, 1 kys in i). æ Th kys wihin a nod ar lisd in incrasing ordr.

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 260] B-Trs (con d) And w rquir h xndd sarch r propry: æ For ach nod x, h i-h ky in x is largr han all h kys in x s i-h subr and is smallr han all h kys in x s èi +1è-s subr 13 4 8 17 20 24 2 3 6 7 10 11 12 14 16 18 19 22 23 25 26 B-rs ar xnsivly usd in h ral world, for insanc, daabas applicaions. In pracic, m is vry larg (such as 512 or 1024). Thorm: Th dph of a B-r r is Oèlog nè. Insr and dl algorihms ar qui involvd.

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 261] Tris In h prvious sarch rs, ach ky is indpndn of h ohr kys in h r, xcp for hir rlaiv posiions. For som kinds of kys, on ky migh b a prfix of anohr r. For xampl, if h kys ar srings, hn h ky a is a prfix of h ky alas. Th nx kind of r aks advanag of prfix rlaionships bwn kys o sor hm mor fficinly. A ri is a (no ncssarily binary) r in which æ ach nod corrsponds o a prfix of a ky, and æ prfix for ach nod xnds prfix of is parn. Th ri soring a, al, an, bd, b, b : a b l n d

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 262] Insring ino a Tri To insr ino a ri: insr(x,s): // x is nod, s is sring o insr ------------ if lngh(s) = 0 hn mark x as holding a compl ky ls c := firs characr in s if no ougoing dg from x is labld wih c hn cra a nw child nod of x labl h dg o h nw child nod wih c pu h dg in h corrc sord ordr among all of x s ougoing dgs ndif x := child of x rachd by dg labld c s := rsul of rmoving firs characr from s insr(x,s) ndif Sar h rcursion wih h roo. To insr an and bp : a b l n d

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 263] Sarching in a Tri To sarch in a ri: sarch(x,s): // x is nod, s is sring o sarch for ------------ if lngh(s) = 0 hn if x holds a compl ky hn rurn x ls rurn null // s is no in h ri ls c := firs characr in s if no ougoing dg from x is labld wih c hn rurn null // s is no in h ri ls x := child of x rachd by dg labld c s := rsul of rmoving firs characr from s sarch(x,s) ndif ndif Sar h rcursion wih h roo. To sarch for ar and b : a b l n d

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 264] Hash Tabl Implmnaion of Dicionary ADT Anohr implmnaion of h Dicionary ADT is a hash abl. Hash abls suppor h opraions æ insr an lmn æ dl an arbirary lmn æ sarch for a paricular lmn wih consan avrag im prformanc. This is a significan advanag ovr vn balancd sarch rs, which hav avrag ims of Oèlog nè. Th disadvanag of hash abls is ha h opraions min, max, prd, succ ak Oènè im; and prining all lmns in sord ordr aks Oèn log nè im.

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 265] Main Ida of Hash Tabl Main ida: xploi random accss faur of arrays: h i-h nry of array A can b accssd in consan im, by calculaing h addrss of A[i], which is offs from h saring addrss of A. Simpl xampl: Suppos all kys ar in h rang 0 o 99. Thn sor lmns in an array A wih 100 nris. Iniializ all nris o som mpy indicaor. æ To insr x wih ky k: A[k] := x. æ To sarch for ky k: chck if A[k] is mpy. æ To dl lmn wih ky k: A[k] := mpy. All ims ar Oè1è. 0 1 2 99 x0 x2... x99 ky is 0 ky is 2 Bu his ida dos no scal wll. ky is 99

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 266] Hash Funcions Suppos æ lmns ar sudn rcords æ school has 40,000 sudns, æ kys ar social scuriy numbrs (000-00-0000). Sinc hr ar 1 billion possibl SSN s, w nd an array of lngh 1 billion. And mos of i will b wasd, sinc only 40,000/1,000,000,000 = 1/25,000 fracion is nonmpy. Insad, w nd a way o condns h kys ino a smallr rang. L M b h siz of h array w ar willing o provid. Us a hash funcion, h, o convr ach ky o an array indx. Thn h maps ky valus o ingrs in h rang 0oM, 1.

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 267] Simpl Hash Funcion Exampl Suppos kys ar ingrs. L h hash funcion b hèkè = k mod M. Noic ha his always givs you somhing in h rang 0 o M, 1 (an array indx). æ To insr x wih ky k: Aëhèkèë := x æ To sarch for lmn wih ky k: chck if Aëhèkèë is mpy æ To dl lmn wih ky k: saëhèkèë o mpy. All ims ar Oè1è, assuming h hash funcion can b compud in consan im. 0 1 2 99 x... ky is k and h(k) = 2 Th ky o making his work is o choos hash funcion h and abl siz M proprly (hy inrac).

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 268] Collisions In raliy, any hash funcion will hav collisions: whn wo diffrn kys hash o h sam valu: hèk 1 è=hèk 2 è, alhough k 1 6= k 2. This is inviabl, sinc h hash funcion is squashing down a larg domain ino a small rang. For xampl, if hèkè = k mod M, hn k 1 = 0 and k 2 = M collid sinc hy boh hash o 0 (0 modmis 0, and M mod M is also 0). Wha should you do whn you hav a collision? Two common soluions ar 1. chaining, and 2. opn addrssing

CPSC 211 Daa Srucurs & Implmnaions (c) Txas A&M Univrsiy [ 269] Chaining Kp all daa ims ha hash o h sam array locaion in a linkd lis: 0 1 2. all hav kys ha hash o 1 M-1 æ o insr lmn x wih ky k: of linkd lis a Aëhèkèë pu x a bginning æ o sarch for lmn wih ky k: scan h linkd lis a Aëhèkèë for an lmn wih ky k æ o dl lmn wih ky k: do sarch, if sarch is succssful hn rmov lmn from h linkd lis Wors cas ims, assuming compuing h is consan: æ insr: Oè1è. æ sarch and dl: Oènè. Wors cas is if all n lmns hash o sam locaion.