You are on page 1of 4

5/28/2021

CSE307 – Introduction to Artificial Intelligence


HW #1
Date: 9th February 2021
Due Date: 16th February 2021, 11pm.
Marks: 5

A. Consider the ‘frog puzzle’ as described (and available for play) at:
https://primefactorisation.com/frogpuzzle/

“N frogs are trying to cross a pond by jumping between stones. Green frogs are
heading right; while Blue frogs are heading Left. Each frog can jump just onto an
empty stone in front, or jump over the opposing frog if there is an empty stone
behind it. The frogs are stubborn, however, and are not willing to change
direction.”

Create the search tree (by hand, no coding required in this part) for this puzzle
with N=4 (2 Green and 2 Blue frogs) using the following notation:
 1 represents a Green frog
 2 represents a Blue frog
 0 represents an empty stone
The root of the tree is 11022 and the goal is 22011.

Use the following as an example of your response, shown for N=2. (Try to show
right branches for right-movements, and left branches for left-movements).

i. How many dead-ends (i.e. a node with no further jumps possible to get to the
goal) did you find? (Note there are no dead-ends in N=2 case)
ii. How many groups of states were duplicated? Circle these.

This part should be written up in a Word or PowerPoint document which may


have your scans of handwritten responses.

CSE307: ItoAI-Spring 2021-HW#1 1


5/28/2021

B. In this part you need to make a new search algorithm that combines BFS and
DFS. As we know BFS has the problem that if the number of branches is very
large the space complexity is O(bs). In order to combine the best of both
approaches, your program should take an input graph and a number ‘b’ which
indicates the maximum branches allowed for the BFS portion, and combine the
two BFS/DFS algorithms as follows:
 Start the algorithm to traverse the tree using BFS.
 However, if the number of branches at any level is greater than ‘b’, then your
algorithm should switch to DFS.
 If the number of branches at any level is equal to ‘b’ or less, it should switch
back to BFS.

You should refer to the BFS/DFS code given at:


https://www.educative.io/edpresso/how-to-implement-a-breadth-first-search-in-python
https://www.educative.io/edpresso/how-to-implement-depth-first-search-in-python

You must use these as baseline codes to come up with a new search algorithm as
follows (Again, you must use the above baseline codes and extend these and not
devise a completely different approach).

Following are 2 examples:

CSE307: ItoAI-Spring 2021-HW#1 2


5/28/2021

Your program will be checked by


an autograder and must follow the following instructions exactly:
i) Create a python function with the following signature (the function name is case-
sensitive):
bds(graph, b, startNode)
ii) Use adjacency list to store the graph in the form of python dictionary,” e.g.:
graph = {
'A' : ['B','C','D'],
'B' : ['E', 'F'],
'C' : [],
'D' : [],
'E' : ['G','H','I'],
'F' : [],
'G' : ['J'],
'H' : [],
'I' : [],
'J' : []
}

iii) E.g. when called using the above graph and: bds(graph, 2, ‘A’), your
function should return the order of visited nodes (and nothing else):

ABEFGJHICD

 Your function should work for any given graph and value of ‘b’ and startNode.
 Your function should return a string, with space-separated nodes in order they
were visited. No other output should be there.
 Also make sure there are no leading or trailing spaces in the string, use
“string”.strip() function if required to remove spaces.
 Do not print the string in your function, just return the resultant string.
 Do not include inverted commas, period, or any other character in your string.
 Nodes should be visited from left to right in adjacency list, e.g.:
E.g. In 'A' : ['B','C','D'], node B should be visited first and not node D

Please note your program will be autograded against several graphs of different
sizes with varying values of ‘b’, and so the output should work for the general
case and be in exactly the above form or else marks will not be given.

CSE307: ItoAI-Spring 2021-HW#1 3


5/28/2021

C. Submission instructions:

 Save Word or scanned document as:


HW#.<Part#>-<ERP no>-<Your First Name*>.docx, e.g. “HW1.A-01234-Awais.docx”

 Save your python code as follows:


HW#.<Part#>-<ERP no>-<Your First Name>.py, e.g. “HW1.B-01234-Awais.py”

 Zip all the above parts into a single zip file with the following name:
HW#-<ERP no>-<Your First Name >.zip, e.g. “HW1-01234-Awais.zip”

 Upload this single Zip file in LMS


(Do not upload multiple files)

 Please follow the above instructions for file names exactly, or marks will be
deducted.

* Your first name can be replaced by your middle/last name by which you are normally called.
You should use this in all your future assignments.

Finally, note that while you can verbally discuss your solutions with your colleagues,
please write your own code. In case of ANY cheating/copying of assignments,
both/all parties will receive ‘0’ marks.

CSE307: ItoAI-Spring 2021-HW#1 4

You might also like