Q-1 Q-1
(a)
(a) Solve The following Crypt arithmetic problem :Solve The following Crypt arithmetic problem : C R O S S C R O S S + R + R O O A D SA D S D E D E N G N G E RE R Ans : Ans :
D has to be 1 because when you
D has to be 1 because when you do your addition by hand:do your addition by hand: CROSS CROSS +ROADS +ROADS ---DANGER DANGER
You see that the D in DANGER must have be
You see that the D in DANGER must have be en carried over from the addition of C and R in en carried over from the addition of C and R in CROSSCROSS and ROADS, respectively. Thus, we h
and ROADS, respectively. Thus, we h ave:ave: CROSS CROSS +ROA1S +ROA1S ---1ANGER 1ANGER
This, by some fairly weird
This, by some fairly weird algebra and modular arithmetic, leads to algebra and modular arithmetic, leads to the following relationships:the following relationships: R = 2S mod 10 R = 2S mod 10 E = (3S + 1 - (2S mod 10)) mod 10 E = (3S + 1 - (2S mod 10)) mod 10 A = (C + 2R - (R + O mod 10)) mod 10 A = (C + 2R - (R + O mod 10)) mod 10 A = G - O mod 10 A = G - O mod 10 N = (R + 2O - (O + A mod 10)) mod 10 N = (R + 2O - (O + A mod 10)) mod 10 C = A - R mod 10 C = A - R mod 10 O = N - R mod 10 O = N - R mod 10 O = G - A mod 10 O = G - A mod 10 G = (O + A + S + 1 - (S + 1 mod 10)) mod 10 G = (O + A + S + 1 - (S + 1 mod 10)) mod 10
Obviously, this is of no help whatsoever to anyone, so we do
Obviously, this is of no help whatsoever to anyone, so we do trial and error.trial and error. So now we try things.
So now we try things. 12344 12344 +25614 +25614 ---3NO! D has to be 1 3NO! D has to be 1 92344 92344 +25614 +25614
---11NO! A cannot be 1 because D is 1 11NO! A cannot be 1 because D is 1
96233 96233 +62513 +62513 ---158746 158746 (b)
(b) Give the problem space for the following :Give the problem space for the following : (i)
(i) Monkey – Banana problemMonkey – Banana problem (ii)
(ii) Water – Jug problemWater – Jug problem Ans:
Ans: (i)
(i) Monkey – Banana problemMonkey – Banana problem
A monkey is in a cage and bananas are suspended f
A monkey is in a cage and bananas are suspended f rom the ceiling, the monkeyrom the ceiling, the monkey wants to eat a banana but cannot reach them
wants to eat a banana but cannot reach them –
– in the room are a chair and a stickin the room are a chair and a stick –
– if the monkey stands on the chair and waves the stick, he if the monkey stands on the chair and waves the stick, he can knock a bananacan knock a banana down to eat it
down to eat it
what are the actions the monkey should take? what are the actions the monkey should take? Initial state:
Initial state:
monkey on ground with empty hand bananas suspended monkey on ground with empty hand bananas suspended Goal state:
Goal state:
monkey eating bananas. monkey eating bananas. Actions:
Actions:
climb chair/get off climb chair/get off grab X grab X wave X wave X eat X eat X
(ii)
(ii) Water – Jug problemWater – Jug problem
The state space for this problem can be described as
The state space for this problem can be described as the set of ordered pairs of the set of ordered pairs of integers (x, y) such that x = 0, 1,2
integers (x, y) such that x = 0, 1,2 , 3 or 4 and y = 0, 3 or 4 and y = 0 ,1,2 or 3; x represents the number of ,1,2 or 3; x represents the number of gallons of water in the 4-gallon jug and y represents the quantity of water in 3-gallon jug gallons of water in the 4-gallon jug and y represents the quantity of water in 3-gallon jug
•• The start state is (0,0)The start state is (0,0) •• The goal state is (2,n)The goal state is (2,n)
Production rules for Water Jug Problem Production rules for Water Jug Problem
The operators to be used to solve the problem can be described as follows: The operators to be used to solve the problem can be described as follows:
Sr.
Sr. No No Current Current state state Next Next State State DescriptionDescription
1
1 (x, (x, y) y) if if x x < < 4 4 (4,y) (4,y) Fill Fill the the 4 4 gallon gallon jugjug
2
2 (x, (x, y) y) if if y y <3 <3 (x,3) (x,3) Fill Fill the the 3 3 gallon gallon jugjug
3
3 (x, (x, y) y) if if x x > > 0 0 (x-d, (x-d, y) y) Pour Pour some some water water out out of of the the 4 4 gallon gallon jugjug
4
4 (x, (x, y) y) if if y y > > 0 0 (x, y-d) (x, y-d) Pour Pour some some water water out out of of the the 3-gallon 3-gallon jugjug
5
5 (x, (x, y) y) if if x>0 x>0 (0, y) (0, y) Empty Empty the the 4 4 gallon gallon jugjug
6
6 (x, (x, y) y) if if y y >0 >0 (x,0) (x,0) Empty Empty the the 3 3 gallon gallon jug jug on on the the groundground
7
7 (x, y) if x + y(x, y) if x + y >= 4 and y >0 >= 4 and y >0
(4, y-(4-x))
(4, y-(4-x)) Pour water from the 3 –gallon jug into the 4 –Pour water from the 3 –gallon jug into the 4 – gallon jug until the 4-gallon jug is full
gallon jug until the 4-gallon jug is full
8
8 (x, y) if x + y(x, y) if x + y >= 3 and x>0 >= 3 and x>0
(x-(3-y), 3)
(x-(3-y), 3) Pour water from the 4-gallon jug into the 3-Pour water from the 4-gallon jug into the 3-gallon jug until the 3-3-gallon jug is full
gallon jug until the 3-gallon jug is full
9
9 (x, y) if x + y(x, y) if x + y <=4 and y>0 <=4 and y>0
(x + y, 0)
(x + y, 0) Pour all the water from the 3-gallon jug into thePour all the water from the 3-gallon jug into the 4-gallon jug 4-gallon jug 10 10 (x, y) if x + y(x, y) if x + y <= 3 and x>0 <= 3 and x>0 (0, x + y)
(0, x + y) Pour all the water from the 4-gallon jug into thePour all the water from the 4-gallon jug into the 3-gallon jug
3-gallon jug
11
11 (0,2) (0,2) (2,0)(2,0) Pour the 2 gallons from 3-gallon jug into the 4-Pour the 2 gallons from 3-gallon jug into the 4-gallon jug
gallon jug
12
12 (2,y) (2,y) (0,y)(0,y) Empty the 2 gallons in the 4-gallon jug on theEmpty the 2 gallons in the 4-gallon jug on the ground
ground
To solve the water jug problem To solve the water jug problem
•• Required a control structure that loops through a simple cycle in which someRequired a control structure that loops through a simple cycle in which some rule whose left side matches the current state is chosen, the appropriate change rule whose left side matches the current state is chosen, the appropriate change to the state is made as described in the corresponding right side, and the
to the state is made as described in the corresponding right side, and the resulting state is checked to see if it corresponds to goal state.
•• One solution to the water jug problemOne solution to the water jug problem
•• Shortest such sequence will have Shortest such sequence will have a impact on the choice of appropriatea impact on the choice of appropriate mechanism to guide the search for solution.
mechanism to guide the search for solution.
Gallons in the Gallons in the 4-gallon jug 4-gallon jug Gallons in the Gallons in the 3-gallon jug gallon jug Rule applied Rule applied 0 0 0 0 22 0 0 3 3 99 3 3 0 0 22 3 3 3 3 77 4 4 2 2 5 5 or or 1212 0 0 2 2 9 9 0r 0r 1111 2 2 00 (c)
(c) Solve the following 8-puzzle using breadth fSolve the following 8-puzzle using breadth f irst searchirst search
2 2 8 8 33 1 1 6 6 44 7 7 55 Ans : Ans : 2 2 8 8 33 1 1 6 6 44 7 7 55 1 1 2 2 33 8 8 44 7 7 6 6 55 2 2 8 8 33 1 1 6 6 44 7 7 55 2 2 8 8 33 1 1 6 6 47 7 545 2 2 8 8 33 Left 1 Left 1 Up 2 Up 2 Right 3 Right 3
1
1 44 7
Left 1 Left 1 2 2 8 8 33 1 1 6 6 44 7 7 55 2 2 8 8 33 6 6 44 1 1 7 7 55 UP 2 UP 2 2 2 8 8 33 1 1 44 7 7 6 6 55 2 2 8 8 33 1 1 44 7 7 6 6 55 2 2 33 1 1 8 8 44 7 7 6 6 55 2 2 8 8 33 1 1 44 7 7 6 6 55 Right 3 Right 3 2 2 8 8 33 1 1 6 6 44 7 7 55 Up 3.1 Up 3.1 2 2 8 8 33 1 1 66 7 7 5 5 44 Up 1.1 Up 1.1 2 2 8 8 33 6 6 44 1 1 7 7 55 8 8 33 2 2 6 6 44 Right Right 1.1.2 1.1.2 2 2 8 8 33 6 6 44 1 1 7 7 55 U U 11..11 U U 22..22 Left 2.1
Left 2.1 Left 2.1 2 2 8 8 33 1 1 44 7 7 6 6 55 Up Up 2.1.1 2.1.1 8 8 33 2 2 1 1 44 7 7 6 6 55 Down Down 2.1.2 2.1.2 2 2 8 8 33 7 7 1 1 44 6 6 55 Up 2.2 Up 2.2 2 2 33 1 1 8 8 44 7 7 6 6 55 Left Left 2.2.1 2.2.1 2 2 33 1 1 8 8 44 7 7 6 6 55 Right Right 2.2.2 2.2.2 2 2 33 1 1 8 8 44 7 7 6 6 55 Right 2.3 Right 2.3 2 2 8 8 33 1 1 44 7 7 6 6 55 Up 2.3.1 Up 2.3.1 2 2 88 1 1 4 4 33 7 7 6 6 55 Down 2.3.2 Down 2.3.2 2 2 8 8 33 1 1 4 4 55 7 7 66 Up 3.1 Up 3.1 2 2 8 8 33 1 1 66 7 7 5 5 44 Left Left 3.1.1 3.1.1 2 2 8 8 33 1 1 66 7 7 5 5 44 Up Up 3.1.2 3.1.2 2 2 88 1 1 6 6 33 7 7 5 5 44
Up Up 1.1.1 1.1.1 8 8 33 2 2 6 6 44 1 1 7 7 55 Right Right 1.1.1.1 1.1.1.1 8 8 33 2 2 6 6 44 1 1 7 7 55 Right Right 1.1.2 1.1.2 2 2 8 8 33 6 6 44 1 1 7 7 55 2 2 33 6 6 8 8 44 Right Right 1.1.2.2 1.1.2.2 2 2 8 8 33 6 6 44 1 1 7 7 55 Down Down 1.1.2.3 1.1.2.3 2 2 8 8 33 6 6 7 7 44 1 1 55 Left Left 2.2.1 2.2.1 2 2 33 1 1 8 8 44 7 7 6 6 55 Down Down 2.2.1.1 2.2.1.1 1 1 2 2 33 8 8 44 7 7 6 6 55 Right Right 2.2.1.1.1 2.2.1.1.1 1 1 2 2 33 8 8 44 7 7 6 6 55 Down Down 2.2.1.1.2 2.2.1.1.2 1 1 2 2 33 7 7 8 8 44 6 6 55
Final goal state find and ans is Block Right 2.2.1.1.1 Final goal state find and ans is Block Right 2.2.1.1.1
Q-Q-22
(a)
Suppose we want to solve the problem of computing the expression Suppose we want to solve the problem of computing the expression
(x
(x22 ++ 3x 3x + sin+ sin22;c • ;c • coscos22*)*) dx dx
We can solve this problem by breaking it down into three smaller problems; We can solve this problem by breaking it down into three smaller problems; each of which we can then solve by using a small collection of specific rules. each of which we can then solve by using a small collection of specific rules. Figure-2;9 shows the problem tree that will be generated by the process of Figure-2;9 shows the problem tree that will be generated by the process of problem decomposition as it can be exploited by a simple recursive integration problem decomposition as it can be exploited by a simple recursive integration program that worksras follows: At each step, it checks tojsee whether the program that worksras follows: At each step, it checks tojsee whether the problem if is working on is immediately solvable.' If-so, then the answer is problem if is working on is immediately solvable.' If-so, then the answer is returned directly. If the problem is not easily solvable, the integrator checks to returned directly. If the problem is not easily solvable, the integrator checks to see whether it can decompose the problem into smaller problems. If it can, it see whether it can decompose the problem into smaller problems. If it can, it creates those problems and calls itself recursively on them. Using: thistechnique creates those problems and calls itself recursively on them. Using: thistechnique of
of problem deco problem decomposition,mposition, we we can can often often solvevery solvevery large large problemseasily; problemseasily; v v .. Now consider the problem illustrated in Figure 2.10. This problem is drawn Now consider the problem illustrated in Figure 2.10. This problem is drawn firom.the domain often referred to in AMiterature as the
firom.the domain often referred to in AMiterature as the blocks world.blocks world. AssumeAssume that the following operators are available:
that the following operators are available:
Figure 2.10: A Simple Blocks
Figure 2.10: A Simple Blocks World ProblemWorld Problem
Figure 2.11 : A Proposed Solution for the Blocks Problem Figure 2.11 : A Proposed Solution for the Blocks Problem
1.
1.CLEARQc) [block x CLEARQc) [block x has nothing on it] -+ ON(has nothing on it] -+ ON(JCJC,, Table) [pick upTable) [pick up x x and put itand put it
on the table] on the table] / / 2 2 88 33 1 1 66 44 7 7 55 1 1 22 33 8 8 44 7 7 66 55
2.
2. CLEAR(x)andCLEAR(y)CLEAR(x)andCLEAR(y)->ON(jt,;y) [put* on ->ON(jt,;y) [put* on y]y]
Applying the technique of problem decomposition to this simple blocks world Applying the technique of problem decomposition to this simple blocks world example would lead to a solution tree such as that shown in Figure 2.11. In the example would lead to a solution tree such as that shown in Figure 2.11. In the figure, goals are underlined. States that have been achieved are not underlined. figure, goals are underlined. States that have been achieved are not underlined. The idea of this solution is to reduce the problem of getting B on C and A on B to The idea of this solution is to reduce the problem of getting B on C and A on B to two separate problems. The first of these new problems, getting B on C, is two separate problems. The first of these new problems, getting B on C, is simple, given the start state. Simply put B on C. The second subgoal is not quite simple, given the start state. Simply put B on C. The second subgoal is not quite so simple. Since the only operators we have allow us to pick up single blocks at so simple. Since the only operators we have allow us to pick up single blocks at a time, we have to clear off A by removing C before we can pick up A and put it a time, we have to clear off A by removing C before we can pick up A and put it on B. This can easily be done. However, if we now try to combine the two on B. This can easily be done. However, if we now try to combine the two subsolutions into one solution, we will fail. Regardless of which one we do first, subsolutions into one solution, we will fail. Regardless of which one we do first, we will not be able to do the second as we had planned. In this problem, the two we will not be able to do the second as we had planned. In this problem, the two subproblems are not independent. They interact and those interactions must be subproblems are not independent. They interact and those interactions must be considered in order to arrive at a solution for the entire problem.
considered in order to arrive at a solution for the entire problem.
These two examples, symbolic integration and the blocks world, illustrate the These two examples, symbolic integration and the blocks world, illustrate the difference between decomposable and nondecomposable problems. In Chapter. difference between decomposable and nondecomposable problems. In Chapter. 3^ we present a specific algorithm for problem decomjposition, and in Chapter 3^ we present a specific algorithm for problem decomjposition, and in Chapter 13, we look at
13, we look at what happens when dwhat happens when decomposition'ecomposition'is'impossible.is'impossible.
(b)
(b)
Write and explain Write and explain Means-End Analysis algorithm.Means-End Analysis algorithm.So far, we have presented a collection of search strategies that can reason So far, we have presented a collection of search strategies that can reason either forward or backward, but for a given problem, one direction or the other either forward or backward, but for a given problem, one direction or the other must be chosen. Often, however, a mixture of the two directions is appropriate. must be chosen. Often, however, a mixture of the two directions is appropriate. Such a mixed strategy would make it possible to solve the major parts of a Such a mixed strategy would make it possible to solve the major parts of a problem first and then go back and solve the small problems that arise in problem first and then go back and solve the small problems that arise in "gluing" the big pieces together. A technique known as
"gluing" the big pieces together. A technique known as means-ends analysismeans-ends analysis allows us to do that.
allows us to do that.
The means-ends analysis process centers around the'detection of differences The means-ends analysis process centers around the'detection of differences between the current state and the goal state. Once such a difference is isolated, between the current state and the goal state. Once such a difference is isolated, an operator that can reduce the difference must be found. But perhaps that an operator that can reduce the difference must be found. But perhaps that operator cannot be applied to the current state. So we set up a subproblem of operator cannot be applied to the current state. So we set up a subproblem of
getting to a state-in which it can be applied. The kind of backward chaining in getting to a state-in which it can be applied. The kind of backward chaining in which operators are selected and then subgoals are set up to establish the which operators are selected and then subgoals are set up to establish the preconditions of the'operators is called
preconditions of the'operators is called operator subgoaling.operator subgoaling. But maybe theBut maybe the operator does not produce exactly the goal state we want. Then we have a operator does not produce exactly the goal state we want. Then we have a second subproblem of getting from the state it does produce to the goal. But if second subproblem of getting from the state it does produce to the goal. But if the difference was chosen correctly and if the operator is really effective at the difference was chosen correctly and if the operator is really effective at reducing the difference,, then the two subproblems should be easier to solve reducing the difference,, then the two subproblems should be easier to solve than the
than the
Algorithm: Means-Ends Analysis
Algorithm: Means-Ends Analysis (CURRENT, GOAL)(CURRENT, GOAL)
1
1.. Compare CURRENT Compare CURRENT toto GOAL.GOAL. If there are no differences between them thenIf there are no differences between them then return.
return. 2.
2. Otherwise, select the most important difference and reduce it by doing theOtherwise, select the most important difference and reduce it by doing the following until success or failure is signaled:
following until success or failure is signaled:
(a)
(a)Select an as yet untried operatorSelect an as yet untried operator OO that is applicable to the currentthat is applicable to the current differ
difference. If there are no sence. If there are no such operators, then signal failure.uch operators, then signal failure. (b)
(b)Attempt to applyAttempt to apply OO toto CURRENT.CURRENT. Generate descriptions of two states:Generate descriptions of two states: O- O-START,
START, a state in which O's preconditions are satisfied anda state in which O's preconditions are satisfied and O-RESULT,O-RESULT, the state that would result if
the state that would result if OO were applied inwere applied in O-START.O-START. (c)
(c)If If
(FIRST-PART
(FIRST-PART <-<- MEAtCURRENT, O-START))MEAtCURRENT, O-START)) and
and
(LAST-PART ±- MEA(0-RESULT, GOAL)) (LAST-PART ±- MEA(0-RESULT, GOAL))
are successful, then signal success and return t
are successful, then signal success and return t he result of concatenatinghe result of concatenating FIRST-PART, O,
FIRST-PART, O, andand LAST-PART.LAST-PART.
Many of the details of this process have been omitted in this discussion. In Many of the details of this process have been omitted in this discussion. In particular, the order in which differences are considered can be critical. It is particular, the order in which differences are considered can be critical. It is important that significant differences be reduced before less critical ones. If this important that significant differences be reduced before less critical ones. If this
is not done, a great deal of effort may be wasted on situations that take care of is not done, a great deal of effort may be wasted on situations that take care of themselves once the main parts of the problem are solved.
themselves once the main parts of the problem are solved.
The simple process we have described is usually not adequate for solving The simple process we have described is usually not adequate for solving complex problems. The number of permutations of differences may get too complex problems. The number of permutations of differences may get too large. Working on one difference may interfere with the plan for reducing large. Working on one difference may interfere with the plan for reducing another. And in complex worlds, the required difference tables would be another. And in complex worlds, the required difference tables would be immense. In Chapter 13 we look at some ways in which the basic means-ends immense. In Chapter 13 we look at some ways in which the basic means-ends analysis approach can be
analysis approach can be extended to tackle some of these extended to tackle some of these problems.problems.
(c) Write and
(c) Write and explain Generate-and-Test algorithm.explain Generate-and-Test algorithm.
The generate-and-test strategy is the simplest of all the approaches we discuss. The generate-and-test strategy is the simplest of all the approaches we discuss. It consists of the following steps:
It consists of the following steps:
Algorithm:
Algorithm: Generate-and-TesGenerate-and-Testt
1
1.. Generate a possible solution. For some problems, this means generating aGenerate a possible solution. For some problems, this means generating a particular point in the problem space. For others, it means generating a particular point in the problem space. For others, it means generating a path from a start state.
path from a start state. 2.
2.Test to see if this is actually a solution by comparing the chosen point orTest to see if this is actually a solution by comparing the chosen point or the endpoint of the chosen path to
the endpoint of the chosen path to the set of acceptable goal states.the set of acceptable goal states. 3.
3.If a solution has been found, quit. If a solution has been found, quit. Otherwise, return to step 1.Otherwise, return to step 1.
If the generation of possible solutions is done systematically, then this If the generation of possible solutions is done systematically, then this procedure
procedure (( will find a solution eventually, if one exists. Unfortunately, if thewill find a solution eventually, if one exists. Unfortunately, if the problem space is very \arge, "eventually" may be a very long ti
problem space is very \arge, "eventually" may be a very long ti me.me.
The generate-and-test algorithm is a depth-first search procedure since The generate-and-test algorithm is a depth-first search procedure since complete solutions must be generated before they can be tested. In its most complete solutions must be generated before they can be tested. In its most systematic form, it is simply an exhaustive search of the problem space. systematic form, it is simply an exhaustive search of the problem space. Generate-and-test can, of course, also operate by generating solutions Generate-and-test can, of course, also operate by generating solutions randomly, but then there is no guarantee that a solution will ever be found. In randomly, but then there is no guarantee that a solution will ever be found. In this form, it is also known as the British Museum algorithm, a reference to a this form, it is also known as the British Museum algorithm, a reference to a method for finding an object in the British Museum by wandering randomly. method for finding an object in the British Museum by wandering randomly.11 Between these two extremes lies a practical middle ground in which the search Between these two extremes lies a practical middle ground in which the search
process proceeds systematically, but some paths are not considered because process proceeds systematically, but some paths are not considered because they seem Unlikely to lead to a solution. This evaluation is performed by a they seem Unlikely to lead to a solution. This evaluation is performed by a heuristic function, as described in Section 2.2.2.
heuristic function, as described in Section 2.2.2.
The most straightforward way to implement systematic generate-and-test is The most straightforward way to implement systematic generate-and-test is as a depth-first search tree with backtracking. If some intermediate states are as a depth-first search tree with backtracking. If some intermediate states are likely to • appear often in the tree/however, it may be better to modify that likely to • appear often in the tree/however, it may be better to modify that procedure, as described above; to traverse a graph rather than a tree.
procedure, as described above; to traverse a graph rather than a tree.
For simple problems; exhaustive generate-and-test is often a reasonable For simple problems; exhaustive generate-and-test is often a reasonable technique. For example, consider the puzzle that consists of four six-sided technique. For example, consider the puzzle that consists of four six-sided cubes, with each side of each cube painted one of four colors. A cubes, with each side of each cube painted one of four colors. A sojutjpjuothe'puzzle consists of an arrangement of the cubes in a row such that sojutjpjuothe'puzzle consists of an arrangement of the cubes in a row such that on all four sides of the row one block face of each color is showing. This on all four sides of the row one block face of each color is showing. This probJejrjLcan_be_^olved by a person (who is a much slower processor for this probJejrjLcan_be_^olved by a person (who is a much slower processor for this sort of thin^ffhan even a very cheap computer) in several minutes by sort of thin^ffhan even a very cheap computer) in several minutes by systematically and exhaustively trying all possibilities. It can be solved even systematically and exhaustively trying all possibilities. It can be solved even .more quickly using a heuristic generate-and-test procedure.. A quick glance at .more quickly using a heuristic generate-and-test procedure.. A quick glance at the four blocks reveals.that there are more
the four blocks reveals.that there are morett say, red faces than there are of say, red faces than there are of
other colors. Thus when placing a block with several fed faces, it would be a other colors. Thus when placing a block with several fed faces, it would be a good idea to use as few of them as possible as outside faces. As many of them good idea to use as few of them as possible as outside faces. As many of them as possible should be placed to abut the next block. \Using this heuristic, many as possible should be placed to abut the next block. \Using this heuristic, many configurations need never be explored and a solution can be found quite q
configurations need never be explored and a solution can be found quite q uickly.uickly. 'Or, as another story goes, if a sufficient number of monkeys were 'Or, as another story goes, if a sufficient number of monkeys were placed in front of a set of typewriters and left alone long enough, then placed in front of a set of typewriters and left alone long enough, then they would eventually produce all of the works of Shakespeare.
they would eventually produce all of the works of Shakespeare.
Unfortunately, for problems much harder than this, even heuristic Unfortunately, for problems much harder than this, even heuristic generate-and-test, all by itself, is not a very effective technique. Bat when combined and-test, all by itself, is not a very effective technique. Bat when combined with other t
with other techniques to restrict the space in which to echniques to restrict the space in which to search even further, thesearch even further, the technique can be very effective.
technique can be very effective.
For example, one early example of a successful AI program is DENDRAL For example, one early example of a successful AI program is DENDRAL [Lindsay
[Lindsay et ai,et ai, 1980], which infers the structure of organic compounds using1980], which infers the structure of organic compounds using mass spectrogram and nuclear magnetic resonance (NMR) data. It uses a mass spectrogram and nuclear magnetic resonance (NMR) data. It uses a strategy called
constraint-satisfaction techniques (see Section 3.5)if creates lists of constraint-satisfaction techniques (see Section 3.5)if creates lists of recommended and contraindicated substructures. The generate-and-test recommended and contraindicated substructures. The generate-and-test procedure then uses those lists so that it can explore only a fairly limited set of procedure then uses those lists so that it can explore only a fairly limited set of structures. Constrained in this way the generate-and-test procedure has structures. Constrained in this way the generate-and-test procedure has proved highly effective..
proved highly effective..
This combination of planning, using one problem-solving method (in this This combination of planning, using one problem-solving method (in this case, constraint satisfaction) with the use of the plan by another case, constraint satisfaction) with the use of the plan by another problem-solving method, generate-and-test, is an excellent example of the way solving method, generate-and-test, is an excellent example of the way techniques can be combined to overcome the limitations that each possesses techniques can be combined to overcome the limitations that each possesses individually.
individually. AA "^n>"^n>rr""*akness ofplanning is that it often produces somewhat""*akness ofplanning is that it often produces somewhat inaccurate solutions since there is no feedback from the world. But by using it inaccurate solutions since there is no feedback from the world. But by using it only to produce pieces of solutions-thai: will then be exploited in the only to produce pieces of solutions-thai: will then be exploited in the generate-and-test process, the lack of detailed accuracy becomes unimportant. And, at and-test process, the lack of detailed accuracy becomes unimportant. And, at the same time, the combinatorial problems that arise in simple the same time, the combinatorial problems that arise in simple generate-and-test are avoided by judicious reference to the plans.
test are avoided by judicious reference to the plans.
(c) Write and explain Hill
(c) Write and explain Hill Climbing algorithm.Climbing algorithm.
Hill climbing is a variant of generate-and-test in which feedback from the test Hill climbing is a variant of generate-and-test in which feedback from the test procedure is used to help the generator decide which direction to move in the procedure is used to help the generator decide which direction to move in the search space. In a pure generate-and-test procedure, the test function search space. In a pure generate-and-test procedure, the test function responds with only a yes or no. But if the test function is augmented with a responds with only a yes or no. But if the test function is augmented with a heuristic function
heuristic function22 that provides an estimate of how close a given state is to athat provides an estimate of how close a given state is to a goal state, the generate procedure can exploit it .as shown in the procedure goal state, the generate procedure can exploit it .as shown in the procedure below. This is particularly nice because often the computation of the heuristic below. This is particularly nice because often the computation of the heuristic function can be done at almost no cost at the same time that the test for a function can be done at almost no cost at the same time that the test for a solution is being performed. Hill climbing is often used when a good heuristic solution is being performed. Hill climbing is often used when a good heuristic function is available for evaluating stateTEut when nrJother useful function is available for evaluating stateTEut when nrJother useful knowledgelFavailable. For example, suppose you are in an unfamiliar city knowledgelFavailable. For example, suppose you are in an unfamiliar city without a map and you want to get downtown. You simply aim for the tall without a map and you want to get downtown. You simply aim for the tall buildings. The heuristic function is just distance between the current location buildings. The heuristic function is just distance between the current location and the location of the tall buildings and the desirablestates are those in which and the location of the tall buildings and the desirablestates are those in which this distance is minimized.
Recall from Section 2.3.4 that one way to characterize problems is according Recall from Section 2.3.4 that one way to characterize problems is according to their answer to the question, "Is a good solution absolute or relative?" to their answer to the question, "Is a good solution absolute or relative?" Absolute solutions exist whenever it is possible to recognize a goal state just Absolute solutions exist whenever it is possible to recognize a goal state just by examining it. Getting downtown is an example of such a problem. For these by examining it. Getting downtown is an example of such a problem. For these problems, hill climbing can terminate whenever a goal state is reached. Only problems, hill climbing can terminate whenever a goal state is reached. Only relative solutions exist, however, for maximization (or minimization) problems, relative solutions exist, however, for maximization (or minimization) problems, suchjs the traveling salesman problem. In these problems, there is no
suchjs the traveling salesman problem. In these problems, there is no a priori a priori goal state. For problems of this sort, it makes -sense to terminate hill climbing goal state. For problems of this sort, it makes -sense to terminate hill climbing when there is no reasonable alternative state to move to.
when there is no reasonable alternative state to move to.
What we are calling the heuristic function is sometimes also called What we are calling the heuristic function is sometimes also called the
the objective function,objective function, particularly in the literature of mathematicalparticularly in the literature of mathematical optimization.
optimization.
Simple Hill Climbing Simple Hill Climbing
The simplest way to implement hill climbing is as follows. The simplest way to implement hill climbing is as follows.
Algorithm: Simple Hill Climbing Algorithm: Simple Hill Climbing
1.
1.Evaluate the initial state. If it is also a goal state, then return it and quit.Evaluate the initial state. If it is also a goal state, then return it and quit. Otherw
Otherwise, continue with the initial state as ise, continue with the initial state as the current state.the current state. 2.
2.Loop until a solution is found or until there are no new operators left to beLoop until a solution is found or until there are no new operators left to be applied in the current state:
applied in the current state:
Select an operator that has riot yet been applied to the current state and apply Select an operator that has riot yet been applied to the current state and apply it to produce a new state.
it to produce a new state.
Evaluate the new state, i. If it is a goal state, then return it and quit, ii. If it is Evaluate the new state, i. If it is a goal state, then return it and quit, ii. If it is not a goal state but it is better than the current state, then make it
not a goal state but it is better than the current state, then make it
the current state, iii. If it is not better than the current state, then continue the current state, iii. If it is not better than the current state, then continue in the loop.
in the loop.
The key difference between this algorithm and the one we gave for The key difference between this algorithm and the one we gave for generate-and— test is the use of an evaluation function as a way to inject task-specific and— test is the use of an evaluation function as a way to inject task-specific knowledge into the control process. It is the use of such knowledge that makes knowledge into the control process. It is the use of such knowledge that makes this and the other methods discussed in the rest of this chapter
methods, and it is that same knowledge that gives these methods their power to methods, and it is that same knowledge that gives these methods their power to solve some otherwise intractable problems.
solve some otherwise intractable problems.
Notice that in this algorithm, we have asked the felativelvjrapue question, "Is Notice that in this algorithm, we have asked the felativelvjrapue question, "Is one state
one state better better than another?" For the algorithm to work, a precise definitionthan another?" For the algorithm to work, a precise definition of
of better better must be provided. In some cases, .it meiuis a higher value of themust be provided. In some cases, .it meiuis a higher value of the heuristic function. In others, it means a lower value. It does not matter'which, heuristic function. In others, it means a lower value. It does not matter'which, as long as a particular hill
as long as a particular hill-climbing pro-climbing program is consistent in its gram is consistent in its interpretatidh."interpretatidh." To see how hill climbing works, let's return to the puzzle of the four colored To see how hill climbing works, let's return to the puzzle of the four colored blocks. To solve the problem, we first need to define a heuristic function that blocks. To solve the problem, we first need to define a heuristic function that describes how close a particular configuration is to being a solution. One,such describes how close a particular configuration is to being a solution. One,such function 1$ Simply the sum of the
function 1$ Simply the sum of the number of different colors on each of the fournumber of different colors on each of the four sides. A solution to the puzzle will have a value of 16. Next we need to define a sides. A solution to the puzzle will have a value of 16. Next we need to define a set of rules that describe ways of transforming one configuration into another. set of rules that describe ways of transforming one configuration into another. Actually, one rule will suffice. It says simply pick a block and rotate it 90 Actually, one rule will suffice. It says simply pick a block and rotate it 90 degrees in any direction. Having provided these definitions, the next step is to degrees in any direction. Having provided these definitions, the next step is to generate a starting configuration. This can either be done at random or with the generate a starting configuration. This can either be done at random or with the aid of the heuristic function described in the last section. Now hill climbing can aid of the heuristic function described in the last section. Now hill climbing can begin. We generate a new state by selecting a block and rotating it. If the begin. We generate a new state by selecting a block and rotating it. If the resulting state is better, then we keep it. If not, we return to the previous state resulting state is better, then we keep it. If not, we return to the previous state and try a different perturbation.
and try a different perturbation.
(a)
(a)
Can Solution Steps Be Ignored or Undone? Explain with example,Can Solution Steps Be Ignored or Undone? Explain with example, Suppose we are trying to prove a mathematical theorem. We proceed by first Suppose we are trying to prove a mathematical theorem. We proceed by first proving a lemma that we think will be useful. Eventually, we realize that the proving a lemma that we think will be useful. Eventually, we realize that the lemma is no help at all. Alemma is no help at all. Are we in trouble?re we in trouble?
No. Everything we need to know to prove the theorem is still, true and in No. Everything we need to know to prove the theorem is still, true and in memory, if it ever was. Any rules that could have been applied at the outse? memory, if it ever was. Any rules that could have been applied at the outse? can still be applied. We can just proceed as we should have in the first place. can still be applied. We can just proceed as we should have in the first place. All we have lost is th
All we have lost is the effort that was spent exploring the blind alle effort that was spent exploring the blind all ey.ey. Now consider a different problem.
jf
jf The 8-Puzzle: The 8-puzzle is a square tray in which are placed, eightThe 8-Puzzle: The 8-puzzle is a square tray in which are placed, eight \s\s square tiles. The remaining ninth square is uncovered. Each tile has a square tiles. The remaining ninth square is uncovered. Each tile has a Nurnberg on it. A tile that is adjacent to the blank space can be slid into Nurnberg on it. A tile that is adjacent to the blank space can be slid into that space. A game consists of a starting position and a specified goal that space. A game consists of a starting position and a specified goal position. The goal is to transform the starting position into the goal position position. The goal is to transform the starting position into the goal position by sliding the tiles around.
by sliding the tiles around.
A sample game using the 8-puzzle is shown in Figure 2.12. In attempting to A sample game using the 8-puzzle is shown in Figure 2.12. In attempting to solve the 8-puzzle, we might make a stupid move. For example, in the game solve the 8-puzzle, we might make a stupid move. For example, in the game shown above, we might start by sliding tile 5 into the empty space. Having shown above, we might start by sliding tile 5 into the empty space. Having done that, we cannot change our mind and immediately slide tile 6 into the done that, we cannot change our mind and immediately slide tile 6 into the empty space since the empty space will essentially have moved. But we can empty space since the empty space will essentially have moved. But we can backtrack and undo the first move, sliding tile.5 back to where it was. Then we backtrack and undo the first move, sliding tile.5 back to where it was. Then we can move tile, 6. Mistakes can still be recovered from but not quite as easily as can move tile, 6. Mistakes can still be recovered from but not quite as easily as
in the theorem-proving problem. An additional step must
in the theorem-proving problem. An additional step must
be performed to undo each incorrect step, whereas no action was required to be performed to undo each incorrect step, whereas no action was required to "undo" a useless lemma. In addition, the control mechanism for an .8»puzzle "undo" a useless lemma. In addition, the control mechanism for an .8»puzzle solver must keep track of the order in which operations are performed so that solver must keep track of the order in which operations are performed so that the operations can be undone one at a time if necessary. The control structure the operations can be undone one at a time if necessary. The control structure for a theorem prover does, not need to record all that information.
for a theorem prover does, not need to record all that information.
Now consider again the problem of playing chess. Suppose a chess-playing Now consider again the problem of playing chess. Suppose a chess-playing program makes a stupid move and realizes it a couple of moves later. It program makes a stupid move and realizes it a couple of moves later. It cannot fcimply play as though it had never made the stupid move. Nor can it cannot fcimply play as though it had never made the stupid move. Nor can it simply back up and start the game over from that point. All it can do is to try simply back up and start the game over from that point. All it can do is to try to make the best of the,current situation and go on
to make the best of the,current situation and go on from there.from there.
(b)Write and explain agenda driven algorithm.
(b)Write and explain agenda driven algorithm. 11
Algorithm: Agenda-Driven Search Algorithm: Agenda-Driven Search
1. Do until a goal
1. Do until a goal state is reached or the agenda is empty:state is reached or the agenda is empty:
(a)
can be represented in any desired form. It can be thought of as an can be represented in any desired form. It can be thought of as an explicit statement of what to do next or simply as an indication of the explicit statement of what to do next or simply as an indication of the next node to be expanded.
next node to be expanded. (b)
(b)Execute the task by devoting to it the number of resources determinedExecute the task by devoting to it the number of resources determined by
by its importance. The important resources to consider are time andits importance. The important resources to consider are time and space. Executing the task will probably generate additional tasks space. Executing the task will probably generate additional tasks (successor nodes). For each of them, do the following:
(successor nodes). For each of them, do the following:
i. See if it is already on the agenda. If so, then see if this same reason i. See if it is already on the agenda. If so, then see if this same reason for doing it is already on its list of justifications. If so, ignore this for doing it is already on its list of justifications. If so, ignore this current evidence. If this justification was not already present, add it current evidence. If this justification was not already present, add it to the list. If the task was not on the agenda, insert it.
to the list. If the task was not on the agenda, insert it.
ii. Compute the new task's rating, combining the evidence from all its ii. Compute the new task's rating, combining the evidence from all its
justifications. Not all
justifications. Not all justifications need have justifications need have equal weight. It iequal weight. It is oftens often useful to'associate with each justification a measure of how strong a useful to'associate with each justification a measure of how strong a
reason it is. These measures are then combined at this step to reason it is. These measures are then combined at this step to produce an overall rating for the task.
produce an overall rating for the task.
One important question that arises in agenda-driven systems is how to find One important question that arises in agenda-driven systems is how to find the most promising task on each cycle. One way to do this is simple. Maintain the most promising task on each cycle. One way to do this is simple. Maintain the agenda sorted by rating. When a new task is created, insert it into the the agenda sorted by rating. When a new task is created, insert it into the agenda in-its proper place. When a task has its justifications changed, agenda in-its proper place. When a task has its justifications changed, recompute its rating and move it to the correct place i
recompute its rating and move it to the correct place in the list. But this n the list. But this methodmethod causes a great deal of time to be spent keeping the agenda in perfect order causes a great deal of time to be spent keeping the agenda in perfect order Much of this time is wasted since we do not
Much of this time is wasted since we do not need perfect order. We only need toneed perfect order. We only need to know the proper first element. The following modified strategy may occasionally know the proper first element. The following modified strategy may occasionally cause a task other than the best to be executed, but it is significantly cheaper cause a task other than the best to be executed, but it is significantly cheaper than the perfect method. When a task is proposed, or a new justification is than the perfect method. When a task is proposed, or a new justification is added to an existing task, compute the new rating and compare it against the added to an existing task, compute the new rating and compare it against the top few Xe.g., five or ten) elements on the agenda. If it is better, insert the top few Xe.g., five or ten) elements on the agenda. If it is better, insert the node into its proper position at the top of the list. Otherwise, leave it where it is node into its proper position at the top of the list. Otherwise, leave it where it is or simply insert it at the end of the agenda. At the beginning of each cycle, or simply insert it at the end of the agenda. At the beginning of each cycle, choose the first task on the agenda. In addition, once in a while, go through the choose the first task on the agenda. In addition, once in a while, go through the agenda and reorder it properly.
An agenda-driven control structure is also useful if some tasks (or nodes) An agenda-driven control structure is also useful if some tasks (or nodes) provide negative evidence about the merits of other tasks (or nodes). This can provide negative evidence about the merits of other tasks (or nodes). This can be represented by justifications with negative weightings. If these negative be represented by justifications with negative weightings. If these negative weightings are used, it may be important to check not only for the possibility of weightings are used, it may be important to check not only for the possibility of moving a task to the head of the agenda but also of moving a top task to the moving a task to the head of the agenda but also of moving a top task to the bottom if new, negative justifications appear. But this is easy tq.do.
bottom if new, negative justifications appear. But this is easy tq.do.
As you can see, the agenda mechanism provides a good way of focusing the As you can see, the agenda mechanism provides a good way of focusing the attention of a complex system in the areas suggested by the greatest number of attention of a complex system in the areas suggested by the greatest number of positive indicators. But the overhead for each task executed may be fairly high. positive indicators. But the overhead for each task executed may be fairly high. This raises the question of (he proper grain size for the division of the entire This raises the question of (he proper grain size for the division of the entire problem-solving process into individual tasks. Suppose each task is very small. problem-solving process into individual tasks. Suppose each task is very small. Then we will never do even a very small thing unless it realjy is the best thing to Then we will never do even a very small thing unless it realjy is the best thing to do. But we will spend a large percentage of our total effort on figuring out what do. But we will spend a large percentage of our total effort on figuring out what to do next. If, on the other hand, the size of an individual task is very large, to do next. If, on the other hand, the size of an individual task is very large, then some effort may be spent finishing one task when there are more then some effort may be spent finishing one task when there are more promising ones that could be done. But a smaller percentage of the total time promising ones that could be done. But a smaller percentage of the total time will be" spent on the overhead of figuring out what to do. The exact choice of will be" spent on the overhead of figuring out what to do. The exact choice of task size for a particular system depends on the extent to which doing one small task size for a particular system depends on the extent to which doing one small thing really means that a set of other small things is likely to be very good to do thing really means that a set of other small things is likely to be very good to do too. It often requires
too. It often requires some experimentation to get right.some experimentation to get right.
There are some problem domains for which an agenda mechanism is There are some problem domains for which an agenda mechanism is inappropriate. The agenda"mechanism assumes that if there is good reason to inappropriate. The agenda"mechanism assumes that if there is good reason to do something now, then there will also be the same good reason to do do something now, then there will also be the same good reason to do something later unless something better comes along in the interim. But this is something later unless something better comes along in the interim. But this is not always the case, particularly for systems that are interacting with people. not always the case, particularly for systems that are interacting with people. The following dialogue would not b
The following dialogue would not be acceptable to most people:e acceptable to most people:
Person:
Person: I I don't don't want want to to read read any any more more about about China. China. Give Give me me something something ejse.ejse. Compute
Computer: r: OK. What OK. What else aelse are you re you interested interested in?in? Person:
Person: How How about about Italy? Italy? I I think think I'd I'd find find Italy Italy fascinating.fascinating. Computer:
Q-3(a) Explain heuristic Search.
Q-3(a) Explain heuristic Search.
Ans:
Ans:
Definition:
Definition:
A
A HeuristicHeuristic is an operationally-effective nugget of information on how to directis an operationally-effective nugget of information on how to direct search in a problem space. Heuristics are only approximately correct. Their purpose is to search in a problem space. Heuristics are only approximately correct. Their purpose is to minimize search on average.
minimize search on average.
Common Types of Heuristics
Common Types of Heuristics
"If-then" rules for state-transition selection"If-then" rules for state-transition selection
Macro-operator formation [discussed later]Macro-operator formation [discussed later]
Problem decomposition [e.g. hypothesizing islands on the Problem decomposition [e.g. hypothesizing islands on the search path]search path]
Estimation of distance between SEstimation of distance between Scurrcurr and Sand SG.G. (e.g. Manhattan, Euclidian,(e.g. Manhattan, Euclidian,
topological distance) topological distance)
Value function on each Succ(SValue function on each Succ(Scurrcurr))
cost(path(Scost(path(S00, S, Scurrcurr)) + E[cost(path(S)) + E[cost(path(Scurrcurr,S,SGG))]))]
Utility: value(S) – cost(S)Utility: value(S) – cost(S)
Heuristic Search
Heuristic Search
Value function: E(o-Path(S
Value function: E(o-Path(S
00, S
, S
currcurr), S
), S
currcurr, S
, S
GG))
Since S
Since S
00and S
and S
GGare constant, we abbreviate E(S
are constant, we abbreviate E(S
curr curr))
General Form:
General Form:
1.
1. Quit if done (with success or
Quit if done (with success or failure), else:
failure), else:
2.
2. s-Queue:= F(Succ(S
s-Queue:= F(Succ(S
currcurr),s-Queue)
),s-Queue)
3.
3. S
S
nextnext:=
:=
Arg
Arg
max[E(s-Queue)]
max[E(s-Queue)]
4.
Steepest-Ascent Hill-Climbing
Steepest-Ascent Hill-Climbing
F(Succ(S
F(Succ(S
currcurr), s-Queue) = Succ(S
), s-Queue) = Succ(S
currcurr))
S
S
nextnext:=
:=
Arg
Arg
max[E(Succ(S
max[E(Succ(S
currcurr))]
))]
If Succ(S
If Succ(S
nextnext) is null, then
) is null, then
stop
stop
Quintessential greedy search
Quintessential greedy search
Max-Gradient Search
Max-Gradient Search
"Informed" depth-first search
"Informed" depth-first search
S
S
nextnext:=
:=
Arg
Arg
max[E(Succ(S
max[E(Succ(S
currcurr))]
))]
But if Succ(S
But if Succ(S
nextnext) is null, then
) is null, then
backtrack
backtrack
Alternative: backtrack if E(S
Alternative: backtrack if E(S
nextnext)<E(S
)<E(S
currcurr))
Q-3(b) what is Intelligence and Artificial Intelligence?
Q-3(b) what is Intelligence and Artificial Intelligence?
Ans:
Ans:
Intelligence: Intelligence:
Intelligence is the computational part of the ability to achieve goals in the world. Intelligence is the computational part of the ability to achieve goals in the world. Varying kinds and degrees of intelligence occur in people, many
Varying kinds and degrees of intelligence occur in people, many animals and some machines.animals and some machines. Artificial Intelligence:
Artificial Intelligence:
Artificial Intelligence (AI) is usually defined as the science of making computers do Artificial Intelligence (AI) is usually defined as the science of making computers do things that require intelligence when done by humans.
Q-3(c) List out merits & demerits of DFS & BFS.
Q-3(c) List out merits & demerits of DFS & BFS.
Ans:
Ans:
Depth first search is another way of traversing graphs, which is closely related to preorder Depth first search is another way of traversing graphs, which is closely related to preorder traversal of a tree. Recall that preorder traversal simply visits each node before its children. It traversal of a tree. Recall that preorder traversal simply visits each node before its children. It is most easy to program as a
BFS: This can be throught of as being like Dijkstra's algorithm for shortest paths, but with BFS: This can be throught of as being like Dijkstra's algorithm for shortest paths, but with every edge having the same length. However it is a lot simpler and doesn't need any data every edge having the same length. However it is a lot simpler and doesn't need any data structures. We just keep a tree (the breadth first search tree), a list of nodes to be added to the structures. We just keep a tree (the breadth first search tree), a list of nodes to be added to the tree, and markings (Boolean variables) on the vertices to tell whether they are in the tree or tree, and markings (Boolean variables) on the vertices to tell whether they are in the tree or list.
list.
Q-3(d)(i)Construct The Semantic Net
Q-3(d)(i)Construct The Semantic Net For The All Indian Likes Football
For The All Indian Likes Football
Q-3(e)
Q-3(e)
Ans:
Ans:
AA Tree structureTree structure is a way of representing the hierarchical nature of a structure in a graphical form. Inis a way of representing the hierarchical nature of a structure in a graphical form. In computer science
computer science, a tree i, a tree is a widely-useds a widely-used data structuredata structure that emulates a hierarchicalthat emulates a hierarchical tree structuretree structurewithwith a set of linked
a set of linked nodesnodes..
A node is a structure which may contain a value, a condition, or represent a separate data A node is a structure which may contain a value, a condition, or represent a separate data structure (which could be a tree of
structure (which could be a tree of its own). Each node in a its own). Each node in a tree has zero or more child nodes,tree has zero or more child nodes, which are below it in the tree (by convention, trees are drawn growing downwards). A node which are below it in the tree (by convention, trees are drawn growing downwards). A node that has a child is called the child's parent node (or ancestor node, or
that has a child is called the child's parent node (or ancestor node, or superiorsuperior). A node has at). A node has at most one parent.
most one parent.
Nodes that do not have any children are called
Nodes that do not have any children are called leaf nodesleaf nodes. They are also referred to as. They are also referred to as terminal nodes.
terminal nodes.
A free tree is a tree that is not rooted. A free tree is a tree that is not rooted.
The height of a node is the length of the longest downward path to a leaf from that node. The The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. The depth of a node is the length of the path to its height of the root is the height of the tree. The depth of a node is the length of the path to its root (i.e., its root path). This is commonly needed in the manipulation of the various self root (i.e., its root path). This is commonly needed in the manipulation of the various self balancing trees,
balancing trees, AVL TreesAVL Trees in particular. Conventionally, the value -1 corresponds to ain particular. Conventionally, the value -1 corresponds to a subtree with no nodes, whereas zero corresponds to a subtree with
subtree with no nodes, whereas zero corresponds to a subtree with one node.one node. The topmost node in a tree
The topmost node in a tree is called the root node. Being the is called the root node. Being the topmost node, the root node willtopmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin (although not have parents. It is the node at which operations on the tree commonly begin (although some algorithms begin with the leaf nodes and work up ending at the root). All other nodes some algorithms begin with the leaf nodes and work up ending at the root). All other nodes can be reached from it by following edges or links. (In the formal definition, each such path can be reached from it by following edges or links. (In the formal definition, each such path is also unique). In diagrams, it is typically drawn at the top. In some trees, such as
is also unique). In diagrams, it is typically drawn at the top. In some trees, such as heapsheaps, the, the root node has special properties. Every node in a tree can be seen as the root node of the root node has special properties. Every node in a tree can be seen as the root node of the subtree rooted at that node.
subtree rooted at that node.
An internal node or inner node is any
An internal node or inner node is any nodenodeof a tree that hasof a tree that has child nodeschild nodesand is thus not a leaf and is thus not a leaf
node
node. A sub tree of a tree T is a t. A sub tree of a tree T is a tree consisting of a node in T and all of its descendants in T.ree consisting of a node in T and all of its descendants in T.
Tree representations
Tree representations
There are many different ways to represent trees; common representations represent the There are many different ways to represent trees; common representations represent the nodes as records allocated on the heap (not to be confused with the heap data structure) with nodes as records allocated on the heap (not to be confused with the heap data structure) with pointers to their children, their parents, or both, or as items in an array, with relationships pointers to their children, their parents, or both, or as items in an array, with relationships between them determined by their positions in the a
between them determined by their positions in the a rrayrray
Trees and graphs
Trees and graphs
The tree data structure can be generalized to represent
The tree data structure can be generalized to represent directed graphsdirected graphs by removing theby removing the constraints that a node may have at most one parent, and that no cycles are allowed. Edges constraints that a node may have at most one parent, and that no cycles are allowed. Edges are still abstractly considered as pairs of nodes, however, the terms
are still abstractly considered as pairs of nodes, however, the terms parent parent andand child child areare usually replaced by
usually replaced by different terminology.different terminology.
Relationship with trees in graph t
Relationship with trees in graph theory
heory
InIn graph theorygraph theory, a, a treetreeis a connectedis a connected acyclicacyclicgraphgraph; unless stated otherwise, trees and graphs; unless stated otherwise, trees and graphs are undirected. There is no one-to-one correspondence between such trees and trees as data are undirected. There is no one-to-one correspondence between such trees and trees as data structure. We can take an arbitrary undirected tree, arbitrarily
structure. We can take an arbitrary undirected tree, arbitrarily pick one of itspick one of its verticesverticesas theas the root
root , make all its edges directed by making them point away from the , make all its edges directed by making them point away from the root node - producingroot node - producing an
an arborescencearborescence- and assign an order to all - and assign an order to all the nodes. The result corresponds to a tree datathe nodes. The result corresponds to a tree data structure. Picking a different root or different ordering produces a different one.
structure. Picking a different root or different ordering produces a different one.
Q-4(A) Explain Expert System Architecture In Artificial Intelligence.
Q-4(A) Explain Expert System Architecture In Artificial Intelligence.
An expert system is, typically, composed of two major components, the Knowledge-base An expert system is, typically, composed of two major components, the Knowledge-base and the Expert System Shell. The Knowledge-base is a collection of rules encoded as and the Expert System Shell. The Knowledge-base is a collection of rules encoded as metadataa problem-independent component housing facilities for creating, editing, and executing a problem-independent component housing facilities for creating, editing, and executing rules. A software architecture for an expert system is
rules. A software architecture for an expert system is illustrated in Figure 2.illustrated in Figure 2.
The shell portion includes software modules whose purpose it is to, The shell portion includes software modules whose purpose it is to,
•
• Process requests for service from system users Process requests for service from system users and application layer modules;and application layer modules; •
• Support the creation and modification of business rules by subject matter experts;Support the creation and modification of business rules by subject matter experts; •
• Translate business rules, created by a Translate business rules, created by a subject matter experts, subject matter experts, into machine-readablinto machine-readablee
forms; forms;
•
• Execute business rules; andExecute business rules; and •
• Provide low-level support to expert system components (e.g., retrieve metadata fromProvide low-level support to expert system components (e.g., retrieve metadata from
and save metadata to knowledge base, build Abstract Syntax Trees during rule and save metadata to knowledge base, build Abstract Syntax Trees during rule translation of business rules, etc.).
translation of business rules, etc.).
4.1 Client Interface
4.1 Client Interface
The Client Interface processes requests for service from system-users and from application The Client Interface processes requests for service from system-users and from application layer components. Client Interface logic routes these requests to an appropriate shell layer components. Client Interface logic routes these requests to an appropriate shell program unit. For example, when a subject matter expert wishes to create or edit a rule, they program unit. For example, when a subject matter expert wishes to create or edit a rule, they use the Client Interface to dispatch the
use the Client Interface to dispatch the Knowledge-base Editor Knowledge-base Editor . Other service requests. Other service requests might schedule a rule, or a
might schedule a rule, or a group of rules, for execution by the Rule Engine.group of rules, for execution by the Rule Engine.
4.2 Knowledge Base Editor
4.2 Knowledge Base Editor
The Knowledge-base Editor is a simple text editor, a graphical editor, or some hybrid of The Knowledge-base Editor is a simple text editor, a graphical editor, or some hybrid of these two types. It provides facilities that enable a subject matter expert to compose and add these two types. It provides facilities that enable a subject matter expert to compose and add rules to t
rules to the Knowledge-bahe Knowledge-base.se.