math trees1

36
TREES TREES

Upload: lee-kah-hou

Post on 07-Apr-2015

75 views

Category:

Documents


0 download

TRANSCRIPT

TREESTREES

PROPERTIES OF TREES

A Tree structure is a way of representing the hierarchical nature of a structure in a graphical form. In computer science, a tree is a widely-used data structurethat emulates a hierarchical tree structure with a set of linked nodes.

Mathematically, it is a tree, more specifically an arborescence: an acyclic connected graph where each node has zero or more children nodes and at most one parent node. Furthermore, the children of each node have a specific order.

DIFFERENCES BETWEEN BINARY TREE AND

COMPLETE BINARY TREE

BINARY TREE

A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element.

The "root" pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller "subtrees" on either side.

A null pointer represents a binary tree with no elements -- the empty tree.

The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each poin to a binary tree.

•THE BINARY TREE

A simple binary tree of size 9 and height 3, with a root node whose value is 2. The above tree is neither a sorted nor a balanced binary tree

2

7

926

411

5

5

COMPLETE BINARY TREE

May also be defined as a FULL BINARY TREE in which all leaves are at depth n or n-1 for some n.

In order for a tree to be the latter kind of complete binary tree, all the children on the last level must occupy the leftmost spots consecutively, with no spot left unoccupied in between any two.

A labeled binary tree containing the labels 1 to with root 1, branches leading to nodes labeled to nodes labeled 2 and 3, branches from these leading to 4, 5 and 6, 7, respectively, and so on.

The graph corresponding to the complete binary tree on nodes is implemented as CompleteBinaryTree [n] in the Mathematica package Combinatorica ` or CompleteKaryTree[n, 2] in the Mathematica package Combinatorica.

SPANNING TREE

A spanning tree T of a connected, undirected graph G is a tree composed of all the vertices and some (or perhaps all) of the edges of G.

A spanning tree of G is a selection of edges of G that form a tree spanning every vertex.

Every vertex lies in the tree, but no cycles (or loops) are formed.

Every bridge of G must belong to T.A spanning tree of a connected graph G

can also be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices.

Useful to find a minimum spanning tree of a weighted graph.

A minimum spanning tree (MST) or minimum weight spanning tree is then a spanning tree with weight less than or equal to the weight of every other spanning tree.

More generally, any undirected graph (not necessarily connected) has a minimum spanning forest, which is a union of minimum spanning trees for its connected components.

Type of Spanning Tree

COUNTING OF SPANNING TREEThe number t(G) of spanning trees of a

connected graph is an important invariant. it is easy to calculate t(G) directly. It is also widely used in data structures in

different computer languages. For example,

if G = tree, then t(G)=1, if G = cycles graph Cn with n vertices, then t(G)=n. For any graph G, the number t(G) can be

calculated using Kirchhoff’s matrix-tree theorem

Carley’s formula is a formula for the number of spanning trees in the complete graph Kn with n vertices. The formula t(Kn) = nn − 2

Exactly nn − 2 vlabelled trees with n vertices Can be proved using Kirchhoff’s matrix-tree

theorem or via the Prüfer codeIf G = complete bipartite graph Kp,q,

t(G) = pq − 1qp − 1, while if G is the n-dimensional hypercube graph Qn, then . These formulae are also consequences of the matrix-tree theorem.

If G = multigraph and e is an edge of G, then the number t(G) of spanning trees of

G satisfies the deletion-contraction recurrence t(G)=t(G-e)+t(G/e),

where G-e is the multigraph obtained by deleting e and G/e is the contraction of G by e, where multiple edges arising from this contraction are not deleted.

PRIM’S ALGORITHM

Definition : An algorithm that finds a minimum spanning tree for a connected weighted undirected graph.

This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.

Prim's algorithm is an example of a greedy algorithm

Sometimes called the DJP algorithm, the Jarník algorithm, or the Prim-Jarník algorithm.

Prim's algorithm is essentially a minor variation of Dijkstra's algorithm (see Section ). To construct the spanning tree, the algorithm constructs a sequence of spanning trees , each of which is a subgraph of G. The algorithm begins with a tree that contains one selected vertex, say

The only spanning tree of the empty graph (with an empty vertex set) is again the empty graph.

The following description assumes that this special case is handled separately.The algorithm continuously increases the size of a

tree, one edge at a time, starting with a tree consisting of a single vertex, until it spans all vertices.

Input: A non-empty connected weighted graph with vertices V and edges E (the weights can be negative).

Initialize: Vnew = {x}, where x is an arbitrary node (starting point) from V, Enew = {}

Repeat until Vnew = V: Choose an edge (u, v) with minimal weight such

that u is in Vnew and v is not (if there are multiple edges with the same weight, any of them may be picked)

Add v to Vnew, and (u, v) to Enew

Output: Vnew and Enew describe a minimal spanning tree

IDENTIFY MINIMAL SPANNING TREE USING KRUSKAL ALGORITHM

KRUSKAL ALGORITHM

•KRUSKAL’S ALGORITHM FOR FINDING A MINIMAL SPANNING TREE IN A CONNECTED GRAPH IS A GREEDY ALGORITHM THAT IS GIVEN A CHOICE IT ALWAYS PROCESSES THE EDGE WITH THE LEAST WEIGHT.

• THIS ALGORITHM OPERATES BY CONSIDERING EDGES IN THE GRAPH IN ORDER OF WEIGHT FROM THE LEAST WEIGHTED EDGE UP TO THE MOST WHILE KEEPING TRACK OF WHICH NODES IN THE GRAPH HAVE BEEN ADDED TO THE SPANNING TREE.

• If an edge being considered joins either two nodes not in the spanning tree, or joins a node in the spanning tree to one not in the spanning tree, the edge and its end points are added to the spanning tree.

• After considering one edge the algorithm continues to consider the next higher weighed edge.

•The algorithm stops when all nodes have been added to the spanning tree.

•Kruskal can be working on many independent, non-connected sections of the trees. These sections will be joined before the algorithm completes.

•This algorithm is implemented using parent pointers and equivalence classes.

•Looping through the edges in order of weight, the algorithm groups the vertices together into one or more equivalence classes to denote that these nodes have been added to the solution minimal spanning tree.

CONCLUSION

The trees used in data structure can use in many ways.

The common uses of trees can be manipulate hierarchical data, make information easy to search (see tree traversal), manipulate sorted lists of data, as a workflow for compositing digital images for visual effects, router algorithms, and also form of a multi-stage decision-making.