โครงสร้างข้อมูลทรีและไบนารีทรี (Tree and Binary Tree). A. B. C. Terminology. ต้นไม้ (Tree) ประกอบด้วย 1. Node ใช้เก็บข้อมูล 2. Branch ใช้เชื่อม Node เข้าด้วยกัน. Node A, B, C Branch AB, AC. A. B. C. Degree หมายถึง จำนวน Branch ที่สัมพันธ์กับ Node แบ่งเป็น
01 / 64โครงสร้างข้อมูลทรีและไบนารีทรี (Tree and Binary Tree)
1 / 17
Download Presentation
โครงสร้างข้อมูลทรีและไบนารีทรี (Tree and Binary Tree)
An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
Parents Children Siblings Leaves Internal nodes Ancestor of G Descendent of A Height A,B,F B,E,F,C,D,G,H,I {B,E,F}, {C,D}, {G,H,I} C,D,E,G,H,I B,F A,F B,E,F,C,D,G,H,I 3
แบบ Preorder N L R algorithm preOrder (val root <node pointer>) 1 if (root is not null) 1 process(root) 2 preOrder(root->leftSubtree) 3 preOrder(root->rightSubtree) 2 return
แบบ Inorder L N R algorithm inOrder (val root <node pointer>) 1 if (root is not null) 1 inOrder(root->leftSubtree) 2 process(root) 3 inOrder(root->rightSubtree) 2 return
แบบ Postorder L R N algorithm postOrder (val root <node pointer>) 1 if (root is not null) 1 postOrder(root->leftSubtree) 2 postOrder(root->rightSubtree) 3 process(root) 2 return
2. Breath-first algorithm breathFirst (val root <node pointer>) 1 p = root 2 while (p not null) 1 process(p) 2 if (p->left not null) 1 enqueue(p->left) 3 if (p->right not null) 1 enqueue(p->right) 4 if (not emptyQueue) 1 dequeue(p) else 1 p = null 3 return
A B C D E R S F G L แบบฝึกหัด 1. จากต้นไม้ต่อไปนี้ จงหาลำดับการประมวลผลแบบ Depth-first ทั้งหมด
A B C D E R S F G L 2. จากต้นไม้ต่อไปนี้ จงหาลำดับการประมวลผลแบบ Breath-first
1. Preorder Traversal 1 if (root is not null) 1 print(root->token) 2 prefix(root->leftSubtree) 3 prefix(root->rightSubtree) 2 return + * a + b c d
2. Postorder Traversal 1 if (root is not null) 1 postfix(root->leftSubtree) 2 postfix(root->rightSubtree) 3 print(root->token) 2 return a b c + * d +
3. Inorder Traversal 1 if (root is not null) 1 if root->token is operand 1 print(root->token) else 1 print(open parenthesis) 2 infix(root->leftSubtree) 3 print(root->token) 4 infix(root->rightSubtree) 5 print(close parenthesis) 2 return ( ( a * ( b + c ) ) + d )