DFS Program
DFS Program
h>
#include <stdbool.h>
#include <stdlib.h> // Added this line for malloc
// Graph DFS Implementation
#define MAX_VERTICES 8
// Adjacency Matrix Representation
int graph[MAX_VERTICES][MAX_VERTICES] = {
{0, 1, 1, 0, 0, 0, 0, 0},
{1, 0, 0, 1, 1, 0, 0, 0},
{1, 0, 0, 0, 0, 1, 0, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 1, 0}
};
bool visited[MAX_VERTICES] = {false};
// Graph DFS Function
void graphDFS(int vertex) {
// Mark current vertex as visited
visited[vertex] = true;
printf("%d ", vertex);
// Visit root
printf("%d ", root->data);
int main() {
// Graph DFS Demonstration
printf("Graph DFS Traversal: ");
graphDFS(0); // Start DFS from vertex 0
printf("\n");
return 0;
}