โครงสร้างข้อมูลแบบต้นไม้ (Tree)

โครงสร้างข้อมูลแบบต้นไม้ (Tree)

(TREE)TREE) Tree Root Node Subtree 1.

(Root node) , RRoot node) , R 2. n T1 , T2 ,..Tn (Root node) , Rn >=0) (Root node) , RSubtree) R A,B,C,D A E,F,G F J B (Level)Level))

1 1 F 4 (Level)Level) Degree) X 1 A 2 H 3 B 1 E 0 (Level)Leaf Node)

0 C, D, E, J, F G 0 interior node branch node Immediate Successor SON i Immediate Successor i i SON H E, I, F Immediate Predecessor father i Immediate Predecessor i

FATHER J I FATHER I H (TREE)Tree Structure) Root Nodes R Nodes X Immediate Predecesso Y X Father (TREE)Parent) C A B

X D H YNodes Y Immediate Successo X Y son (TREE)Child) X Leaf Nodes E I G (TREE)Tree Structure)

Root Nodes R A B D H C Leaf Nodes E I

Level 0 X Level 1 Y Level 2 G Level 3 el Node 1 (TREE)Tree Structure) Root Nodes

R A B D H C Leaf Nodes E I Level 0

X Level 1 Y Level 2 G Level 3 gree Subtree A De Degree 1 (TREE)Tree Structure) Root Nodes

R A B D H C Leaf Nodes E I Level 0

X Level 1 Y Level 2 G Level 3 Node Degree = 0 C, D, E, I ,G Degree <> 0 Branch Node Interior Node (TREE)Tree Structure) R C

A B D H E I Nodes X Immediate Predecesso X Y X Father (TREE)Parent) Nodes Y Immediate Successor Y X Y son (TREE)Child) X

G Predecessor Node Successor Node R, B, H Predecessor E, I, (TREE)Binary Tree) rooted binary tree 2 ( ) (left subtree) (right subtree)

17 (TREE)Binary Trees) <=2 18 Binary Tree 19

Empty Null Tree A C B D V C E F G

D S G () () (), () () F X () () () (), ()

() () (TREE) Complete Binary Tree) ( left son right son ) (leaf nodes) Dn () 3 R K W

O U () M n 2n-1 W V D S A Q

N 23-1 = 7 2 1. 2. (Root node) , Rsequential)

DATA DATA LLINK RLINK LSON RSON LSON RSON 1 complete binary tree 1 2 ...

k 1 1 2 4 C 8 E A B D

9 10 3 6 5 11 12 X 13 7 14 15

4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 A B X C D - - E - - - - - - x 2x Data07 Tree(Level) 28) Tree Binary Tree (Root node) , Rordinary) binary tree 1.

2. 1 Data07 Tree(Level) 29) Tree Binary Tree 1 2 3

4 Data07 Tree(Level) 30) Tree A Binary Tree A B B C F D

E G H C K J L D E G L I

A I F C G D K J H

B 1-3 F E H J K L I (TREE)Tree Traversal) Tree Traversal

3 () 1. Pre-Order Traversal (TREE)RTLTR) 2. In-Order Traversal (TREE)TLRTR) 3. Post-Order Traversal (TREE)TLTRR) Data07 Tree(TREE) 32) Binary Tree 3 1. Inorder traversal Symmetric order

(TREE)Left/ Root/Right) 2. Preorder traversal (TREE)Root/ Left/ (TREE)Binary Tree Traversal) start R stop Pre-Order Traversal (TREE)Root/ Left/ Right A

C X D Y G Result R A C D X

Y G (TREE)Binary Tree Traversal) start R stop In-Order Traversal (TREE)Left/ Root/Righ A C

X D Y G Result C A D R G Y

X (TREE)Binary Tree Traversal) start R stop Post-Order Traversa (TREE)Left/ Right/ Root) A C X D

Y G Result C D A G Y X R

Data07 Tree(TREE) 36) Binary Tree A B C 1. (TREE)Left/ Root/Right) BAC 2. (TREE)Root/ Left/ Right) ABC 3. (TREE)Left/ Right/ Root) BCA A B

D C E F G H I 1. (TREE)Left/ Root/Right) DB A EG C HFI 2. (TREE)Root/ Left/ Right) A B

