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 />

as shown in fig :f<br />

The adjacency matrix of the directed graph in fig:F is shown in fig :G:<br />

i \ j 1 2 3 4 5 6<br />

1 0 1 0 0 0 0<br />

2 0 1 1 0 0 0<br />

3 0 0 0 0 1 1<br />

4 0 0 1 0 0 0<br />

5 0 0 0 0 0 0<br />

6 0 0 0 0 0 0<br />

Fig :G<br />

In this representation we required nxn bits to represent a graph with n nodes .<br />

the adjacency matrix is a simple way to represent a graph ,but it has two<br />

disadvantages ;<br />

<strong>1.</strong> it takes o(nxn )space to represent a graph with n vertices,even for spars<br />

graph and<br />

2. it takes o(nxn)time to solve most of graph problem.<br />

ADJACENCY LIST REPRESENTATION:<br />

In this representation ,we store a graph as a linked structure. We store all the<br />

vertices in a list and then for each vertex ,we have a linked list of its adjacent<br />

vertices.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!