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

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

1 Pertemuan 12 Binary Search Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
1 Pertemuan 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Chapter 7 Trees. 2 What is a Tree In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
1 Pertemuan 13 AVL Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
1 Pertemuan 09 Binary Tree Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005.
Binary and Other Trees CSE, POSTECH. 2 2 Linear Lists and Trees Linear lists are useful for serially ordered data – (e 1,e 2,e 3,…,e n ) – Days of week.
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Binary Trees. Node structure Data A data field and two pointers, left and right.
Chapter 11 A Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 A-2 Terminology A tree consists of vertices and edges, –An edge connects to.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures.
Compiled by: Dr. Mohammad Omar Alhawarat
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
Data Structures & Algorithm Analysis Muhammad Hussain Mughal Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
Disusun Oleh : Budi Arifitama Pertemuan ke-8. Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Trees. Binary Trees. Reading: Chap.4 ( ) Weiss.
© University of Auckland Trees – (cont.) CS 220 Data Structures & Algorithms Dr. Ian Watson.
CH 7. TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
1 Chapter 4 Trees Basic concept How tree are used to implement the file system How tree can be used to evaluate arithmetic expressions How to use trees.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
CH 7 : TREE ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Trees (Unit 7).
TREE Ahsan Ahmed College of Computer and Information Science Majma’ah University 1.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
CSCE 3110 Data Structures & Algorithm Analysis
Traversal From CSCE 3110 Data Structures & Algorithm Analysis
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Design and Analysis of Algorithms
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Binary Tree Properties & Representation
Chapter 20: Binary Trees.
Binary Trees.
Binary Trees, Binary Search Trees
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

1 Pertemuan 11 Tree & 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 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) TREE Dusty Honey BearBrandy BrundhildeTerry Figure B. Lineal Chart Proto Indo-European Italic Hellenic Osco-Umbrian Latin Germanic Figure A. Pedigree Chart

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 A BCD EFG DEGREE of C : 2 DEGREE of Tree : 3 HEIGHT: 3 PARENT of C : A CHILDREN of A : B, C, D SIBLING of F : G ANCESTOR of F : A, C DESCENDANT of C :F, G TREE Level 1 Level 2 Level 3

6 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) Binary Tree A BC D Complete Binary Tree E A C G Skewed Binary Tree i -1 k k

7 Traversing is visiting each node in the tree. Type/name of traversals : 1.PreOrder(VLR) 2.InOder(LVR) 3.PostOrder(LRV) Binary Tree Traversals N T1T2 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)

8 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);} Traversal Implementations Traversals Code on C

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 A BC DEF Binary Tree GH ABCDEFGH Array

10 Linked List Representation Data 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;} LeftRight Data LeftRight Data LeftRight Data LeftRight Data LeftRight Parent Data LeftRight Parent Data LeftRight Parent Data LeftRight Parent NULL Double Linked List Multiple Linked List

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