answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

char que[20];

int front=0, rear=0, n;

char arr[20];

int bfs(int );

char ajMat[20][20];

char b[20];

void display();

int p=0;

int main()

{

char v;

printf("Enter the number of nodes in a graph");

scanf("%d",&n);

printf("Enter the value of node of graph");

for(int i=0; i<n; i++)

{

scanf("%s",&b[i]);

}

printf("Enter the value in adjancency matrix in from of 'y' or 'n'\n");

printf("If there exits an edge between two vertices than 'y' otherwise 'n'\n");

for(int i=0; i<n; i++)

printf(" %c ",b[i]);

for(int i=0;i<n; i++)

{

printf("\n%c ",b[i]);

for(int j=0; j<n; j++)

{

printf("%c ",v=getch());

ajMat[i][j]=v;

}

printf("\n\n");

}

for(int i=0;i<n;i++)

bfs(i);

display();

getch();

}

void display()

{

printf("BFS of Graph : ");

for(int i=0; i<n; i++)

printf("%c ",arr[i]);

}

void insert(char val)

{

que[front]=val;

front++;

}

char del()

{

rear=rear+1;

return que[rear-1];

}

bool unVisit(char val)

{

for(int i=0; i<front; i++)

{

if(val==que[i])

return false;

}

return true;

}

int bfs(int i)

{

char m;

if(front==0)

{

insert(b[i]);

}

for(int j=0; j<n; j++)

{

if(ajMat[i][j]=='y')

{

if(unVisit(b[j]))

{

insert(b[j]);

}

}

}

m=del();

arr[p]=m;

p++;

return 0;

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is the advantages of depth first search?

advantages of depth first search?


How do you implement depth limited search to show how it alleviates failure of depth first search?

Depth-limited search (DLS) restricts the depth of a depth-first search by specifying a maximum depth limit. This prevents the algorithm from going too deep into the search tree, which can lead to infinite loops in cases where a solution is not present or in infinite-depth trees. By enforcing a depth limit, DLS ensures that the search remains manageable and terminates after a certain depth, thus reducing the risk of failure due to excessive recursion or stack overflow. If a solution exists within the specified depth, DLS will find it; otherwise, it will return a failure indication without going indefinitely.


Difference between breadth first and depth first search in artificial intelligence?

diference between depth first search and breath first search in artificial intelellegence


What is the space complexity of Depth First Search (DFS) algorithm?

The space complexity of Depth First Search (DFS) algorithm is O(bd), where b is the branching factor and d is the maximum depth of the search tree.


How to detect binary search tree as depth first search or breadth first search?

O(N-1)


What is the difference between breadth first search and depth first search in C programming?

Both algoritms can be build very similary. The difference between breadth-first search and depth-first search is order in which elements ar added to OPEN list. In breadth-first search new nodes are appended to the end of OPEN list In depth-first search new nodes are inserted in the begining of OPEN list


What is the advantage of iterative deepening search over depth-first?

Iterative deepening effectively performs a breadth-first search in a way that requires much less memory than breadth-first search does. So before explaining the advantage of iterative deepening over depth-first, its important to understand the difference between breadth-first and depth-first search. Depth first explores down the tree first while breadth-first explores all nodes on the first level, then the second level, then the third level, and so on. Breadth-first search is ideal in situations where the answer is near the top of the tree and Depth-first search works well when the goal node is near the bottom of the tree. Depth-first search has much lower memory requirements. Iterative deepening works by running depth-first search repeatedly with a growing constraint on how deep to explore the tree. This gives you you a search that is effectively breadth-first with the low memory requirements of depth-first search. Different applications call for different types of search, so there's not one that is always better than any other.


8 Queens Problem using Breadth First Search and Depth First Search?

1 3


Can i have the depth first search in c language?

yes


What are informed search techniques and uninformed search techniques?

&bull;Uninformed search strategies-Also known as "blind search," uninformed search strategies use no information about the likely "direction" of the goal node(s)-Uninformed search methods: Breadth-first, depth-first, depth-limited, uniform-cost, depth-first iterative deepening, bidirectional&bull;Informed search strategies-Also known as "heuristic search," informed search strategies use information about the domain to (try to) (usually) head in the general direction of the goal node(s)-Informed search methods: Hill climbing, best-first, greedy search, beam search, A, A*


What are the key differences between breadth-first search and depth-first search algorithms, and how do they impact the efficiency and performance of search algorithms?

Breadth-first search explores all neighbors of a node before moving on to the next level, while depth-first search goes as deep as possible before backtracking. Breadth-first search is more systematic and guarantees the shortest path, but requires more memory. Depth-first search is more memory-efficient but may not find the shortest path. The choice between the two depends on the specific problem and desired outcomes.


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.