Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

1 Mata kuliah:K0362/ Matematika Diskrit Tahun:2008 Tree Graph Pertemuan 10 :

Presentasi serupa


Presentasi berjudul: "1 Mata kuliah:K0362/ Matematika Diskrit Tahun:2008 Tree Graph Pertemuan 10 :"— Transcript presentasi:

1 1 Mata kuliah:K0362/ Matematika Diskrit Tahun:2008 Tree Graph Pertemuan 10 :

2 2 Learning Outcomes Mahasiswa dapat menunjukkan tree yg meliputi konsep dasar tree, komponen tree, jenis-jenisnya dan contoh tentang penyelesain masalah dgn menggunakan tree atau ordered rooted tree. Mahasiswa dapat mengkombinasikan materi Ordered Rooted Tree dgn disiplin ilmu yg lain serta menerapkannya untuk berbagai kasus..

3 3 Outline Materi: Pengertian Tree Spanning Tree Cabang, akar & daun Titik berat, Berat pohon & Pusat berat Ordered Rooted Tree Pengertian Ordered rooted tree Leksikografik order Prefix form/ Pre order Posfix form/Post order Infix form/ In order Contoh pemakaian

4 4 Pengertian Pohon Suatu graph yang banyak vertexnya sama dengan n (n>1) disebut pohon, jika : Graph tersebut tidak mempunyai lingkar (cycle free) dan banyaknya rusuk (n-1). Graph tersebut terhubung.

5 5 Pengertian Pohon (2) Diagram pohon, diagram pohon merupakan digraph, yang : mempunyai source tak ada vertex yang indegreenya lebih dari satu. hutan (forest) = himpunan pohon diagram pohon dapat digunakan sebagai alat untuk memecahkan masalah dengan menggambarkan semua alternatif pemecahan. Hutan : banyaknya titik = n banyaknya pohon = k banyaknya rusuk = n-k

6 6 Applications of Graphs: Topological Sorting Topological order –A list of vertices in a directed graph without cycles such that vertex x precedes vertex y if there is a directed edge from x to y in the graph –There may be several topological orders in a given graph Topological sorting –Arranging the vertices into a topological order

7 7 Topological Sorting Figure The graph in Figure arranged according to the topological orders a) a, g, d, b, e, c, f and b) a, b, g, d, e, f, c Figure A directed graph without cycles

8 8 Topological Sorting Simple algorithms for finding a topological order –topSort1 (Example: Figure 13-16) Find a vertex that has no successor Remove from the graph that vertex and all edges that lead to it, and add the vertex to the beginning of a list of vertices Add each subsequent vertex that has no successor to the beginning of the list When the graph is empty, the list of vertices will be in topological order

9 9 Topological Sorting Simple algorithms for finding a topological order (Continued) –topSort2 (Example: Figure 13-17) A modification of the iterative DFS algorithm Strategy –Push all vertices that have no predecessor onto a stack –Each time you pop a vertex from the stack, add it to the beginning of a list of vertices –When the traversal ends, the list of vertices will be in topological order

10 10 Spanning Trees A tree –An undirected connected graph without cycles A spanning tree of a connected undirected graph G –A subgraph of G that contains all of G’s vertices and enough of its edges to form a tree –Example: Figure To obtain a spanning tree from a connected undirected graph with cycles –Remove edges until there are no cycles

11 11 Spanning Trees You can determine whether a connected graph contains a cycle by counting its vertices and edges –A connected undirected graph that has n vertices must have at least n – 1 edges –A connected undirected graph that has n vertices and exactly n – 1 edges cannot contain a cycle –A connected undirected graph that has n vertices and more than n – 1 edges must contain at least one cycle

12 12 Spanning Trees Figure Connected graphs that each have four vertices and three edges

13 13 The DFS Spanning Tree To create a depth-first search (DFS) spanning tree –Traverse the graph using a depth-first search and mark the edges that you follow –After the traversal is complete, the graph’s vertices and marked edges form the spanning tree –Example: Figure 13-20

14 14 The BFS Spanning Tree To create a breath-first search (BFS) spanning tree –Traverse the graph using a breadth-first search and mark the edges that you follow –When the traversal is complete, the graph’s vertices and marked edges form the spanning tree –Example: Figure 13-21

15 15 Minimum Spanning Tree Minimum spanning tree –A spanning tree for which the sum of its edge weights is minimal Prim’s algorithm –Finds a minimal spanning tree that begins at any vertex –Strategy (Example: Figures and 13-23) Find the least-cost edge (v, u) from a visited vertex v to some unvisited vertex u Mark u as visited Add the vertex u and the edge (v, u) to the minimum spanning tree Repeat the above steps until there are no more unvisited vertices

16 16 Tree Traversals Definition: A traversal is the process for “visiting” all of the vertices in a tree –Often defined recursively –Each kind corresponds to an iterator type –Iterators are implemented non-recursively

17 17 Preorder Traversal Visit vertex, then visit child vertices (recursive definition) Depth-first search –Begin at root –Visit vertex on arrival Implementation may be recursive, stack-based, or nested loop

18 18 Preorder Traversal root

19 19 Preorder Traversal root

20 20 Postorder Traversal Visit child vertices, then visit vertex (recursive definition) Depth-first search –Begin at root –Visit vertex on departure Implementation may be recursive, stack-based, or nested loop

21 21 Postorder Traversal root

22 22 Postorder Traversal root

23 23 Postorder Traversal root

24 24 Postorder Traversal root

25 25 Levelorder Traversal Visit all vertices in level, starting with level 0 and increasing Breadth-first search –Begin at root –Visit vertex on departure Only practical implementation is queue-based

26 26 Levelorder Traversal root

27 27 Levelorder Traversal root

28 28 Tree Traversals Preoder: depth-first search (possibly stack-based), visit on arrival Postorder: depth-first search (possibly stack-based), visit on departure Levelorder: breadth-first search (queue-based), visit on departure

29 29 Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children Definition: A binary tree is complete iff every layer but the bottom is fully populated with vertices root 7

30 30 Binary Tree Traversals Inorder traversal –Definition: left child, visit, right child (recursive) –Algorithm: depth-first search (visit between children)

31 31 Inorder Traversal root

32 32 Inorder Traversal root

33 33 Inorder Traversal root

34 34 Inorder Traversal root

35 35


Download ppt "1 Mata kuliah:K0362/ Matematika Diskrit Tahun:2008 Tree Graph Pertemuan 10 :"

Presentasi serupa


Iklan oleh Google