Home Page
Cis 561 Unit 1 Research Paper
Cis 561 Unit 1 Research Paper
1131 Words
5 Pages
CIS 561 Project Deliverable 1: General Search Algorithm and Framework Submitted by : Arsalan Hafiz(01498800) 1. Build a search framework that implements the general graph search algorithm (Figure 3.7 in textbook), with the following search strategies: Breath-first, Depth-first, Depth-limited, and Iterative Deepening Search. Breadth First Search: #include #include using namespace std; class Graph { int V; list *adj; public: Graph(int V); void addEdge(int v, int w); void BFS(int s); }; Graph::Graph(int V) { this->V = V; adj = new list[V]; } void Graph::addEdge(int v, int w) { adj[v].push_back(w); // Add w to v’s list. } void Graph::BFS(int s) { bool *visited = new bool[V]; for(int i = 0; i < V; i++)
…show more content…
g.addEdge(2, 0); g.addEdge(2, 3); g.addEdge(3, 3); cout << "Following is Breadth First Traversal (starting from vertex 2) \n"; g.BFS(2); return 0; } Output: DEPTH FIRST SEARCH: #include #include using namespace std; class Graph { int V; list *adj; void DFSUtil(int v, bool visited[]); public: Graph(int V); void addEdge(int v, int w); void DFS(int v); }; Graph::Graph(int V) { this->V = V; adj = new list[V]; } void Graph::addEdge(int v, int w) { adj[v].push_back(w); } void Graph::DFSUtil(int v, bool visited[]) { visited[v] = true; cout << v << " "; list::iterator i; for(i = adj[v].begin(); i != adj[v].end(); ++i) if(!visited[*i]) DFSUtil(*i, visited); } void Graph::DFS(int v) { bool *visited = new bool[V]; for(int i = 0; i < V; i++) visited[i] = false; DFSUtil(v, visited); } int main() { Graph g(4); g.addEdge(0, 1); g.addEdge(0, 2); g.addEdge(1, 2); g.addEdge(2, 0); g.addEdge(2, 3); g.addEdge(3, 3); cout << "Following is Depth First Traversal (starting from vertex 2) \n"; g.DFS(2); return 0; } Output: DEPTH LIMITED
Show More
Related
More about Cis 561 Unit 1 Research Paper
Popular Essays
Pain Management: Article Analysis
On Revolution Hannah Arendt
Analyzing Katie's Argument Against Global Climate Change
Rhetorical Analysis Of 'What The Buddha Taught'
Winnie Wong Research Paper
The Most Dangerous Game Literary Analysis
Open Document