tr0 TREES Hanan Samet

Similar documents
tr0 TREES Hanan Samet

Tree. Tree. Siblings Grand Parent Grand Child H I J I J K. Tree Definitions

Depth-first search and strong connectivity in Coq

Noncrossing Trees and Noncrossing Graphs

Red-Black Trees Goodrich, Tamassia Red-Black Trees 1

10 Torque. Lab. What You Need To Know: Physics 211 Lab

arxiv:cs/ v1 [cs.ds] 8 Dec 1998

CS3350B Computer Architecture. Lecture 6.2: Instructional Level Parallelism: Hazards and Resolutions

Lecture Topics. Overview ECE 486/586. Computer Architecture. Lecture # 9. Processor Organization. Basic Processor Hardware Pipelining

Multi-Robot Forest Coverage

ABriefIntroductiontotheBasicsof Game Theory

The Solution to the Bühlmann - Straub Model in the case of a Homogeneous Credibility Estimators

Multi-Robot Flooding Algorithm for the Exploration of Unknown Indoor Environments

Complexity of Data Tree Patterns over XML Documents

Design Engineering Challenge: The Big Dig Contest Platter Strategies: Ball Liberation

Torque. Physics 2. Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB

Faster Nearest Neighbors: Voronoi Diagrams and k-d Trees

CORESTA RECOMMENDED METHOD N 68

Fundamental Algorithms for System Modeling, Analysis, and Optimization

British Prime Minister Benjamin Disraeli once remarked that

Rearranging trees for robust consensus

The Properties of. Model Rocket Body Tube Transitions

The Study About Stopping Distance of Vehicles

55CM ROUND CHARCOAL KETTLE BBQ

Efficient Algorithms for finding a Trunk on a Tree Network and its Applications

Multiple Vehicle Driving Control for Traffic Flow Efficiency

f i r e - p a r t s. c o m

Trees & Routing (1) BFS

Data Sheet. Linear bearings

A Force Platform Free Gait Analysis

Cyclostrophic Balance in Surface Gravity Waves: Essay on Coriolis Effects

POSSIBLE AND REAL POWERFLOWS IN CONNECTED DIFFERENTIAL GEAR DRIVES WITH η 0 <i pq <1/η 0 INNER RATIO

Lesson 33: Horizontal & Vertical Circular Problems

EC-FRM: An Erasure Coding Framework to Speed up Reads for Erasure Coded Cloud Storage Systems

An integrated supply chain design model with random disruptions consideration

Cluster trees and message propagation

I. FORMULATION. Here, p i is the pressure in the bubble, assumed spatially uniform,

Interior Rule of the Quebec Open 2017

Incorporating Location, Routing and Inventory Decisions in Dual Sales Channel - A Hybrid Genetic Approach

SHRiMP: Accurate Mapping of Short Color-space Reads

Color Encodings: srgb and Beyond

Motivation. Prize-Collecting Steiner Tree Problem (PCSTP) Kosten und Profite. Das Fraktionale Prize-Collecting Steiner Tree Problem auf Baumgraphen

Operating Instructions Compressors

Trends in Cycling, Walking & Injury Rates in New Zealand

Wind and extremely long bridges a challenge for computer aided design

Overlap-Based Genome Assembly from Variable-Length Reads

CS 173: Discrete Structures, Spring 2010 Homework 9 Solutions

Session 6. Global Imbalances. Growth. Macroeconomics in the Global Economy. Saving and Investment: The World Economy

MODEL 1000S DIGITAL TANK GAUGE

DETC A NEW MODEL FOR WIND FARM LAYOUT OPTIMIZATION WITH LANDOWNER DECISIONS

An Auction Based Mechanism for On-Demand Transport Services

PlacesForBikes City Ratings Methodology. Overall City Rating

Design and Simulation Model for Compensated and Optimized T-junctions in Microstrip Line

RESOLUTION No A RESOLUTION OF THE CITY OF SALISBURY, MARYLAND AUTHORIZING THE MAYOR TO ENTER INTO AN AGREEMENT BETWEEN THE CITY OF

