AI Mids
AI Mids
AI Mids
Instructor: Engr. DARAKHSHAN SYED, Engr. SYED SAFDAR HUSSAIN, DR. AARIJ MAHMOOD HUSSAAN ‐,
Submission Date: 29th November 2020
1. Write your answers in a Word file and upload the file before the due date on BlackBoard.
2. Write your name and registration ID on the first page of your Word file.
3. Answer scripts can be uploaded on BlackBoard any time before its deadline.
Therefore, do not wait for the last hour to avoid any unforeseen problems.
4. Submission of answer copy(ies) will be considered acceptable through BlackBoard
only. Therefore, do not submit your document through email or any other medium.
5. Use 12 pt. font size and Times New Roman font style along with 1-inch page margins.
6. Follow the requirements of the word limit and the marking criteria while writing your
answers
7. Provide relevant, original and conceptual answers, as this exam aims to test your ability to
examine, explain, modify or develop concepts discussed in class.
8. Do not copy answers from the internet or other sources. The plagiarism of your answers
may be checked through Turnitin.
9. Recheck your answers before the submission on BlackBoard to correct any content or
language related errors.
Page 1 of 22
Page 2 of 22
10. Double check your word file before uploading it on BlackBoard to ensure that you have
uploaded the correct file with your answers.
Solution:
An agent is a system that is situated in an environment.it is capable of perceiving its environment,and it is
capable of acting in its environment with the goal of satisfying its design objectives.anything that can be
viewed as perceiving its environment through sensors and sensors acting upon the environment through
actuators.
utility based agents is a model based,goals alone are not really enough to generate high quality behaviour
is most environments.goals just provide a crude binary distinction between happy and unhappy
states,where as a more general performance measure should allow a comparision of different world states
according to exactly how happy they would make the agent if they could be achieved.
a utility function maps a state onto a real number,which describes the associated degree of happiness.a
complete specification of the utility function allows rational decisions in cases where goals are inadequate.
->the utility function measures its preferences among states of the world.then it chooses the action that
leads to the best expected utility,where expected utility is computed by averaging overall possible outcome
states,weighted by the probability of the outcome.
->goal based agents decide s its actions based on goal whereas utility based agents decide its actions
based on utilities.goal based agents are more flexible whereas utility based agents are less flexible.
->it is important to know that an intelligent agent is one that can make decisions based on the
environment.it makes decisions based on the maximum utility of its choices and it collects information and
there are several types.it is an agent that acts based not only on what the goal is,but the best way to reach
that goal.
->learning agent in artificial intelligence is the type of agent which can learn from its past experiences or its
has learning capabilities.it has different components,those are:learning element,critic,performance
element,problem generator.these are the working of the different components of the agents.
Page 2 of 22
Page 3 of 22
• You have to move the red block in order to the exit. You can move horizontal blocks
from side to side You can move vertical blocks up and down.
• Your representation of the game should take into account that the grid size i.e. the number
of rows and columns would be as follows:
o number of rows >= 7 o
number of columns >= 8
• There could be an arbitrary number of blocks in the puzzle, however, the puzzle will
always have a solution
• The puzzle could also have many solutions
• You will be given the best possible solution
• Every slide will cost +1
a) Describe the agent using the PEAS framework. Also describe the characteristics of the
task environment.
b) Model this game as a search problem. You have to describe the following:
i. Data
structure to be used
to represent the
state
ii. State
space iii.
Initial State iv.
Successor
Function
v. Actions
vi. Goal Test
Page 3 of 22
Page 4 of 22
c)Use the following puzzle to show the working of the BFS and IDS for upto depth = 3.
Show the contents of the frontier list, and the selected node at every step.
c) Develop two admissible heuristics for this problem. Also show that they are admissible.
d) Use the heuristics developed in part (e) to run A* search and Greedy Search to a depth =
5. Show the contents of the frontier list, and the selected node at every step.
e) Describe in your words why UCS is optimal
Solution:
a) Performance measure
b) Environment
c) Actuators
d) Sensors
>> Performance measure can be profit made by him , safe ride for his customers, comfortable and fast
ride.
Page 4 of 22
Page 5 of 22
>> Sensors are speadometer, air bag senson, camera, break sensors.
Class Main {
public void bfs()
{
// BFS uses Queue data structure
Queue queue = new LinkedList();
queue.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited = true;
while(!queue.isEmpty()) {
Node node = (Node)queue.remove();
Node child=null;
while((child=getUnvisitedChildNode(node))!=null) {
child.visited=true;
printNode(child);
queue.add(child);
}
}
// Clear visited property of nodes
clearNodes();
}
public void dfs() {
// DFS uses Stack data structure
Stack stack = new Stack();
stack.push(this.rootNode);
rootNode.visited=true;
printNode(rootNode);
while(!stack.isEmpty()) {
Node node = (Node)s.peek();
Node child = getUnvisitedChildNode(n);
if(child != null) {
child.visited = true;
printNode(child);
s.push(child);
}
else {
Page 5 of 22
Page 6 of 22
s.pop();
}
}
// Clear visited property of nodes
clearNodes();
}
}
Class Node {
Char data;
Public Node(char c) {
this.data=c;
}
}
#include<iostream>
//node declaration
struct node
int info;
}*start;
/*
* Class Declaration
*/
class single_llist
Page 6 of 22
Page 7 of 22
public:
node* create_node(int);
void insert();
void delete_pos();
void search();
void display();
single_llist()
start = NULL;
};
/*
*/
int main()
single_llist sl;
start = NULL;
while (1)
Page 7 of 22
Page 8 of 22
cout<<endl<<"---------------------------------"<<endl;
cout<<endl<<"---------------------------------"<<endl;
cout<<"1.Add a node."<<endl;
cout<<"2.Delete a node."<<endl;
cout<<"3.Search a node."<<endl;
cout<<"4.Display a node."<<endl;
cout<<"5.Exit "<<endl;
cin>>choice;
switch(choice)
case 1:
sl.insert();
cout<<endl;
break;
case 2:
sl.delete_pos();
break;
case 3:
Page 8 of 22
Page 9 of 22
sl.search();
cout<<endl;
break;
case 4:
sl.display();
cout<<endl;
break;
case 5:
cout<<"Exiting..."<<endl;
exit(1);
break;
default:
cout<<"Wrong choice"<<endl;
//create a node
Page 9 of 22
Page 10 of 22
if (temp == NULL)
return 0;
else
temp->info = value;
temp->next = NULL;
return temp;
//add a node
void single_llist::insert()
int value;
cin>>value;
temp = create_node(value);
if (start == NULL)
Page 10 of 22
Page 11 of 22
start = temp;
start->next = NULL;
else
p = start;
start = temp;
start->next = p;
//delete a node
void single_llist::delete_pos()
if (start == NULL)
cout<<"List is empty"<<endl;
return;
Page 11 of 22
Page 12 of 22
cin>>pos;
s = start;
if (pos == 1)
start = s->next;
else
while (s != NULL)
s = s->next;
counter++;
s = start;
ptr = s;
s = s->next;
Page 12 of 22
Page 13 of 22
ptr->next = s->next;
else
free(s);
cout<<"Element Deleted"<<endl;
//display a node
void single_llist::display()
if (start == NULL)
return;
temp = start;
Page 13 of 22
Page 14 of 22
cout<<temp->info<<"->";
temp = temp->next;
cout<<"NULL"<<endl;
//search a node
void single_llist::search()
if (start == NULL)
cout<<"List is empty"<<endl;
return;
cin>>value;
s = start;
while (s != NULL)
Page 14 of 22
Page 15 of 22
pos++;
if (s->info == value)
flag = true;
Calcudoku puzzles are similar to Sudoku, but also require some basic math skills to solve.
(https://www.calcudoku.org/en/2020-11-20/6/1)
I. the 4×4 puzzle uses the numbers 1-4, the 6×6 the numbers 1-6, and so on
II. in each row and in each column each digit can appear only once (just like in Sudoku)
III. each "cage" (the blocks with the thick border) shows a result and an operation (addition:
+, subtraction: -, multiplication: ×, or division: :). The operation applied to the numbers
in the cage should produce the result shown. Note that for subtraction and division the
order is not fixed (!)
More about this type of Sudoku can be found over the internet
Page 15 of 22
Page 16 of 22
https://en.wikipedia.org/wiki/KenKen. Do not worry you are not going to be asked to solve the
puzzle here. However, you are required to answer the following questions:
Executioner Sudoku is a riddle that joins components of sudoku and kakuro. In spite of the name, the
more straightforward executioner sudokus can be simpler to understand than ordinary sudokus,
contingent upon the solver's ability at mental number-crunching; the hardest ones, nonetheless, can take
hours to break.
An ordinary issue is appeared on the right, utilizing hues to characterize the gatherings of cells. All the
more frequently, puzzles are imprinted clearly, with slender spotted lines used to layout the "confines".
The goal is to fill the framework with numbers from 1 to 9 out of a way that
* Each line, segment, and nonet contains each number precisely once.
* The aggregate of all numbers in an enclosure must match the modest number printed
in its corner.
* No number shows up more than once in a pen. (This is the standard guideline
for executioner sudokus, and suggests that no confine can incorporate more
than 9 cells.)
Complexity- In the event that we are to illuminate Sudoku utilizing a bruteforce strategy, our calculation
would need to attempt each accessible number over every vacant cell. Such a calculation would have a
runtime unpredictability of O(N^(N²)), where n is the size of the Sudoku puzzle. For a 9x9 Sudoku puzzle
(N = 9), the calculation would perform 2*10⁷⁷ tasks to discover an answer. That would not be
commonsense. Practically speaking, the runtime would differ as per the trouble of the riddle itself and
the quantity of choices for each unfilled cell. For instance, a 17-piece of information puzzle with slanting
Page 16 of 22
Page 17 of 22
evenness is one of the hardest to tackle because of an enormous number of up-and-comers and
branches.
In 'Executioner X', an extra standard is that every one of the long diagonals
215647398
368952174
794381652
586274931
142593867
973816425
821739546
659428713
437165289
Page 17 of 22
Page 18 of 22
Page 18 of 22
Page 19 of 22
Page 19 of 22
Page 20 of 22
Page 20 of 22
Page 21 of 22
Page 21 of 22