1 / 11

Pertemuan 11 Tree & Binary Tree

Pertemuan 11 Tree & Binary Tree. Matakuliah : T0026/Struktur Data Tahun : 2005 Versi : 1/1. Learning Outcomes. Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat mengembangkan program modular yang menggunakan ADT tree. Outline Materi.

madison
Download Presentation

Pertemuan 11 Tree & 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.

E N D

Presentation Transcript


  1. Pertemuan 11Tree & Binary Tree Matakuliah : T0026/Struktur Data Tahun : 2005 Versi : 1/1

  2. Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : • Mahasiswa dapat mengembangkan program modular yang menggunakan ADT tree

  3. Outline Materi • pengertian dan kegunaan TreeADT tree • Terminologi Tree • Pengertian Binary Tree • Operasi Traversal Tree • Representasi Tree: Array & linked-list

  4. TREE • One-to-Many data relational (Hierarchy). • Definition : A tree is a finite set of one or more nodes such that : • There is a specially designed node called the ROOT. • The remaining node a partitioned into n>=0 disjoint sets T1,…,Tn, where each of these set is a tree. T1,...,Tn are subtrees of the ROOT. • There is an instance of recursive definition since the subtrees as trees. • Two types of data presentation (genealogical) : • Pedigree chart (figure A: S ancestor) • Lineal chart (figure B : descendant) Proto Indo-European Figure A. Pedigree Chart Figure B. Lineal Chart Dusty Italic Hellenic Germanic Honey Bear Brandy Brundhilde Terry Latin Osco-Umbrian

  5. Normally we draw trees with root at the top. The degree of node is the number of subtrees of the node. The degree of tree is the maximum degree of the node in the tree. Height/depth is the maximum level of any node in the tree. Parent-Child. Siblings are Children of the same Parent Ancestors Descendant TREE DEGREE of C : 2 DEGREE of Tree : 3 HEIGHT : 3 PARENT of C : A CHILDREN of A : B, C, D SIBLINGofF : G ANCESTORof F : A, C DESCENDANTofC :F, G TREE Level 1 A B C D Level 2 E F G Level 3

  6. Binary Tree • Set of nodes that is either empty or consist of a root and two disjoint binary trees called left subtree and right subtree . • Degree of any given node must not exceed two. • Maximum number of nodes : • On level i : 2 , i >= 1 • In a Binary Tree of depth k : 2 -1, k >=1 • Types • Complete Binary Tree • Skewed Binary Tree • Full Binary Tree is Binary Tree that has maximum number of nodes (2 -1) i -1 k k Complete Binary Tree Skewed Binary Tree A A B C C G D E

  7. Binary Tree Traversals • Traversing is visiting each node in the tree. • Type/name of traversals : • PreOrder (VLR) • InOder (LVR) • PostOrder (LRV) Traversal Algorithms on Binary Tree PreOrder : • Visit Root (N) • Move Left SubTree(T1) • Move Right SubTree(T2) InOrder : • Move Left SubTree(T1) • Visit Root (N) • Move Right SubTree(T2) PostOrder : • Move Left SubTree(T1) • Move Right SubTree(T2) • Visit Root (N) N T1 T2

  8. Traversal Implementations Traversals Code on C PreOrder (ROOT n) { if (n != NULL){ printf(n->info); PreOrder(n->Left); PreOrder(n->Right); } } InOrder (ROOT n) { if (n != NULL){ InOrder(n->Left); printf(n->info); InOrder(n->Right); } } PostOrder (ROOT n) { if (n != NULL){ PostOrder(n->Left); PostOrder(n->Right); printf(n->info); } }

  9. Array Representation • Root’s Index is 0 • Left Child’s Index is 2p + 1, p is parent’s index • Right Child’s Index is 2p + 2 • Parent’s Index is (c-1)/2, c is child’s index Binary Tree A B C D E F Array 2 7 11 12 1 0 5 6 9 10 3 4 8 G H

  10. Linked List Representation Double Linked List Multiple Linked List struct node { Elemen_Type Data; struct node *Left; struct node *Right; } struct node { Elemen_Type Data; struct node *Left; struct node *Right; struct node *Parent;} Data Parent Left Right Data Left Right Data Data Parent Parent Left Right Left Right Data Data NULL NULL NULL Data Left Right Left Right Left Right NULL NULL NULL Parent NULL NULL Data Left Right NULL NULL

  11. Expression Tree • For each node contains operand or operator for arithmetic expression. • Traversals : • InOrder, produce Infix • PreOrder , produce Prefix • PostOrder , produce Postfix Expression Tree + x 7 5 8

More Related