2 Replies - 1991 Views - Last Post: 11 November 2011 - 05:20 AM Rate Topic: -----

#1 born2c0de   User is offline

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

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

Depth First Search Graph Traversal

Posted 10 June 2008 - 07:40 AM

Description: Implements Depth 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 MAX 5

int dfs(int adj[][MAX],int visited[],int start)
{
    int stack[MAX];
    int top=-1,i;
    
    printf("%c-",start+65);
    visited[start]=1;
    stack[++top]=start;
    while(top!=-1)
    {
                  start=stack[top];
                  for(i=0;i<MAX;i++)
                  {
                                    if(adj[start][i]&&visited[i]==0)
                                    {
                                                                   stack[++top]=i;
                                                                   printf("%c-",i+65);
                                                                   visited[i]=1;
                                                                   break;
                                    }
                  }

                  if(i==MAX)
                          top--;
    }
    return 0;
}

int main()
{

    int adj[MAX][MAX]={{0,0,1,1,0},{0,0,0,0,0},{0,1,0,1,1},{0,0,0,0,1},{0,0,0,1,0}};
    int visited[MAX]={0};

    printf("DFS Traversal : ");
    dfs(adj,visited,0);
	printf("n");
    
    return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Depth First Search Graph Traversal

#2 shivan87   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-November 11

Re: Depth First Search Graph Traversal

Posted 07 November 2011 - 10:24 AM

why you used Adjacency Matrix and what is his important?? please can u comment on ur code?? i need DLS(depth limited search).
Was This Post Helpful? 0
  • +
  • -

#3 shivan87   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-November 11

Re: Depth First Search Graph Traversal

Posted 11 November 2011 - 05:20 AM

send me Depth Limited Search for this : [email protected] please, please, please
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1