A CONCEPTUAL WHEELED ROBOT FOR IN-PIPE INSPECTION Ioan Doroftei, Mihaita Horodinca, Emmanuel Mignon

THE performance disparity between processor speed and the

MODELLING THE INTERACTION EFFECTS OF THE HIGH-SPEED TRAIN TRACK BRIDGE SYSTEM USING ADINA

Accel. (m/s 2 ) Time (sec) Newton s 3 rd Law and Circular Motion. Group Problem 04

Diana Krall Straighten Up And Fly Right SONG TITLE: STRAIGHTEN UP AND FLY RIGHT ALBUM: STEPPING OUT RELEASED: 1993 LABEL: JUSTIN TIME GENRE: JAZZ

Numerical study of super-critical carbon dioxide flow in steppedstaggered

ECE 697B (667) Spring 2003

OPTIMAL SCHEDULING MODELS FOR FERRY COMPANIES UNDER ALLIANCES

Matlab Simulink Implementation of Switched Reluctance Motor with Direct Torque Control Technique

"A Home for Gracious Living" (real estate brochure for Batten House)

TLV493D-A1B6 3D Magnetic Sensor

Phase Behavior Introduction to Phase Behavior F.E. Londono M.S. Thesis (2001)

STUDY OF IRREGULAR WAVE-CURRENT-MUD INTERACTION

A Deceleration Control Method of Automobile for Collision Avoidance based on Driver's Perceptual Risk

Experiment #10 Bio-Physics Pre-lab Questions

Alternate stable states in coupled fishery-aquaculture systems. Melissa Orobko

EcoMobility World Festival 2013 Suwon: an analysis of changes in citizens awareness and satisfaction

Carnegie Mellon University Forbes Ave., Pittsburgh, PA command as a point on the road and pans the camera in

Bubble clustering and trapping in large vortices. Part 1: Triggered bubbly jets investigated by phase-averaging

DAM SITE 2017 STAGE 1

Watford Half Marathon. Watford Half Marathon. Sunday February 4th Starting at 10.30am. Enjoy Your Run!!! Notice to all Entrants.

Electrical Equipment of Machine Tools

Example. The information set is represented by the dashed line.

ANALYSIS AND TESTING OF AN INTEGRATED REFRIGERATION AND STORAGE SYSTEM FOR LIQUID HYDROGEN ZERO BOIL-OFF, LIQUEFACTION, AND DENSIFICATION

Fire-Safety Analysis Timber. FRILO Software GmbH As of 29/06/2016

Watford Half Marathon. Watford Half Marathon. Sunday February 5th Starting at 10.30am. Enjoy Your Run!!! Notice to all Entrants.

ELDORADO 2017 STAGE 1 - DRUNK & LOUD

THE IMPACTS OF CONGESTION ON COMMERCIAL VEHICLE TOUR CHARACTERISTICS AND COSTS

Complexity of Data Tree Patterns over XML Documents

The Dockline AUGUST Board of Directors. Greetings from the Commodore. Jim Manlick

Lecture 24. Wind Lidar (6) Direct Motion Detection Lidar

Performance Characteristics of Parabolic Trough Solar Collector System for Hot Water Generation

College Hill Carthage. Winton Hills. Mill Creek. Spring Grove Village Paddock Hills. North Avondale. Avondale. Evanston. CUF Walnut Hills.

High Axial Load Capacity, High speed, Long life. Spherical Roller Bearings

Range Extension Control System for Electric Vehicles Based on Front and Rear Driving Force Distribution Considering Load Transfer

Project Proposal: Characterization of Tree Crown Attributes with High Resolution Fixed-Base Aerial Photography. by Rich Grotefendt and Rob Harrison

TECHNIQUE. Parental generation (P) Stamens Carpel 3. RESULTS First filial. offspring (F 1 )

A Collision Risk-Based Ship Domain Method Approach to Model the Virtual Force Field

OUTDOOR FOOTBALL FIELD

CLASS: XI: MATHEMATICS

DECO THEORY - BUBBLE MODELS

0ur Ref:CL/Mech/ Cal /BID-01(11-12) Date: 29 July 2011

