1 Pertemuan 09 Binary Tree Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005.

Slides:



Advertisements
Similar presentations
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
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
Trees Chapter 8.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
1 Pertemuan 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
1 Pertemuan 20 Binomial Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
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 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
1 General Trees & Binary Trees CSC Trees Previous data structures (e.g. lists, stacks, queues) have a linear structure. Linear structures represent.
1 Pertemuan 11 Tree & Binary Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Binary Trees. Node structure Data A data field and two pointers, left and right.
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.
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
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.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
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.
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, Binary Trees, and Binary Search Trees COMP171.
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.
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Disusun Oleh : Budi Arifitama Pertemuan ke-8. Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
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.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
BINARY TREES A BINARY TREE t IS EITHER EMPTY OR CONSISTS OF AN ITEM, CALLED THE ROOT ITEM, AND TWO DISTINCT BINARY TREES, CALLED THE LEFT SUBTREE AND.
Binary Trees. 2 Parts of a binary tree A binary tree is composed of zero or more nodes In Java, a reference to a binary tree may be null Each node contains:
Trees (Unit 7).
1 CMSC 341 Introduction to Trees Textbook sections:
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
CMSC 341 Introduction to Trees.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
General Trees & Binary Trees
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
General Trees & Binary Trees
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Binary Trees, Binary Search Trees
8.2 Tree Traversals Chapter 8 - Trees.
Presentation transcript:

1 Pertemuan 09 Binary Tree Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005

2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : mendemonstrasikan operasi pada Binary Tree (TIK-07). menerapkan Binary Tree pada program aplikasi komputer (TIK-07).

3 Outline Materi Karakteristik Terminologi Jenis Operasi Representasi Implementasi Expression Tree

4 Merupakan tipe Struktur Data dg hubungan One-to-Many / Nested / Hirarki. Terdapat 1 node yang unique, yang tidak memiliki predecessor. Node ini disebut ROOT. Terdapat satu atau beberapa node yang tidak mempunyai successor. Node-node ini disebut LEAF. Setiap node, kecuali ROOT, pasti memiliki 1 predecessor yang unique. Setiap node, kecuali LEAF, pasti memiliki 1 atau lebih successor. Contoh : Karakteristik A BCD EFG ROOT EDGE LEAF TREE

5 HUBUNGAN PARENT-CHILD PARENT adalah predecessor langsung dari suatu node. CHILD adalah successor langsung dari suatu node. Node-node yang memiliki PARENT yang sama disebut SIBLING. HUBUNGAN ANCESTOR-DESCENDANT ANCESTOR adalah semua node yang berada di atas / sebelum node tertentu, yang terdapat pada path yang sama. DESCENDANT adalah semua node yang berada di bawah / setelah node tertentu. Contoh : Terminologi A BCD EFG PARENT dari C adalah A CHILD dari A adalah B, C, D SIBLING dari F adalah G ANCESTOR dari F adalah A, C DESCENDANT dari C adalah F, G TREE

6 REKURSIVE pd TREE Tree memiliki sifat yang dinamakan Rekursive,yang dapat didefinisikan sbb: –Untuk sebuah node tertentu, node tersebut beserta semua descendantnya adalah SUBTREE dari parentnya. –SUBTREE tersebut memiliki semua karakteristik dari suatu TREE. TREE PATH-LENGTH –Utk SIMPLE TREE, path length adalah sama dengan JUMLAH NODE dikurangi 1. –Secara umum, path length diambil dari path length dari subtree yang terpanjang. TREE HEIGHT –Level : Setiap node pasti akan berada pd tingkat/level tertentu. –TREE Height : Level tertinggi dari suatu TREE. Contoh : Terminologi (2) A BCD EFG PATH-LENGTH= 3 - 1= 2 HEIGHT= 3 TREE Level 1 Level 2 Level 3

7 Complete Binary Tree (HEAP) Bila semua node, kecuali LEAF memiliki 0 atau 2 children. Subtree dalam Heap dapat mempunyai path length yang berbeda. Full Binary Tree Bila semua node kecuali LEAF memiliki 2 chldren dan semua subtree harus memiliki path length yang sama. Skewed Binary Tree (Binary Tree Miring) Bila semua node, kecuali LEAF memiliki hanya 1 child. Contoh : Jenis A BC D Complete Binary Tree E A BC D EFG A C G Full Binary TreeSkewed Binary Tree

8 Traverse (TypeOrd Ord) Pre : Tree is not empty. Post: Each node in the tree has been proceeded exactly once. The order in which nodes are proceeded depends on the value of Ord. Insert (TypeElm E, TypePos Pos, Boolean *Fail) Pre : Either Pos=root and tree is empty or Pos<>root and tree is not empty. Post: E may have been added to the tree, depending on the value of Pos. If E was added, the node that contains E is the current node. Deletesub () Pre : there is not an empty tree. Post: The subtree of T-pre whoser root is c-pre has been removed from the tree. The root node is the current node. Update (TypeElm E) Pre : The tree is not empty. Post: The current node’s element has the value of E. Retrieve (TypeElm *E) Pre : The tree is not empty. Post: E has value of the standard element in the current node. Operasi

9 Characteristics (Status S) Post: S contains a size, height, and average length of a path from the root to a leaf node. Find (TypePos Pos, Boolean *Fail) Pre: The tree is not empty. Post: The current node is determined by the value of Pos. Empty () Post: If T-pre is empty then empty is true else empty is false. Create () Pre: None. Post: An empty BT exists. Clear () Post: The BT is empty. Operasi (2)

10 Adalah operasi penelusuran terhadap node-node di dalam binary tree. Pola-pola traversal : 1.PreOrder 2.InOder 3.PostOrder Traversal N T1T2 Algoritma Traversal pada Binary Tree PreOrder : –Kunjungi Root (N) –Kunjungi Left SubTree secara PreOrder (T1) –Kunjungi Right SubTree secara PreOrder (T2) InOrder : –Kunjungi Left SubTree secara InOrder (T1) –Kunjungi Root (N) –Kunjungi Right SubTree secara InOrder (T2) PostOrder : –Kunjungi Left SubTree secara PostOrder (T1) –Kunjungi Right SubTree secara PostOrder (T2) –Kunjungi Root (N)

11 Representasi dg Array Indeks pd array menyatakan nomor node Indeks 0 adalah Root node Indeks Left Child adalah 2p + 1, dimana p adalah indeks parent Indeks Right Child adalah 2p + 2 Indeks Parent adalah (p-1)/2 Contoh : A BC DEF Binary Tree GH ABCDEFGH Posisi node dalam array

12 Representasi dg Linked List 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 Implementasi dg Double Linked ListImplementasi dg Multiple Linked List

13 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);} Implementasi Traversal Implementasi Traversal dg bahasa C

14 Binary Tree yang dapat menampung ekspresi aritmatika, dimana setiap node akan berisi operand dan operator. Hasil traversal akan membentuk pola notasi Prefix, Infix, Suffix/Postfix –Traversal InOrder akan menghasilkan notasi Infix –Traversal PreOrder akan menghasilkan notasi Prefix –Traversal PostOrder akan menghasilkan notasi Postfix Contoh : Expression Tree + x7 5 8 TraversalNotasi InOrder5 x PreOrder+ x PostOrder5 8 x 7 +

15 Selesai