Graph Theory
 Length: 1544 words (4.4 doublespaced pages)
 Rating: Excellent
If you already know what a binary tree is, but not a general tree, then pay close attention, because binary trees are not just the special case of general trees with degree two. I use the definition of a tree from the textbook, but bear in mind that other definitions are possible. Definition. A tree consists of a (possible empty) set of nodes. If it is not empty, it consists of a distinguished node r called the root and zero or more nonempty subtrees T1, T2, …, Tk such that there is a directed edge from r to each of the roots of T1, T2, …, Tk.Definition. A forest is a collection of trees. You can always create a tree form a forest by creating a new root node and making it the parent of the roots of all of the trees in the forest. Conversely, if you lop off the root of a tree, what is left is a forest. I assume that you are familiar with the terminology of binary trees, e.g., parents, children, siblings, ancestors, descendants, grandparents, leaf nodes, internal nodes, external nodes, and so on, so I will not repeat their definitions here. Because the definitions of height and depth may vary from one book to another, I do include their definitions here, using the ones from the textbook. Definition. A path from node n1 to node nk is a sequence of nodes n1, n2, …, nk such that ni is the parent of ni+1 for 1 ≤ i < k. The length of a path is the number of edges in the path, not the number of nodes. Because the edges in a tree are directed, all paths are “downward”, i.e., towards leaves and away from the root. The height of a node is the length of the longest path from the node to any of its descendants. Naturally the longest path must be to a leaf node. The depth of a node is the length of the path from the root to the node. The root has depth 0. All leaf nodes have height 0. The height of a tree is the height of its root. The degree of a node is the number of children of the node. The degree of a tree is the maximum degree of the degrees of its nodes. The tree on the next page has height 3 and degree 5. Need Writing Help?Get feedback on grammar, clarity, concision and logic instantly. Check your paper »How to Cite this Page
MLA Citation:
"Graph Theory." 123HelpMe.com. 20 May 2018 <http://www.123HelpMe.com/view.asp?id=158816>.
Keywords:
It is not hard to see that a tree with N nodes must have N1 edges because every node except the root has exactly one incoming edge. How many edges are in a forest with N nodes and K trees? Applications of General Trees A general tree is useful for representing hierarchies in which the number of children varies. • In a file system, a node represents each file, and if the file is a directory, then it is an internal node whose children are the files contained in the directory. Some file systems do not restrict the number of files per folder, implying that the number of children per node is varying and unbounded. • In computational linguistics, as sentences are parsed, the parser creates a representation of the sentence as a tree whose nodes represent grammatical elements such as predicates, subjects, prepositional phrases, and so on. Some elements such as subject elements are always internal nodes because they are made up of simpler elements such as nouns and articles. Others are always leaf nodes, such as nouns. The number of children of the internal nodes is unbounded and varying. • In genealogical software, the tree of descendents of a given person is a general tree because the number of children of a given person is not fixed. Spanning Trees Given a connected graph G, a spanning graph of G that is a tree is called a spanning tree. A spanning tree for an undirected graph G = (V,E) is a graph G’ = (V,E’) such that G’ is a tree. In other words, G’ has the same set of vertices, but edges have been removed from E so that the resulting graph is a tree. This amounts to saying that G’ is acyclic. If G is directed, it means that cycles have been removed. Since a tree with V vertices has V1 edges, to generate a spanning tree of a connected graph G having V vertices and E edges we must delete all but (V1) edges from the G. We cannot do that randomly because it has to be a tree which is acyclic and connected. We must delete E(V1) = EV+1 edges, none of which is a bridge. A graph G can have several spanning tree. Removal of any single edge from a spanning tree causes the graph to be unconnected. For any spanning tree T of graph G, if an edge e that is not in T is added, a cycle is created. And also see one thing if we add any edge from ~G, we will also create a cycle. Minimum Spanning Trees A spanning tree is minimum if there is no other spanning tree with smaller cost. If the graph is unweighted, then the cost is just the number of edges. If it has weighted edges, then the cost is the sum of the edge weights of the edges in the spanning tree. An example of an application of spanning trees is for finding the least wiring to wire the electrical connections in a building. A weighted graph and one of its minimum spanning trees: Figure 1 Figure 2 A relatively simple algorithm for finding a minimum spanning tree is Kruskal’s Algorithm. It is a greedy algorithm in that it always tries to find the best solution at each step. Not all greedy approaches work. Here it does. It uses the UnionFind algorithm from Chapter 8. Kruskal’s Algorithm The strategy of this algorithm is continually to select the edges in order of smallest weight and accept an edge if it does not cause a cycle. The idea is to start out with a forest in which each vertex is a tree by itself. Then look for the edge with least weight and connect its two vertices into a tree with two vertices. Find the next smallest weight edge and connect the two vertices together if they are not already in a tree together. If they are in the same tree, then adding this edge would form a cycle, so the edge should not be added. If we continue this process until there is just one tree, then this tree will be minimum cost because the edges were added in order of ascending cost. The algorithm treats the trees like sets of vertices. To form a new tree the union operation is used. A disjoint set ADT is used to represent the vertices. A heap is used for picking the minimum edge at each step. Kruskal’s Algorithm void kruskal() { int edgesAccepted; DisjointSet s(NUM_VERTICES ); PriorityQueue h( NUM_EDGES ); Vertex u,v; SetType uset, vset; Edge e; readGraphIntoHeapArray(h); h.buildHeap(); edgesAccepted = 0; while ( edgesAccepted < NUM_VERTICES –1 ) { h.deleteMin( e ); // assume e = (u,v) uset = s.find(u); vset = s.find(v); if ( uset != vset ) { // add the edge edgesAccepted++; s.union(uset, vset); }}} The algorithm takes roughly O(E log V ) time. Figure 3 shows action of Kruskal’s algorithm on graph G. Edge Weight Action (V1,V4) 1 Accepted (V6,V7) 1 Accepted (V1,V2) 2 Accepted (V3,V4) 2 Accepted (V2,V4) 3 Rejected (V1,V3) 4 Rejected (V4,V7) 4 Accepted (V3,V6) 5 Rejected (V5,V7) 6 Accepted Figure 3 Figure 4 KDeficient Vertices of spanning Trees A vertex v in a spanning tree T of graph G is called kdeficient if its degree satisfies the equation deg G(v) – deg T(v) = k. The integer k is called the deficiency of vertex. If k = 0, v is a degree preserving vertex that is deg G(v) = deg T(v). Observe that for any kdeficient vertex of a nontrivial tree T, we have k<= ^(G) 1, since deg T(v) > 0. KDeficient Vertices Theorem 3.3 Let G be a connected graph on n vertices and q edges. Then the sum of the deficiencies of the vertices of any spanning tree of G is 2(qn+1). Proof Let T be a spanning tree of G. Since the deficiency of a vertex v e V(T) is deg G(v) – deg T(v), the sum of the deficiencies of the vertices of T may be obtained by adding the degrees of the vertices in G and then subtracting the sum of the degrees in T. We know that the sum of the degrees of the vertices in G is 2q. Since T has n1 edges, the sum of the degrees of the vertices in T is 2(n1). The difference is 2q2(n1) = 2(qn+1). Real life application of spanning trees Suppose that a county needs to build a passenger railroad to serve its eight major towns. Joining all (8:2) pairs of town directly would be too expensive and wasteful; railroad tracks would clutter the county. Using spanning tree we are able to design the rail system in such a way that, using the system a person can travel from each of the eight towns to any of the others. It will be cost effective and efficient. 
