



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The reason we cover both depth and breadth first search methods in the same tutorial is because they are both similar. In depth first search, newly explored nodes were added to the beginning of your Open list. In breadth first search, newly explored nodes are added to the end of your Open list. BFS is level wise searching mechanism.
Typology: Lab Reports
1 / 6
This page cannot be seen from the preview
Don't miss anything!




#include using namespace std; #define MAX 100 int n; int adj[MAX][MAX]; int state[MAX]; int queue[MAX], front = -1, rear = -1; void BFS(int v); void insert_queue(int v);
cout<<v<<" "; state[v] = 3; //Visited State for(int i=0; i<n; i++){ if(adj[v][i] == 1 && state[i] == 1){ insert_queue(i); state[i] = 2; } } } cout<<"\n"; } void insert_queue(int v){ if(rear == MAX-1){ cout<<"Queue Overflow!\n"; } else { if (front == -1){ front = 0; } rear = rear + 1; queue[rear] = v; } } int delete_queue(){ int delete_item; if(front == -1 || front > rear) { cout<<"Queue Underflow\n"; return 0;; } delete_item = queue[front]; front = front+1; return delete_item; } bool isEmpty_queue(){ if(front == -1 || front > rear) return true; else return false; } int main(){ createGraph();
apply_BFS(); return 0; }