Exercise Set - 1
Exercise Set - 1
Exercise Set - 1
1. Assume that you will be given an undirected graph represented as an adjacency list and a
starting vertex. Implement a function BFS(graph, start) that performs Breadth-First
Search starting from the given vertex. The function should return a list of vertices visited
in BFS order.
2. Assume that you will be given an undirected graph represented as an adjacency list and a
starting vertex. Implement a function DFS(graph, start) that performs Breadth-First
Search starting from the given vertex. The function should return a list of vertices visited
in DFS order.
3. The Missionaries and Cannibals problem is a classic river-crossing puzzle that involves
moving missionaries and cannibals from one side of a river to the other. The challenge is
to find a sequence of moves that allows all missionaries and cannibals to cross without
violating certain rules. The rules usually include constraints on the number of
missionaries and cannibals on each side of the river, and ensuring that the cannibals don't
outnumber the missionaries on either side.
Create an implementation of the Missionaries and Cannibals problem using a simple BFS
algorithm in Python.
1
School of Computer Science Engineering & Information Systems
4. The 8-Queens problem is a classic problem in computer science. The goal is to place
eight queens on a chessboard in such a way that no two queens threaten each other. This
means that no two queens can be in the same row, column, or diagonal.
Make an implementation of the N-Queens problem in Python using a backtracking
algorithm:
5. Uniform Cost Search (UCS) is a search algorithm that explores a weighted graph by
expanding the least-cost node. It is often used for finding the shortest path in a graph with
non-negative edge weights.
Make an implementation of the Uniform Cost Search algorithm in Python.
7. Depth Limited Search is a modified version of DFS that imposes a limit on the depth of
the search. This means that the algorithm will only explore nodes up to a certain depth,
effectively preventing it from going down excessively deep paths that are unlikely to
lead to the goal. By setting a maximum depth limit, DLS aims to improve efficiency
and ensure more manageable search times.
Make an implementation of the Depth Limited Search in Python.