1 / 27

TRAVERSING BINARY TREE

TRAVERSING BINARY TREE. GALIH WASIS WICAKSONO. TOPIK BAHASAN. PENGERTIAN TRAVERSING BINARY TREE 3 JENIS TRAVERSAL PADA BINARY TREE IMPLEMENTASI TRAVERSING BINARY TREE DALAM KODE PROGRAM EFISIENSI BINARY TREE. APA ITU TREE?. Gambaran alami dari Tree. Leave. Branch. Root. APA ITU TREE ?.

klaus
Télécharger la présentation

TRAVERSING 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. TRAVERSING BINARY TREE GALIH WASIS WICAKSONO

  2. TOPIK BAHASAN PENGERTIAN TRAVERSING BINARY TREE 3 JENIS TRAVERSAL PADA BINARY TREE IMPLEMENTASI TRAVERSING BINARY TREE DALAM KODE PROGRAM EFISIENSI BINARY TREE

  3. APA ITU TREE? • Gambaran alami dari Tree Leave Branch Root

  4. APA ITU TREE ? • Tree dalam perspektif Ilmu Komputer Root Branch Leave

  5. TRAVERSING TREE • Travers pada tree bermakna mengunjungi setiap node dengan tujuan tertentu. • Pada dasarnya proses traverse tidak sering digunakan, disebabkan karena secara umum prosesnya tidak cepat. • Akan tetapi traverse pada tree dapat bermanfaat pada aplikasi yang anda buat, dan secara teori menarik.

  6. 3 JENIS TRAVERSE BINARY TREE • Inorder • Preorder • Postorder • Finding

  7. INORDER TRAVERSAL • Inorder paling banyak digunakan dalam Binary Search Tree • Inorder dilakukan pada binary tree yang sudah berada dalam kondisi terurut didasarkan key/element tree tersebut. • Cara paling mudah mengimplementasikan inorder dengan rekursif

  8. GAMBARAN INORDER

  9. IMPLEMENTASI INORDER voidinOrder(BinaryTree t) { if (t != null) { inOrder(t.leftChild); visit(t); inOrder(t.rightChild); } }

  10. PREORDER & POSTORDER • Preorder dan postorder digunakan untuk analisis atau mengurai ekspresi aljabar • Umumnya digunakan untuk transformasi dari bentuk infix ke bentuk postfis maupun prefix

  11. EKSPRESI ARITMATIKA • (a + b) * (c + d) + e – f/g*h + 3.25 • Ekspresi aritmatika diatas terdiri dari 3 jenis entitas • Operators (+, -, /, *). • Operands (a, b, c, d, e, f, g, h, 3.25, (a + b), (c + d),etc.). • Delimiters [(, )].

  12. MASALAH PADA INFIX • Butuh prioritas operator, tie breaker, dan pembatas. • Mengakibatkn perhitungan di komputer menjadi sulit. • Bentuk ekspresi Postfix dan prefix tidak bergantung pada prioritas operator, tie breaker, atau pembatas, sehingga lebih mudah dioperasikan oleh komputer. • Ex. Infix : a + b

  13. CONTOH • Infix = a + b * c • Postfix = a b c * + • Infix = a * b + c • Postfix = a b * c + • Infix = (a + b) * (c – d) / (e + f) • Postfix = a b + c d - * e f + /

  14. + a b - a SOLUSI BINARY TREE • a + b • - a

  15. / / + * e f - + - a b c d BINARY TREE SOLUTION • (a + b) * (c – d) / (e + f)

  16. IMPLEMENTASI PREORDER voidpreOrder(BinaryTree t) { if (t != null) { visit(t); preOrder(t.leftChild); preOrder(t.rightChild); } }

  17. IMPLEMENTASI POSTORDER void postOrder(BinaryTree t) { if (t != null) { preOrder(t.leftChild); preOrder(t.rightChild); visit(t); } }

  18. EFISIENSI BINARY TREE • Search pada binary tree = ordered array • O(Log N) -> Full Binary Tree • Search pada binary tree vs linked list & unordered array kasus 100.000 item. • linked list & unordered array butuh rata-rata 500.000 perbandingan • Binary tree butuh 20 (atau kurang) perbandingan • Operasi traversal pada binary tree tidak se-efisen operasi lain, akan tetapi dapat dimanfatkan untuk menguraikan ekspresi aljabar.

  19. REPRESENTASI BINARY TREE BINARY TREE PROPERTIES ARRAY REPRESENTATION LINKEDLIST REPRESENTATION

  20. MINIMUM NUMBER OF NODE • Jumlah node minimum binary tree = level (L) • 1 node pada setiap level

  21. MAXIMUM NUMBER OF TREE Maximum number of nodes • = 1 + 2 + 4 + 8 + … + 2L-1 • = 2L- 1

  22. NUMBER OF NODE & LEVEL • Jika n adalah jumlah node pada binary tree • Dan L adalah level pada binary tree maka : • h <= n <= 2L– 1 • log2(n+1) <= h <= n

  23. PENOMORAN PADA FULL BT • Nomer node dimulai dari 1 hingga 2L-1 • Nomer antar level dimulai dari atas ke bawah • Nomer pada satu level dimulai dari kiri ke kanan 1 2 3 4 6 5 7 8 9 10 11 12 13 14 15

  24. PENOMORAN NODE • i Adalah node root (tidak memiliki parent) • i= 1 • Penomoran left child adalah 2i • 2i > n -> tidak memiliki child • Penomoran right child adalah 2i + 1 • 2i+1 > n tidak memiliki child

  25. b 1 a 2 3 c 4 5 6 7 d f e g 8 9 10 h i j tree[] 0 5 10 REPRESENTASI PD ARRAY • Penomoran pd node menggunakan skema penomoran pada full binary tree. Nomor i disimpan pada tree[i] a b c d e f g h i j

  26. 1 a 3 b 15 7 d c tree[] a - b - - - c - - - - - - - d 0 5 10 15 REPRESENTASI PD ARRAY 0 5 10 15

  27. root a c b d f e g h leftChild element rightChild REPRESENTASI PD LINKEDLIST

More Related