# Breadth First Search Graph Traversal

Page 1 of 1

## 5 Replies - 1615 Views - Last Post: 09 March 2011 - 02:24 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=364265&amp;s=e44487d52972eee6f61f91b28cee53f7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

# Breadth First Search Graph Traversal

Posted 10 June 2008 - 07:42 AM

Description: Performs Breadth First Search on a Graph stored as an Adjacency Matrix.
```/* Written by Sanchit Karve (born2c0de)
Contact me on born2c0de AT dreamincode DOT net
*/

#include <stdio.h>

#define N 10

{
int q[N],rear=-1,front=-1,i;
q[++rear]=start;
visited[start]=1;
while(rear != front)
{
start = q[++front];
if(start==9)
printf("10t");
else
printf("%c t",start+49); //change to 65 in case of alphabets

for(i=0;i<N;i++)
{
{
q[++rear]=i;
visited[i]=1;
}
}
}
}

int main()
{
int visited[N]={0};
{0,0,0,0,1,0,0,0,0,1},
{0,0,0,0,1,0,1,0,0,0},
{1,0,1,0,0,1,1,0,0,1},
{0,0,0,0,0,0,1,1,0,0},
{0,0,0,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,1,1,1},
{0,0,1,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,1,1,0}};

return 0;

}

```

Is This A Good Question/Topic? 0

## Replies To: Breadth First Search Graph Traversal

Reputation: 0
• Posts: 1
• Joined: 03-May 09

## Re: Breadth First Search Graph Traversal

Posted 03 May 2009 - 02:18 AM

plz add the graph u used ,i have to match it with the one made by me through the "adjancy matrix "taken by u.

### #3 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

## Re: Breadth First Search Graph Traversal

Posted 06 May 2009 - 04:09 AM

Can't you just create the graph from the adjacency matrix?

### #4 dranjan

Reputation: 0
• Posts: 0
• Joined: 11-July 09

## Re: Breadth First Search Graph Traversal

Posted 10 July 2009 - 11:52 PM

brother the adjacency matrix u hav made seems to be wrong at some places .. u r kindly requested to check it Eg. in the 10th row:vertex 10 seems to be connected to 3 , 8,9. but in 9th row:9 is only connected to 4. there are other nistakes like this one. please rectify them also.

Reputation: 0
• Posts: 0
• Joined: 06-September 10

## Re: Breadth First Search Graph Traversal

Posted 07 September 2010 - 11:32 PM

make it more user friendly. program still may some mistakes.

### #6 thebban

Reputation: 0
• Posts: 7
• Joined: 09-March 11

## Re: Breadth First Search Graph Traversal

Posted 09 March 2011 - 02:24 PM

that codes doesnt work, would u please check it again. it compiles but before it runs it says run-time error: at line 24 and 47. thanks