Installation and Operation Instructions

Fault tolerant oxygen control of a diesel engine air system

Cheat-Proof Playout for Centralized and Distributed Online Games

Rotor Design and Analysis of Stall-regulated Horizontal Axis Wind Turbine

Transcription:

t0 TRS Hanan Samet ompute Science epatment and ente fo utomation Reseach and Institute fo dvanced ompute Studies Univesity of Mayland ollege Pak, Mayland 074 e-mail: hjs@umiacs.umd.edu opyight 1997 Hanan Samet These notes may not e epoduced y any means (mechanical o electonic o any othe) without the expess witten pemission of Hanan Samet

TR INITION t1 TR a anching stuctue etween nodes finite set T of one o moe nodes such that: 1. one element of the set is distinguished, ROOT(T). the emaining nodes of T ae patitioned into m 0 disjoint sets T 1, T, T m and each of these sets is in tun a tee. tees T 1, T, T ae the sutees of the oot Recusive definition easy to pove theoems aout popeties of tees. x: pove tue fo 1 node assume tue fo n nodes pove tue fo n+1 nodes ORR TR if the elative ode of the sutees T 1, T, T is impotant ORINT TR ode is not impotant m m odeed? = ompute epesentation odeed! opyight 1998 y Hanan Samet

TRMINOLOGY 1 t level 0 ounteintuitive! G level 1 level level 3 GR nume of sutees of a node Teminal node leaf degee 0 RNH NO non-teminal node Root is the fathe of the oots of its sutees Roots of sutees of a node ae othes Roots of sutees of a node ae sons of the node The oot of the tee has no fathe! is an ancesto of,, G, G is a descendant of level(x) if fathe(x)=ω then 0 else 1+level(fathe(X)); x: level(g) = 1+level() 1+level() 1+level() 0 opyight 1998 y Hanan Samet

ORSTS N INRY TRS 3 z 81 t3 ORST a set (usually odeed) of 0 o moe disjoint tees, o equivalently: the nodes of a tee excluding the oot has the foest INRY TR a finite set of nodes which eithe is empty o a oot and two disjoint inay tees called the left and ight sutees of the oot Is a inay tee a special case of a tee? NO! n entiely diffeent concept 1 and 1 has an empty ight sutee has an empty left sutee ut as tees 1 and ae identical! ae diffeent inay tees opyight 1998 y Hanan Samet

OTHR RPRSNTTIONS O TRS t4 Nested sets (also known as ule diagams ) G G Nested paentheses Tee (oot sutee 1 sutee... sutee n ) ( ( () ()) (G ( ()))) inay tee Indentation G (oot left ight) ( ( ( () ()) ( () ())) (G ( ( () ()) ()) ())) ewey decimal notation:.1...3.4.5 opyight 1998 y Hanan Samet

t5 PPLITIONS Segmentation of lage ectangula aays [n,m] each ow is a segment (uoughs computes) [1] [] [n] [1,1] [1,] [1,m] [n,1] [n,] [n,m] lgeaic fomulas opeato opeand opeand +(( ) ) + 1. no need fo paentheses ut + = ( )+ (+). code geneation LW 1, LW, W, MW, W,1 opyight 1998 y Hanan Samet

LISTs (with a capital L!) t6 LIST a finite sequence of 0 o moe atoms o LISTS L=(,(,,),(),,((()))) () empty list Index notation: L[]=(,,) L[,1]= L[5,] L[5,1,1] iffeences etween LISTS and tees: 1. no data appeas in the nodes epesenting LISTS - i.e.,. LISTS may e ecusive M=(M) [M] Lael [M] 3. LISTS may ovelap (i.e., need not e disjoint) equivalently, sutees may e shaed N=(M,M,,N) [N] [M] [M] [N] [M] opyight 1998 y Hanan Samet

TRVRSING INRY TRS t7 Repesentation LLINK INO RLINK Ω Ω Ω Ω Ω Ω Ω pplications: 1. code geneation in compiles. game tees in atificial intelligence 3. detect if a stuctue is eally a tee TR one path fom each node to anothe node (unlike gaph) no cycles and opyight 1998 y Hanan Samet

