Pertemuan 13 Graph Tree Graph Tree Struktur data

  • Slides: 24
Download presentation
Pertemuan 13 Graph + Tree

Pertemuan 13 Graph + Tree

Graph & Tree Struktur data non-linier. Penambahan atau penghapusan elemen data tidak mengakibatkan strukturnya

Graph & Tree Struktur data non-linier. Penambahan atau penghapusan elemen data tidak mengakibatkan strukturnya tumbuh atau menyusut secara linier (garis lurus). Strukturnya bersifat hierarkis multidimensi 2 dimensi atau lebih. Umumnya diimplementasikan dengan array multidimensi atau linked list multilink.

Pengenalan Graph Komponen penyusun : Vertices (node) Edges (arc/ link) Jenis : Weighted/ non

Pengenalan Graph Komponen penyusun : Vertices (node) Edges (arc/ link) Jenis : Weighted/ non weighted graph Directed/ non directed graph Traversal (penelusuran) : DFS (Depth First Search) BFS (Breadth First Search) Contoh kasus : path lintasan terpendek

 Struktur data sepeti tree Tree bisa disebut juga dengan graph Struktur graph biasanya

Struktur data sepeti tree Tree bisa disebut juga dengan graph Struktur graph biasanya merepresentasikan fisik studi kasus seperti Dalam kasus sortest path : vertices menunjukkan kota, dan edges menunjukkan jarak atau rute sebuah pesawat Dalam kasus penjadwalan : vertices menunjukkan sebuah tugas, dan edges menunjukkan alur tugas apa yang harus diselesaikan sebelum sebuah tugas dijalankan Graph sudah digunakan sebelum ditemukannya komputer (abad 18), tree baru digunakan setelah ada komputer

Directed graph Hanya bisa melewati edges sesuai arah panah Dalam realita menggambarkan arah rute

Directed graph Hanya bisa melewati edges sesuai arah panah Dalam realita menggambarkan arah rute jalan yang bisa ditempuh Arah digambarkan dengan tanda panah pada akhir edge

Weighted graph Menunjukkan biaya atau besar nilai yang dibutuhkan untuk melewati sebuah edges Misal

Weighted graph Menunjukkan biaya atau besar nilai yang dibutuhkan untuk melewati sebuah edges Misal : Biaya pesawat antara kota A dan kota B Jarak antara kota A dan kota B Waktu yang dibutuhkan untuk menyelesaikan pekerjaan B Dll Digambarkan dengan angka pada edges

Pengenalan Tree nodes contain two or more links All other data structures we have

Pengenalan Tree nodes contain two or more links All other data structures we have discussed only contain one Binary trees All nodes contain two links None, or both of which may be NULL The root node is the first node in a tree. Each link in the root node refers to a child A node with no children is called a leaf node

 Sebuah tree terdiri dari Nodes : menggambarkan entities seperti orang, komponen mobil, pesawat

Sebuah tree terdiri dari Nodes : menggambarkan entities seperti orang, komponen mobil, pesawat dll Edges : menggambarkan bagaimana nodes berhubungan Tiap node pada tree maksimal memiliki 2 child Pada general tree bisa lebih dari 2 child disebut multiway tree

Class node

Class node

Class tree

Class tree

main

main

Method find

Method find

Method insert

Method insert

Tree traversals Inorder traversal 1. Traverse the left subtree with an inorder traversal 2.

Tree traversals Inorder traversal 1. Traverse the left subtree with an inorder traversal 2. Process the value in the node (i. e. , print the node value) 3. Traverse the right subtree with an inorder traversal Preorder traversal 1. Process the value in the node 2. Traverse the left subtree with a preorder traversal 3. Traverse the right subtree with a preorder traversal Postorder traversal 1. Traverse the left subtree with a postorder traversal 2. Traverse the right subtree with a postorder traversal 3. Process the value in the node

Binary Tree Search p = tree; while ( p != null && key !=

Binary Tree Search p = tree; while ( p != null && key != k(p)) if (key < k(p)) p = left(p); else p = right(p); return (p);