Mata kuliah :K0362/ Matematika Diskrit Tahun :2008
Diterbitkan olehSri TedjoTelah diubah "2 tahun yang lalu
Presentasi berjudul: "Mata kuliah :K0362/ Matematika Diskrit Tahun :2008"— Transcript presentasi:
1 Mata kuliah :K0362/ Matematika Diskrit Tahun :2008 Tree GraphPertemuan 10 :
2 Learning OutcomesMahasiswa 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 Outline Materi: Pengertian Tree Spanning Tree Cabang, akar & daun Titik berat, Berat pohon & Pusat beratOrdered Rooted TreePengertian Ordered rooted treeLeksikografik orderPrefix form/ Pre orderPosfix form/Post orderInfix form/ In orderContoh pemakaian
4 Pengertian PohonSuatu 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 Pengertian Pohon (2)Diagram pohon, diagram pohon merupakan digraph, yang : mempunyai source tak ada vertex yang indegreenya lebih dari satu.hutan (forest) = himpunan pohondiagram pohon dapat digunakan sebagai alat untuk memecahkan masalah dengan menggambarkan semua alternatif pemecahan.Hutan : banyaknya titik = nbanyaknya pohon = kbanyaknya rusuk = n-k
6 Applications of Graphs: Topological Sorting Topological orderA 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 graphThere may be several topological orders in a given graphTopological sortingArranging the vertices into a topological order
7 Topological Sorting Figure 13.14 Figure 13.15 A directed graph without cyclesFigure 13.15The 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
8 Topological Sorting Simple algorithms for finding a topological order topSort1 (Example: Figure 13-16)Find a vertex that has no successorRemove from the graph that vertex and all edges that lead to it, and add the vertex to the beginning of a list of verticesAdd each subsequent vertex that has no successor to the beginning of the listWhen the graph is empty, the list of vertices will be in topological order
9 Topological SortingSimple algorithms for finding a topological order (Continued)topSort2 (Example: Figure 13-17)A modification of the iterative DFS algorithmStrategyPush all vertices that have no predecessor onto a stackEach time you pop a vertex from the stack, add it to the beginning of a list of verticesWhen the traversal ends, the list of vertices will be in topological order
10 Spanning TreesA treeAn undirected connected graph without cyclesA spanning tree of a connected undirected graph GA subgraph of G that contains all of G’s vertices and enough of its edges to form a treeExample: Figure 13-18To obtain a spanning tree from a connected undirected graph with cyclesRemove edges until there are no cycles
11 Spanning TreesYou can determine whether a connected graph contains a cycle by counting its vertices and edgesA connected undirected graph that has n vertices must have at least n – 1 edgesA connected undirected graph that has n vertices and exactly n – 1 edges cannot contain a cycleA connected undirected graph that has n vertices and more than n – 1 edges must contain at least one cycle
12 Spanning TreesFigure 13.19Connected graphs that each have four vertices and three edges
13 The DFS Spanning TreeTo create a depth-first search (DFS) spanning treeTraverse the graph using a depth-first search and mark the edges that you followAfter the traversal is complete, the graph’s vertices and marked edges form the spanning treeExample: Figure 13-20
14 The BFS Spanning TreeTo create a breath-first search (BFS) spanning treeTraverse the graph using a breadth-first search and mark the edges that you followWhen the traversal is complete, the graph’s vertices and marked edges form the spanning treeExample: Figure 13-21
15 Minimum Spanning Tree Minimum spanning tree A spanning tree for which the sum of its edge weights is minimalPrim’s algorithmFinds a minimal spanning tree that begins at any vertexStrategy (Example: Figures and 13-23)Find the least-cost edge (v, u) from a visited vertex v to some unvisited vertex uMark u as visitedAdd the vertex u and the edge (v, u) to the minimum spanning treeRepeat the above steps until there are no more unvisited vertices
16 Tree TraversalsDefinition: A traversal is the process for “visiting” all of the vertices in a treeOften defined recursivelyEach kind corresponds to an iterator typeIterators are implemented non-recursively
17 Visit vertex, then visit child vertices (recursive definition) Preorder TraversalVisit vertex, then visit child vertices (recursive definition)Depth-first searchBegin at rootVisit vertex on arrivalImplementation may be recursive, stack-based, or nested loop
28 Tree TraversalsPreoder: depth-first search (possibly stack-based), visit on arrivalPostorder: depth-first search (possibly stack-based), visit on departureLevelorder: breadth-first search (queue-based), visit on departure
29 Binary TreesDefinition: A binary tree is a rooted tree in which no vertex has more than two childrenDefinition: A binary tree is complete iff every layer but the bottom is fully populated with vertices.root1234567
30 Binary Tree Traversals Inorder traversalDefinition: left child, visit, right child (recursive)Algorithm: depth-first search (visit between children)
Your consent to our cookies if you continue to use this website.