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

Similar documents
tr0 TREES Hanan Samet

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

tr0 TREES Hanan Samet

Noncrossing Trees and Noncrossing Graphs

Depth-first search and strong connectivity in Coq

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

Faster Nearest Neighbors: Voronoi Diagrams and k-d Trees

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

Fundamental Algorithms for System Modeling, Analysis, and Optimization

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

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

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

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

Long-term Improvement of Ventilator-Associated Pneumonia in Bumrungrad International Junya Jarayopas Department Manager, Infection Control

Multi-Robot Forest Coverage

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

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

Trees & Routing (1) BFS

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

PSU WORLD RANKINGS STRATEGY & IMPLEMENTATION

Figures of Thai Export & Import of Tuna, Salmon, Sardine, Mackerel and Petfood in Jan Oct 2018

16 th edition of the wmf world championship 2019

Complexity of Data Tree Patterns over XML Documents

11/ Soi Sathorn 11, South Sathorn Road, Yannawa, Sathorn, Bangkok

Rearranging trees for robust consensus

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

Sudaporn Chungloo 1 and Chub Tienchutima 2 ส ดาภรณ ฉ งล และช ปน เธ ยรช ต มา

CORESTA RECOMMENDED METHOD N 68

Balloon Assisted Valsalva Maneuver in the Diagnosis of Saphenofemoral Junction Incompetence

Cluster trees and message propagation

ABriefIntroductiontotheBasicsof Game Theory

The Effect of Capillary Number on a Condensate Blockage in Gas Condensate Reservoirs

Cooling Tower Performance

Water Pollution Control and Enforcement Status and Challenges in Thailand

รายงานการเข าร วมโครงการเอพ โอ. 16-IN-28-GE-TRC-B/ Training of Trainers on Business Excellence for SMEs ระหว างว นท 24 ต ลาคม-27 ต ลาคม 2559

Dispatching Universität Karlsruhe, System Architecture Group

CABLE L TV!!"! # " $# # $ % & % ' & ' '! )!&! Gr G ou o p u p 4 ISR S A R A I NS N T S ITTU T T U E T

SUVARNABHUMI PIPE INDUSTRY CO., LTD. 8 Soi Ladkrabang 38, Ladkrabang, Ladkrabang, Bangkok Tel thru 49 Fax.

Lesson 33: Horizontal & Vertical Circular Problems

Natures of Golf ธรรมชาต ของก ฬากอล ฟ

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

Data Sheet. Linear bearings

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

SAFETY DATA SHEET ( SDS )

English (original) ภาษาไทย

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

Experiment #10 Bio-Physics Pre-lab Questions

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

Cyclostrophic Balance in Surface Gravity Waves: Essay on Coriolis Effects

Interior Rule of the Quebec Open 2017

Edited by Gordon L J Paterson, Chittima Aryuthaka

Wind and extremely long bridges a challenge for computer aided design

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

ห องปฏ บ ต การทางการแพทย ข อกำหนดด าน ความปลอดภ ย

Angle-restricted Steiner arborescences for flow map layout Buchin, K.A.; Speckmann, B.; Verbeek, K.A.B.

An Auction Based Mechanism for On-Demand Transport Services

Providing solutions for your most demanding applications

Complexity of Data Tree Patterns over XML Documents

The Properties of. Model Rocket Body Tube Transitions

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

Mr. Somporn Pakpien. Asst. Prof. Vijak Chimchome, Ph.D. Dr. Nanthachai Pongpattananurak, Ph.D. Forest Biological Science, Kasetsart University

FY15 Financial Briefing

Real World Search Problems. CS 331: Artificial Intelligence Uninformed Search. Simpler Search Problems. Example: Oregon. Search Problem Formulation

Lecture 8. OUTLINE BJT Amplifiers (cont d) Common emitter topology CE stage with emitter degeneration Impact of Early effect (r o )

Experiment #10 Bio-Physics Pre-lab Comments, Thoughts and Suggestions

THE performance disparity between processor speed and the


(!{{ONLINE) FC Midtjylland U19 - Hamilton Academical Fc Europe. UEFA Youth League, Knockout stage tv

CS 4649/7649 Robot Intelligence: Planning

1 of 6 5/12/2015 8:02 PM

Development of Fly Ash for Application in Thailand

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

CITY OF ANN ARBOR ENGINEERING RIVERVIEW DRIVE SANITARY SEWER AND WATER MAIN EXTENSION PROJECT. ITB No. 4555, FILE No WARREN STEIN BARTON

Module #7: Kit Singles

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

A Force Platform Free Gait Analysis

Uninformed search strategies

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

An integrated supply chain design model with random disruptions consideration

Numerical study of super-critical carbon dioxide flow in steppedstaggered

CSE 3401: Intro to AI & LP Uninformed Search II

British Prime Minister Benjamin Disraeli once remarked that

THE IMPACTS OF CONGESTION ON COMMERCIAL VEHICLE TOUR CHARACTERISTICS AND COSTS

Overlap-Based Genome Assembly from Variable-Length Reads

Lecture 22. Humming Noise in Audio Amplifier. Supply Ripple Rejection. Ripple Free Differential Output. Common Inputs to Differential Amp.

SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY :: PUTTUR (AUTONOMOUS) Siddharth Nagar, Narayanavanam Road QUESTION BANK (DESCRIPTIVE)

Humidity Humidity is the amount of water vapor in the atmosphere

Algorithms and Data Structures

Problem Solving Agents

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

A Physical Prototype of an Automotive Magnetorheological Differential

AIRPLANE PAVEMENT MARKINGS

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

CS 173: Discrete Structures, Spring 2010 Homework 9 Solutions

The Princess Sirivannavari Thailand Masters 2016

UNIVERSITÀ DEGLI STUDI DI PADOVA. Dipartimento di Scienze Economiche Marco Fanno

Representation. Representation. Representation. Representation. 8 puzzle.

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

Tracking of High-speed, Non-smooth and Microscale-amplitude Wave Trajectories

THE GREAT CARDBOARD BOAT RACE INTRODUCTION, BOAT BUILDING & RULES by United Way of Elkhart County

Transcription:

Tee Tee Lectues : oontee Kuatachue Room no. Kitawan Siiboon Room no. Text : ata Stuctues & lgoithm nalysis in, ++, Mak llen Weiss, ddison Wesley. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee teecan be empty with no nodes called thenull o empty teeo a tee is a stuctue consisting of one node called the ootand one o moe subtees. Node in a tee must be disjoint. t must not be in common in oot o subtees. Root = fathe (paent) of subtee s oot. Subtee s oot = son(child child) of his fathe. Tee efinitions The name of the tee usually called by its oot. Root node R fathe paent of,, R,, : E subtee T son, child of R T H J Kisnot disjoint (be in subtee & subtee J) R is not a tee. K T Leaf ntenal Siblings and Paent and hild Leaf node (extenal, oute, teminal) node with no son anch node(intenal, inne, inode (fo shot) node leaf Siblings (bothes) node with same fathe and Paent fathe of fathe and hild son of son (fo shot)) E J K L H...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

epth = Level = 0 Path, Path Length, epth, Height Path (fom n to d)sequence of nodes and edges connecting a node nwith a descendant d n tee, only path fom node to node Heightof node = longest path length fomnode to leaf epth = Level = epth = Level = epth = Level = epth = Level = E Path,, length = epth(level level) of node = path length fom oot to node epth of = Path length= # edge in path Height of = Tee Height = Root Heigth = Empty Tee Height = -...ก KMTL 00 ata Stuctues & lgoithms : Tee J K L H = Heightof =? ncesto & ecendent ncesto fathe of ancesto = ancesto of if has path fom to ecendent ก son of decendent = Popencesto of if = Popeecendent of if E H J K L...ก KMTL 00 ata Stuctues & lgoithms : Tee Tee Examples Tee Examples...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 8

Thai Royal amily Tee Tee. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 0 inay Tee inay Tee bi = has at most subtees (has 0, o subtees) q p Pefect inay Tee Pefect inay Tee (mbiguously also called omple inay Tee ) Evey level is completely filled epth = Level = 0 = L = = L = = L = 8 0 # Nodes in each level : = 0 = = 8= = L = 8 0 8 0 = = H Tee Height Leave epth H = 0 8 Nomally not daw banch diection null pt s N =จ านวน node ใน pefect binay tee N= 0 + +...+ H N n+ i N= H+ =, i= 0 - N= ( H extenal) + ( H - intenal) H= = log (N+) O( log (N)) <> Pefect inay Tee of N nodes: H= log (N+) N= H+ -...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

omplete inaytee omple inay Tee Evey level, except possibly the last, is completely filled & ll nodes ae as fa left as possible. 8 0 omplete binay tee 8 0 Without node : Not a complete binay tee...ก KMTL 00 ata Stuctues & lgoithms : Tee ull (pope, stictly, -tee) inaytee ull Node = node with childen ull binay tee node = full node o leaf # extenal = # intenal + edge top edge bottom Poof : edge top = #intenal edge bottom = #extenal + #intenal (oot) H J K edge bottom = edge top #extenal + #intenal = #intenal #extenal = #intenal + How good? Ty add evey leaf with sons. id you see? E edge top...ก KMTL 00 ata Stuctues & lgoithms : Tee L M efoe : N = Max Seach Path = Tee s Height Q N R P dd = 8 moe Max Seach Path + Tee s Height ull omplete Pefect How can 0 nodes in a binay tee has shotest seach path? 8 0 Linked list : N Wost ase epth omplete inay Tee : H = = log (N+) 8 0 deal tee How much diffeent N vs log N? Log,000,000 < 0...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

inay Seach Tee Why Tee? inay SeachTee : fo evey node left decendents < ight decendents 8 < 8 < 0 mplicit (Sequential ) ay nsetion eletion Poblems Tee Tee Seach O(log n) Linea Linked list Linea Seach O(n) UNX ile system of seveal popula OS...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 8 Tee inay Tee Tavesals. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees Tee Tavesal การไปเย ยม (visit เช นการพ มพ การ update ข อม ล) ท ก node node ละ คร ง อย างม ระบบ แบ งตามล าด บของการ visit eadth ist (Level Ode) จากoot ไปด านข างก อน. ล กคนแรก ล กคนท ล กคนท...จนหมดล กท กคน. ท าข อ. ก บท กคนท ไปเย ยมมาตามล าด บ epth-ist Ode จาก oot ไปด านล กก อนไปด านข าง ล กคนแรก แล วไปหลานคนแรกก อนไปท ล กคนท...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 0

eadth - ist (Level Ode) epth ist Ode eadth ist จากoot ไปด านข างก อน ใช queueช วยในการหา ไล ไปท ละ level จ งเร ยกอ กอย างหน งว า Level Ode epth-ist Ode จาก oot ไปด านล กก อนไปด านข าง ใช stack ช วยในการหา queue enq ( oot ) while( notemptyq ){ n = deq () E if ( n->left ) enq ( n->left ) H if ( n->ight ) enq ( n-> ight ) E H แบ งเป น แบบ ข นก บการวางต าแหน งการ visit oot ไว ท ใด node (Symmetic Ode). inode(leftsubtee). visit_oot. inode(ightsubtee) Peode. visit_oot. peode(leftsubtee). peode(ightsubtee) Postode. postode(leftsubtee). postode(ightsubtee). visit_oot...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee node (Symmetic Ode) Peode inode( oot ) { if (oot){ inode(oot->left) visit(oot) inode(oot->ight) E H pe ข ก in ค post peode( oot ) { if (oot){ visit(oot) peode(oot->left) peode(oot->ight) E H pe ข ก in ค post E H E H...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

Postode Test You Self postode( oot ) { if (oot){ postode(oot->left) postode(oot->ight) visit(oot) pe ข ก in ค post pe ข ก in E ค post H inay Seach Tee 8 0 node: LootR. inode(l). visit_oot. inode(r) Postode : LRoot Peode: ootlr E J K L H node E J K H L 8 0 sscending Ode! H E Peode E J H K L 8 0 Postode E J K L H 0 8...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee Tee inay SeachTee. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees inay SeachTee : fo evey node < left decendents < ight decendents 8 < 8 < 0...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 8

nsetion elete a : Leaf, Node with only child < < < 8 0 8 0 8 nsets : 8 0 elete Leaf 0 can be deleted ight away, still be a binay seach tee elete a node with only one child elete, eplace a subtee at the deleted node...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 0 elete a Node with oth hilden : Lazy eletion elete a Node with oth hilden : Lazy eletion 8 0 8 8 0 nceases tee height. => Lazy eletion 8 0 0 8 0 8 0 8 nceases tee height. => Lazy eletion 0 8 0 elete Whee can we put tee, and tee? elete an eplace only at the deleted node. Let choose. Whee to put tee? an eplace only at the deleted node. t s a binay seach tee! Whee is it s place? f we choose. Whee is s place?...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

eletion : Using node Successo / Pedecesso 8 0 8 0 = inode successo of Replace with with data elete instead as child deletion. 8 0 8 0 Not inceasing tee height!!! = inode pedecesso of. Replace with data. elete instead as child deletion. 8 0 8 0...ก KMTL 00 ata Stuctues & lgoithms : Tee 8 0 8 0. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations Tee pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees...ก KMTL 00 ata Stuctues & lgoithms : Tee inay Tee Repesentations (Sequential) mplicit ay. ynamic typedef int T; stuct node{ T data; stuct node *left, *ight; ; typedef stuct node node;. Linked ay. Sequential (mplicit) ay oot left data ight fathe 0 - - - - 0 - - - 8 0 0 L M L M 0 8 0 H 8 0 E J K L M N O 0 E H J K L M N O 0 8 0 8 0 0 L M L M 0 8 0 E H J K L M N O 8 0 E H J K L M N O 0 8 0 8 0 L M L M 0 8 0...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee

8 0 (Sequential) mplicit ay 0 L M L M 0 8 0 8 0 L M L M 0 8 0 Stat at index 0 Stat at index Whee is the oot? 0 The node at index i s left son? i + i ight son? i + i + fathe? (i -) div i div So good! No memoy fo link! Easy to calculate! What happen if we have only node at indices : 0,,,? What shape of tee should be best fo sequential aay? Tee. Tee efinitions. inay Tee Tavesals inay Seach Tee Repesentations pplication : Expession Tee. VL Tee. Which Repesentions?. n-ay Tee. eneic Tee. Multiway Seach Tee 8. -Tees...ก KMTL 00 ata Stuctues & lgoithms : Tee...ก KMTL 00 ata Stuctues & lgoithms : Tee 8 Example : Expession Tee onstucting an Expession Tee + stack S a b input postfix fom a b + c d e + * * + * a + c d e b a * + g b c * f d e (a + b * c) + ((d * e + f) * g)...ก KMTL 00 ata Stuctues & lgoithms : Tee + c + a b d e + a b * c + d e * + * a b c + d e Scan input fom left to ight. Opeand eate an opeand node and push to the stack Opeato eate an opeato node. Pop opeands to be its childen. Push to the stack....ก KMTL 00 ata Stuctues & lgoithms : Tee 0