TRVRSL ORRS 1. Peode oot, left sutee, ight sutee depth-fist seach. Inode left sutee, oot, ight sutee inay seach tee 3. Postode left sutee, ight sutee, oot code geneation 4 g 3 z 81 t8 inay seach tee: left < oot < ight 30 15 45 10 0 inode yields 10 15 0 30 45 x: peode = I K G H J I K G H J inode = postode = I K G H J I K G H J Inode tavesal equies a stack to go ack up the tee: opyight 1998 y Hanan Samet

INORR TRVRSL LGORITHM t9 pocedue inode(tee pointe T); egin stack ; tee pointe P; Ω; P T; while not(p=ω and =Ω) do egin if P=Ω then egin P ; /* Pop the stack */ visit(root(p)); P RLINK(P); end else egin P; /* Push on the stack */ P LLINK(P); end; end; end; Using ecusion: pocedue inode(tee pointe T); egin if T=Ω then etun else egin inode(llink(t)); visit(root(t)); inode(rlink(t)); end; end; opyight 1998 y Hanan Samet

THR INRY TRS 3 z 81 t10 inay tee epesentation has too many Ω links Use 1-it tag fields to indicate pesence of a link If Ω link, then use field to stoe links to othe pats of the stuctue to aid the tavesal of the tee Untheaded: Theaded: LLINK(p) = Ω LTG(p) = 0, LLINK(p) = $p = inode pedecesso of p LLINK(p) = q Ω LTG(p) = 1, LLINK(p) = q RLINK(p) = Ω RTG(p) = 0, RLINK(p) = p$ = inode successo of p RLINK(p) = q Ω RTG(p) = 1, RLINK(p) = q LLINK LTG INO RTG RLINK x: H G H J If addess of ROOT(T) < addess of left and ight sons, then don'tneed the TG fields Theads will point to lowe addesses! opyight 1998 y Hanan Samet

OPRTIONS ON THR INRY TRS 6 5 v 4 g 3 z 81 t11 ind the inode successo of node P (P$) 1. Q RLINK(P); /* ight thead points to P$ */. if RTG(P)=1 then egin /* not a thead */ while LTG(Q)=1 do Q LLINK(Q); end; Inset node Q as the ight sutee of node P P P Q Q 1. RLINK(Q) RLINK(P); RTG(Q) RTG(P); RLINK(P) Q; LLINK(Q) P; RTG(P) 1; LTG(Q) 0;. if RTG(Q)=1 then LLINK(Q$) Q; opyight 1998 y Hanan Samet

SUMMRY O THRING t1 1. dvantages no need fo a stack fo tavesal will not un out of memoy duing inode tavesal can find inode successo of any node without having to tavese the entie tee. isadvantages insetion and deletion of nodes is slowe can t shae common sutees in the theaded epesentation x: two choices fo the inode successo of G? G 3. Right-theaded tees inode algoithms make little use of left theads LTG(P)=1 test can e eplaced y LLINK(P)=Ω test opyight 1998 y Hanan Samet

PRINIPLS O RURSION 5 v 4 g 3 z 81 t13 Two inay tees T1 and T ae said to e simila if they have the same shape o stuctue omally: 1. they ae oth empty o?. they ae oth non-empty and thei left and ight sutees espectively ae simila simila(t 1,T ) = if empty(t 1 ) and empty(t ) then T else if empty(t 1 ) o empty(t ) then else simila(left(t 1 ),left(t )) and simila(ight(t 1 ),ight(t )); Will simila wok? No! ase case does not handle case when one of the tees is empty and the othe one is not Simplifying: and = if then o = else if then T else simila(t 1,T ) = if empty(t 1 ) then empty(t ) if empty(t ) then T else else if empty(t ) then and else if simila(left(t 1 ),left(t )) then simila(ight(t 1 ),ight(t )) else ; opyight 1998 y Hanan Samet

QUIVLN O INRY TRS 81 t14 Two inay tees T1 and T ae said to e equivalent if they ae simila and coesponding nodes contain the same infomation? NO! we ae dealing with inay tees and the left sutee of is not the same in the two cases equivalent(t1,t) = if empty(t1) and empty(t) then T else if empty(t1) o empty(t) then else oot(t1)=oot(t) and equivalent(left(t1),left(t)) and equivalent(ight(t1),ight(t)); opyight 1998 y Hanan Samet

RURSION SUMMRY t15 voids having to use an explicit stack in the algoithm Polem fomulation is analogous to induction ase case, inductive case x: actoial n! = n (n 1)! fact(n) = if n=0 then 1 else n*fact(n-1); The esult is otained y peeling one s way ack along the stack fact(3) = 3*fact() *fact(1) 1*fact(0) 1 = 6 Using an accumulato vaiale and a call fact(n,1): fact(n,total) = if n=0 then total else fact(n-1,n*total); Solution is iteative Recusion implemented on compute using stack instuctions. ec-system 10: PUSH, POP, PUSHJ, POPJ Stack pointe fomat: (count, addess) an simulate stack if no stack instuctions opyight 1998 y Hanan Samet

OMPLT INRY TRS t16 When a inay tee is easonaly complete (most Ω links ae at the highest level), use a sequential stoage allocation scheme so that links ecome unnecessay level 0 level 1 level 1 3 4 5 6 7 Ω If n is the highest level at which a node is found, then at most n+1 1 wods ae needed Stoage allocation method: 1. oot has addess 1. left son of x has addess addess(x) 3. ight son of x has addess addess(x) + 1 When should a complete inay tee e used? n = highest level of the tee at which a node is found x = # of nodes in tee 3 wods pe node (left link, ight link, info) use a complete inay tee when x > ( n+1 1) / 3 opyight 1998 y Hanan Samet

ORSTS 4 g 3 z 81 t17 foest is an odeed set of 0 o moe tees Thee exists a natual coespondence etween foests and inay tees G K H J Rigoous definition of () = (T 1, T,, T n ) H T i,1, T i,,, T i,m ae sutees of T i 1. If n = 0, () is empty J. If n > 0, oot of () is oot(t 1 ) left sutee of () is (T 1,1, T 1,,, T 1,m ) ight sutee of () is (T, T 3,, T n ) K G Tavesal of foests peode: postode: 1. visit oot of fist tee 1. tavese sutees of. tavese sutees of fist tee in postode fist tee in peode. visit oot of fist tee 3. tavese emaining 3. tavese emaining sutees in peode sutees in postode peode = K H J G postode = K H J G inode of inay tee opyight 1998 y Hanan Samet

QUIVLN RLTION 3 z 81 t18 Given: elations as to what is equivalent to what (a ) Goal: is x y? omal definition of an equivalence elation 1. if x y and y z then x z (tansitivity). if x y then y x (symmety) 3. x x (eflexivity) x: S = {1.. 9} 1 5 6 8 7 9 8 3 7 4 9 3 is 6? Yes, since 7 3 9 8 6 Patitions S into disjoint susets o equivalence classes Two elements equivalent iff they elong to same class What ae the equivalence classes in this example? {1,5} and {,3,4,6,7,8,9} opyight 1998 y Hanan Samet

LGORITHM 9 8 g 7 z 6 5 g 4 v 3 z 81 t19 Repesent each element as a node in foest of tees Tees consist only of fathe links (nil at oots) ach (nonedundant) elation meges two tees into one asic stategy: fo each elation a do egin find oot node of tee containing a; /* ind step */ find oot node s of tee containing ; if they diffe, mege the two tees; /* Union step */ end; a s mege(a,) a s lgoithm (also known as union-find ): fo evey element i do fathe(i) Ω while input_not_exhausted do egin get_pai(a,); while fathe(a) Ω do a fathe(a); while fathe() Ω do fathe(); if (a ) then fathe(a) ; end; 1 5 5 fathe(k): 5 8 8 6 8 k: 1 3 4 5 6 7 8 9 7 9 8 3 7 1 8 7 3 4 4 9 6 9 3 Moe efficient with path compession and weight alancing xecution time almost linea (invese of ckemann function) opyight 1998 y Hanan Samet