C D E G H Pre-order : ABDGCEHIF In-order : DGBAHEICF F I EX1

+ - A * B D C 1.Pre-order 3.Post-order 2.In-order Expression Tree operands, operators

Expression tree (Root node) , Ra + b * c) + (Root node) , R(Root node) , Rd * e + f ) * g)) Expression Tree Data07 Tree(Level) 41) (Root node) , Roperand) (Root node) , Roperators) (Root node) , Rleave node) (Root node) , Runary operator) - log)(Root node) , R) cos(Root node) , R)

+ * Z X Y X * Y + Z Expression Tree Data07 Tree(Level) 42) (Root node) , RX (Root node) , R(Root node) , RY / R) * D)) X

* / Y D R X-Y/R*D -X*/YRD Expression Tree 1.

operand tree push stack 3. operator pop stack 2 trees T1 T2 (T1 ) tree (root) operator left right children T1 T2 tree stack 2. a b + c d e + * * 1 2 3 a b + c d e + * * 4

5 a b + c d e + * * 6 7 1. Preorder ,Inorder , Postorder A H B F G

D 2. Expression Tree 2.1 (Root node) , RA - 2 * (Root node) , RB + C) D * E) * F 2.2 A + (Root node) , RB C) * D ^ (Root node) , R E * F ) J I K M 3. A H B

C D F E G J I K M

Recently Viewed Presentations

  • Chemistry - KFUPM

    Chemistry - KFUPM

    Aluminum thiosulfate Tetraphosphorous decaoxide Copper(II) nitrite Sodium permanganate Carbon disulfide Iron(III) chromate Hydrogen chloride Phosphonium bromite * Law of Definite Proportion Law of Multiple Proportions 2 2.1 Mass of Nitrogen That Combines With 1 g Oxygen Compound A 1.750 g...
  • Principal Applications of Welding

    Principal Applications of Welding

    double V‑groove weld (for thicker sections) Weld Types: Groove Welds. ... is required for good weld penetration. Edge preparation increases cost of parts fabrication. Weld Types: Plug Weld and Slot Weld (a) Plug weld and (b) slot weld. Filler metal...
  • Informal document No. WP.29-146-21 146th WP.29, 11-14 November

    Informal document No. WP.29-146-21 146th WP.29, 11-14 November

    Informal document No. WP.29-146-21 146th WP.29, 11-14 November 2008, agenda item 3.5.3.) AFS Main Beam (Driving Beam) Improvements Presentation to WP29 - 146th Session
  • The State Budget Situation

    The State Budget Situation

    The State Budget Situation Presented To: California State Association of Counties May 27, 2009 www.lao.ca.gov The February State Budget Package Magnitude of the Problem $40 billion is over 40 percent of the General Fund Budget.
  • The World at War (again) - Yola

    The World at War (again) - Yola

    Review Define lebensraum and appeasement Provide at least two possible reasons why countries did not stop Hitler sooner C. Hitler's Goals For Revenge!! 1. "LEBENSRAUM" -Living Space' for Germans a. Take land from non-Germans (Less Human) and give to his...
  • SECURED TRANSACTIONS & COLLATERAL REGISTRIES GLOBAL PERSPECTIVES &

    SECURED TRANSACTIONS & COLLATERAL REGISTRIES GLOBAL PERSPECTIVES &

    BENEFITS OF A SOLID SECURED TRANSACTIONS SYSTEM. Benefits of a Solid Secured Transactions System - Underserved MSMEs and women entrepreneurs - Promotes risk management, prudent lending. INCREASES ACCESS TO CREDIT REDUCING THE RISK OF CREDIT - - Better. interest rates...
  • Financial Training for School Personnel

    Financial Training for School Personnel

    Title I Stipend Payment Training for School Staff August 2010 Presenters: Amanda Gambill and Kim Lavielle what is a stipend payment? one-time payment to employee for extra hours worked or for attendance at an activity (ex: employee attends training for...
  • GLUCOSE TESTING USING THE TrueTrack GLUCOMETER

    GLUCOSE TESTING USING THE TrueTrack GLUCOMETER

    WARNING. Conducting this test exposes the operator to potentially infectious material. Standard precautions, including glove use, are required for this procedure. and should be handled in the same manner as a patient specimen, using all appropriate precautions.