10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

Algorithm 1 (Kruskal):<br />

1) Order the edges by increasing weight.<br />

2) Add the edge ei if it does not produce a cycle. Ignore if it does.<br />

3) Stop when the (n‐1)‐st edge is added.<br />

The following description explains what this algorithm does:<br />

At any given stage we have a collection of disjoint trees (a forest). We add the<br />

cheapest edge that joins two distinct trees into a single tree. This is a GREEDY<br />

algorithm. The spanning tree produced is not unique. The initial state is just a<br />

collection of isolated vertices (trivial trees).<br />

Algorithm 2 (Prim)<br />

1) Choose an arbitrary vertex as your initial tree.<br />

2) To the current tree T add an edge (g,t) where g G\T , t T and the<br />

edge (g,t) chosen is the cheapest possible.<br />

3) Stop when T has all vertices or no more edges are available.<br />

Shortest Path<br />

Another common application used with graph requires that we find the shortest<br />

path between tow vertices in a network. For example, if the network<br />

represents the routes flown by an airline, when we travel we would like to find<br />

the least expensive route between home and our destination.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 98 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!