Data Structures Notes

Monday, March 30, 2009

This algorithm comes under the greedy method, which means that the objects are chosen to join a growing collection by iteratively picking an object that minimizes some cost function.

Now, taking account of the above mentioned greedy method, the Prim-Jarnik's algorithm is similar to the Dijkstra's shortest-path algorithm to grow the Minimum Spanning Tree (MST) from a single cluster starting with a randomly chosen single root vertex.

The Prim-Jarnik's algorithm can be broken down as follows:Step 1: Define the starting "cloud" of vertices [C] by selecting some random vertex [v] initiallyStep 2: Iteratively choose a min-weight edge [e=(v,u)], thereby connecting a vertex [v] in the cloud [C] to a vertex [u] outside of [C]. After choosing [e] the vertex [u] is brought into the cloud [C] continuously until a spanning tree emerges.

// Initialise a priority queue Q with an entry ((u,null),D[u]) for each vertex [u],// where (u,null) is the element & D[u] in the keywhile Q is not empty do (u,e) Add vertex u and edge e to T

// Perform the relaxation procedure on the edge of the vertex [z] adjacent to [u]For each vertex z adjacent to u such that z is in Q do if W((u,z)) <> D[z] Change to (z,(u,z)) the element of vertex z in Q Change to D[z] the key of vertex z in Qreturn the tree T

This algorithm comes under the greedy method, which means that the objects are chosen to join a growing collection by iteratively picking an object that minimizes some cost function.

Now, taking account of the above mentioned greedy method, the Kruskal's algorithm with a graph considers the edges in order of their weights to grow the Minimum Spanning Tree (MST) in clusters.

The Kruskal's algorithm can be broken down as follows:Step 1: In a given undirected graph [G] consider each vertex is in its own cluster all by itself i.e. if a [G] has four vertices then you have four cluster initiallyStep 2: Look for each edges in turn, ordered by increasing weight i.e. arrange all the edges in ascending orderStep 3: Start with the smallest weighing edge. If this edge connects two different clusters then it is considered as the min-weight "bridge" edge [e] and added to the set of edges of the MST. In this initial stages, due to addition of [e] to the MST (i.e. the growth of the MST), the two clusters then are merged into a single cluster. However, if a given [e] connects to two vertices that are already in the identified cluster then this [e] is discarded.Step 4: Now iteratively the algorithm adds enough [e] to a set of edges of spanning tree, it terminates and outputs this tree as the MST.

Spanning Tree - A tree that contains every vertex of a connected graph G is referred to as a spanning tree. The below figure depicts the Finnish intercity roadways route as a sapnning tree.

Minimum Spanning Tree (MST) - the problem of computing a spanning tree with the smallest total weight is known as the Minimum Spanning Tree problem. The below figure depicts the MST that houses a collection of smallest weighted routes between the Finnish cities. Routes not taken into the MST are: 177,381,409.

Friday, March 27, 2009

The binary tree are applicable in the below mentioned fields:- Used in the compilers of high-level programming languages for intermediate representation- Used as a searching technique- Used in databases for storing data- To solve arithmetic expressions

A binary tree embodies a finite set of data items that is either empty or partitioned into three disjoint subsets. The first part contains a single data item referred to as the root of the binary tree, other two data items are left and right subtrees. These data items is referred to as nodes of the binary tree.

From this figure we can portray the following:A - Root node of the binary treeA - Parent node of the nodes B & CB & C - Children nodes of A and these nodes are in a level one more than the root node AC - Right child node of AB - Left child node of AD & E - These node are without a child, so they are referred to as leafs or external nodesB & C - These nodes have a child each, so they are referred to as internal nodes

Depth of this binary tree - The longest path from the root node A to any leaf node, for example D node. Therefore, the depth of this binary tree is two.Indegreeof a node - The number of edges merging into a node. For example, indegree of the node B is one i.e. one edge merges.Outdegreeof a node - The number of edges coming out from a node. For example, outdegree of the node A is two i.e. two edges comes out of this root node.

A strictly binary tree of depth 'd' in which all the leaves are at level 'd' i.e. there is non empty left or right subtrees and leaves are populated at the same level.In a complete binary tree all the internal nodes have equal degree, which means that one node at the root level, two nodes at level 2, four nodes at level 3, eight nodes at level 4, etc, which the below figure represents: