Q-1 (a) Solve The following Crypt arithmetic problem : C R O S S + R O A D S D E N G E R

Ans : D has to be 1 because when you do your addition by hand: CROSS +ROADS ----------DANGER You see that the D in DANGER must have been carried over from the addition of C and R in CROSS and ROADS, respectively. Thus, we have: CROSS +ROA1S -----------1ANGER This, by some fairly weird algebra and modular arithmetic, leads to the following relationships: R = 2S mod 10 E = (3S + 1 - (2S mod 10)) mod 10 A = (C + 2R - (R + O mod 10)) mod 10 A = G - O mod 10 N = (R + 2O - (O + A mod 10)) mod 10 C = A - R mod 10 O = N - R mod 10 O = G - A 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 trial and error. So now we try things. 12344 +25614 -----3NO! D has to be 1 92344 +25614 -----11NO! A cannot be 1 because D is 1

96233 +62513 -----158746

(b) Give the problem space for the following : (i) Monkey – Banana problem (ii) Water – Jug problem Ans: (i) Monkey – Banana problem

A monkey is in a cage and bananas are suspended from the ceiling, the monkey wants to eat a banana but cannot reach them – in the room are a chair and a stick – if the monkey stands on the chair and waves the stick, he can knock a banana down to eat it what are the actions the monkey should take? Initial state: monkey on ground with empty hand bananas suspended Goal state: monkey eating bananas. Actions: climb chair/get off grab X wave X eat X

(ii)

Water – Jug problem

The state space for this problem can be described as the set of ordered pairs of integers (x, y) such that x = 0, 1,2, 3 or 4 and y = 0,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 • • The start state is (0,0) The goal state is (2,n)

Production rules for Water Jug Problem The operators to be used to solve the problem can be described as follows:

Sr. No 1

Current state (x, y) if x < 4

Next State (4,y)

Description Fill the 4 gallon jug

2

(x, y) if y <3

(x,3)

Fill the 3 gallon jug

3

(x, y) if x > 0

(x-d, y)

Pour some water out of the 4 gallon jug

4

(x, y) if y > 0

(x, y-d)

Pour some water out of the 3-gallon jug

5

(x, y) if x>0

(0, y)

Empty the 4 gallon jug

6

(x, y) if y >0

(x,0)

Empty the 3 gallon jug on the ground

7

(x, y) if x + y >= 4 and y >0 (x, y) if x + y >= 3 and x>0 (x, y) if x + y <=4 and y>0 (x, y) if x + y <= 3 and x>0 (0,2)

(4, y-(4-x))

Pour water from the 3 –gallon jug into the 4 – gallon jug until the 4-gallon jug is full Pour water from the 4-gallon jug into the 3gallon jug until the 3-gallon jug is full Pour all the water from the 3-gallon jug into the 4-gallon jug Pour all the water from the 4-gallon jug into the 3-gallon jug Pour the 2 gallons from 3-gallon jug into the 4gallon jug Empty the 2 gallons in the 4-gallon jug on the ground

8

(x-(3-y), 3)

9

(x + y, 0)

10

(0, x + y)

11

(2,0)

12

(2,y)

(0,y)

To solve the water jug problem • Required 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 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.

Gallons in the 4-gallon jug 0 0 3 3 4 0 2 Gallons in the 3gallon jug 0 3 0 3 2 2 0 Rule applied 2 9 2 7 5 or 12 9 0r 11 (c) Solve the following 8-puzzle using breadth first search 1 8 7 2 1 7 6 8 6 2 3 4 5 3 4 5 Ans : 2 1 Left 1 2 1 8 7 6 3 5 4 7 Up 2 7 2 8 3 5 8 6 3 4 5 Right 3 2 1 8 6 3 4 .• • One solution to the water jug problem Shortest such sequence will have a impact on the choice of appropriate mechanism to guide the search for solution.

1 7 6 4 5 .

1 2 1 7 8 6 5 3 4 Up 1.1 7 8 1 6 3 4 5 Up 2.1 2 1 8 6 7 3 4 5 Right 1.2 Left 1 1 8 6 7 3 4 5 Up 1.1.2 2 6 1 8 7 3 4 5 8 2 6 3 4 .3 2 1 7 Right 3 2 1 7 8 6 5 3 4 8 4 6 5 3 8 6 7 3 4 5 Up 3.2 2 1 7 8 6 6 8 3 4 5 3 4 5 Right 2.1 2 1 UP 2 2 1 7 2 Left 2.

1 8 2 7 1 6 3 4 5 Down 2.1.3.2 2 1 7 8 6 5 3 4 Up 3.3 2 1 7 Up 2.1 7 8 1 6 3 4 5 2 8 1 6 3 4 5 Up 2.1.2 2 1 7 8 4 6 3 5 8 6 5 3 4 Up 3.2.2 2 1 7 3 8 6 4 5 Left 2.2 7 Up 2.1 2 1 7 8 6 3 4 5 Right 2.2.2 Left 2.1 1 7 5 8 3 6 4 1 7 .3.1 2 1 7 8 4 6 3 5 2 8 4 6 3 5 Down 2.2 2 1 7 8 6 3 4 5 Right 2.1.1 2 Left 3.1.

1 Right 1.1.Up 1.1.2.2 8 7 3 4 5 Down 1.2.2.1.3 2 6 1 8 4 7 3 5 2 6 1 8 7 3 4 5 2 6 8 3 4 2 Left 2.1 8 2 1 6 7 3 4 5 8 2 1 6 7 3 4 5 2 Right 1.2.2.2 6 1 Right 1.1.1.1. .2.1.1.1.1.1 1 7 8 6 3 4 5 Down 2.1 Q-2 (a) Explain Problem Decomposability with example.1 1 7 2 8 6 3 4 5 Right 2.2 1 7 2 8 6 3 4 5 Final goal state find and ans is Block Right 2.1.1.2.1 1 8 7 2 6 3 4 5 Down 2.1.

Suppose we want to solve the problem of computing the expression (x2 + 3x + sin2.10. each of which we can then solve by using a small collection of specific rules.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 program that worksras follows: At each step.c • cos2*) dx / We can solve this problem by breaking it down into three smaller problems. If it can.10: A Simple Blocks World Problem 2 8 3 1 2 3 4 1 6 48 7 57 6 5 Figure 2. Table) [pick up x and put it on the table] . CLEARQc) [block x has nothing on it] -+ ON(JC. Using: thistechnique of problem decomposition. Figure-2.' If-so. it checks tojsee whether the problem if is working on is immediately solvable. it creates those problems and calls itself recursively on them. v . the integrator checks to see whether it can decompose the problem into smaller problems. Assume that the following operators are available: Figure 2. we can often solvevery large problemseasily. Now consider the problem illustrated in Figure 2. then the answer is returned directly. This problem is drawn firom.11 : A Proposed Solution for the Blocks Problem 1. If the problem is not easily solvable.the domain often referred to in AMiterature as the blocks world.

These two examples. The first of these new problems. A technique known as means-ends analysis allows us to do that. Once such a difference is isolated. getting B on C. we will fail. Simply put B on C. and in Chapter 13. goals are underlined. however. Regardless of which one we do first. we look at what happens when decomposition'is'impossible. we have to clear off A by removing C before we can pick up A and put it on B. an operator that can reduce the difference must be found. In the figure. a mixture of the two directions is appropriate. is simple. if we now try to combine the two subsolutions into one solution.2. But perhaps that operator cannot be applied to the current state.y) [put* on y] 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. the two subproblems are not independent. CLEAR(x)andCLEAR(y)->ON(jt. we have presented a collection of search strategies that can reason either forward or backward. illustrate the difference between decomposable and nondecomposable problems. So we set up a subproblem of . This can easily be done. The means-ends analysis process centers around the'detection of differences between the current state and the goal state. we will not be able to do the second as we had planned. States that have been achieved are not underlined. but for a given problem. Since the only operators we have allow us to pick up single blocks at a time. In this problem.. 3^ we present a specific algorithm for problem decomjposition. (b) Write and explain Means-End Analysis algorithm. given the start state. Often. 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 "gluing" the big pieces together. They interact and those interactions must be considered in order to arrive at a solution for the entire problem. The second subgoal is not quite so simple. one direction or the other must be chosen. So far. However. The idea of this solution is to reduce the problem of getting B on C and A on B to two separate problems. symbolic integration and the blocks world. In Chapter.

getting to a state-in which it can be applied. Otherwise. Generate descriptions of two states: OSTART. In particular. If this . Compare CURRENT to GOAL. (b) Attempt to apply O to CURRENT. the state that would result if O were applied in O-START. If there are no differences between them then return. O. then signal failure. Many of the details of this process have been omitted in this discussion. then signal success and return the result of concatenating FIRST-PART.MEA(0-RESULT. 2. O-START)) and (LAST-PART ±. (c) If (FIRST-PART <. and LAST-PART. Then we have a second subproblem of getting from the state it does produce to the goal.. then the two subproblems should be easier to solve than the Algorithm: Means-Ends Analysis (CURRENT.MEAtCURRENT. select the most important difference and reduce it by doing the following until success or failure is signaled: (a) Select an as yet untried operator O that is applicable to the current difference. the order in which differences are considered can be critical. The kind of backward chaining in which operators are selected and then subgoals are set up to establish the preconditions of the'operators is called operator subgoaling. If there are no such operators. GOAL)) are successful. It is important that significant differences be reduced before less critical ones. a state in which O's preconditions are satisfied and O-RESULT. But maybe the operator does not produce exactly the goal state we want. But if the difference was chosen correctly and if the operator is really effective at reducing the difference. GOAL) 1.

it means generating a path from a start state. this means generating a particular point in the problem space. (c) Write and explain Generate-and-Test algorithm. Generate-and-test can. Working on one difference may interfere with the plan for reducing another. And in complex worlds. 2. It consists of the following steps: Algorithm: Generate-and-Test 1. the required difference tables would be immense. For others. If a solution has been found. The number of permutations of differences may get too large. The generate-and-test strategy is the simplest of all the approaches we discuss. Unfortunately. if the problem space is very \arge.1 Between these two extremes lies a practical middle ground in which the search . return to step 1. In Chapter 13 we look at some ways in which the basic means-ends analysis approach can be extended to tackle some of these problems. it is also known as the British Museum algorithm. but then there is no guarantee that a solution will ever be found. "eventually" may be a very long time. If the generation of possible solutions is done systematically. Test to see if this is actually a solution by comparing the chosen point or the endpoint of the chosen path to the set of acceptable goal states. if one exists. also operate by generating solutions randomly. a reference to a method for finding an object in the British Museum by wandering randomly. Generate a possible solution. it is simply an exhaustive search of the problem space. For some problems. In its most systematic form. then this procedure ( will find a solution eventually. Otherwise. of course. The simple process we have described is usually not adequate for solving complex problems. quit. In this form.is not done. 3. The generate-and-test algorithm is a depth-first search procedure since complete solutions must be generated before they can be tested. a great deal of effort may be wasted on situations that take care of themselves once the main parts of the problem are solved.

one early example of a successful AI program is DENDRAL [Lindsay et ai. it would be a good idea to use as few of them as possible as outside faces. but some paths are not considered because they seem Unlikely to lead to a solution. It uses a strategy called plan-generate-test in which a planning process that uses . 'Or. as another story goes. Bat when combined with other techniques to restrict the space in which to search even further. the technique can be very effective.2. Thus when placing a block with several fed faces. as described above. The most straightforward way to implement systematic generate-and-test is as a depth-first search tree with backtracking. which infers the structure of organic compounds using mass spectrogram and nuclear magnetic resonance (NMR) data.that there are moret say. exhaustive generate-and-test is often a reasonable technique.more quickly using a heuristic generate-and-test procedure.2. It can be solved even . it may be better to modify that procedure. \Using this heuristic. consider the puzzle that consists of four six-sided cubes. with each side of each cube painted one of four colors. is not a very effective technique. 1980]. to traverse a graph rather than a tree. as described in Section 2. For example. all by itself.process proceeds systematically. A quick glance at the four blocks reveals. If some intermediate states are likely to • appear often in the tree/however. for problems much harder than this. A 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. many configurations need never be explored and a solution can be found quite quickly. Unfortunately. if a sufficient number of monkeys were placed in front of a set of typewriters and left alone long enough. For example. red faces than there are of other colors. 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 systematically and exhaustively trying all possibilities. then they would eventually produce all of the works of Shakespeare. This evaluation is performed by a heuristic function. As many of them as possible should be placed to abut the next block.. For simple problems. even heuristic generateand-test.

constraint-satisfaction recommended and techniques (see Section 3. at the same time. using one problem-solving method (in this case. And. 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 solution is being performed. Constrained in this way the generate-and-test procedure has proved highly effective. Hill climbing is often used when a good heuristic function is available for evaluating stateTEut when nrJother useful knowledgelFavailable. The heuristic function is just distance between the current location and the location of the tall buildings and the desirablestates are those in which this distance is minimized. is an excellent example of the way techniques can be combined to overcome the limitations that each possesses individually. the generate procedure can exploit it . This combination of planning. suppose you are in an unfamiliar city without a map and you want to get downtown. In a pure generate-and-test procedure. constraint satisfaction) with the use of the plan by another problemsolving method. . But by using it only to produce pieces of solutions-thai: will then be exploited in the generateand-test process.5)if The creates lists of contraindicated substructures. the lack of detailed accuracy becomes unimportant. But if the test function is augmented with a heuristic function2 that provides an estimate of how close a given state is to a goal state. generate-and-test procedure then uses those lists so that it can explore only a fairly limited set of structures. For example.as shown in the procedure below. A "^n>r""*akness ofplanning is that it often produces somewhat inaccurate solutions since there is no feedback from the world. 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 search space. the combinatorial problems that arise in simple generate-andtest are avoided by judicious reference to the plans. (c) Write and explain Hill Climbing algorithm. You simply aim for the tall buildings. generate-and-test.. the test function responds with only a yes or no.

Otherwise. "Is a good solution absolute or relative?" Absolute solutions exist whenever it is possible to recognize a goal state just by examining it. then return it and quit.4 that one way to characterize problems is according to their answer to the question. hill climbing can terminate whenever a goal state is reached. ii. then continue in the loop. Algorithm: Simple Hill Climbing 1. particularly in the literature of mathematical optimization. Only relative solutions exist. In these problems. Evaluate the new state. If it is a goal state. Loop until a solution is found or until there are no new operators left to be applied in the current state: Select an operator that has riot yet been applied to the current state and apply it to produce a new state. 2. there is no a priori goal state. iii. What we are calling the heuristic function is sometimes also called the objective function. If it is also a goal state. continue with the initial state as the current state. then return it and quit. For these problems. Simple Hill Climbing The simplest way to implement hill climbing is as follows.3. i. it makes -sense to terminate hill climbing when there is no reasonable alternative state to move to. Evaluate the initial state. however. The key difference between this algorithm and the one we gave for generateand— test is the use of an evaluation function as a way to inject task-specific knowledge into the control process. for maximization (or minimization) problems.Recall from Section 2. Getting downtown is an example of such a problem. For problems of this sort. If it is not a goal state but it is better than the current state. suchjs the traveling salesman problem. If it is not better than the current state. then make it the current state. It is the use of such knowledge that makes this and the other methods discussed in the rest of this chapter heuristic search .

A solution to the puzzle will have a value of 16. "Is one state better than another?" For the algorithm to work. we realize that the lemma is no help at all. If not. Actually. Having provided these definitions. Suppose we are trying to prove a mathematical theorem.methods. All we have lost is the effort that was spent exploring the blind alley. It does not matter'which. This can either be done at random or with the aid of the heuristic function described in the last section. If the resulting state is better. Eventually. Everything we need to know to prove the theorem is still. if it ever was. Now consider a different problem. Now hill climbing can begin.such function 1$ Simply the sum of the number of different colors on each of the four sides. (a) Can Solution Steps Be Ignored or Undone? Explain with example. In others. . We generate a new state by selecting a block and rotating it. one rule will suffice. it means a lower value. It says simply pick a block and rotate it 90 degrees in any direction. we return to the previous state and try a different perturbation. let's return to the puzzle of the four colored blocks. a precise definition of better must be provided. Notice that in this algorithm. To solve the problem. . In some cases. Any rules that could have been applied at the outse? can still be applied. We proceed by first proving a lemma that we think will be useful. as long as a particular hill-climbing program is consistent in its interpretatidh. One. true and in memory. we have asked the felativelvjrapue question. then we keep it. and it is that same knowledge that gives these methods their power to solve some otherwise intractable problems.it meiuis a higher value of the heuristic function. the next step is to generate a starting configuration. we first need to define a heuristic function that describes how close a particular configuration is to being a solution. We can just proceed as we should have in the first place. Next we need to define a set of rules that describe ways of transforming one configuration into another. Are we in trouble? No." To see how hill climbing works.

The remaining ninth square is uncovered. In attempting to solve the 8-puzzle. (b)Write and explain agenda driven algorithm. we might start by sliding tile 5 into the empty space. Having done that.current situation and go on from there. Mistakes can still be recovered from but not quite as easily as in the theorem-proving problem. It cannot fcimply play as though it had never made the stupid move. All it can do is to try to make the best of the. Each tile has a Nurnberg on it. A game consists of a starting position and a specified goal position. A sample game using the 8-puzzle is shown in Figure 2. the control mechanism for an . not need to record all that information.5 back to where it was. In addition. A tile that is adjacent to the blank space can be slid into that space. whereas no action was required to "undo" a useless lemma. The goal is to transform the starting position into the goal position by sliding the tiles around. Then we can move tile. Nor can it simply back up and start the game over from that point. in the game shown above. we might make a stupid move.12. eight \s square tiles. But we can backtrack and undo the first move. 6.jf The 8-Puzzle: The 8-puzzle is a square tray in which are placed. For example. we cannot change our mind and immediately slide tile 6 into the empty space since the empty space will essentially have moved.8»puzzle 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. Algorithm: Agenda-Driven Search 1 1. Suppose a chess-playing program makes a stupid move and realizes it a couple of moves later. Now consider again the problem of playing chess. Do until a goal state is reached or the agenda is empty: (a) Choose the most promising task from the agenda. The control structure for a theorem prover does. sliding tile. Notice that this task . An additional step must be performed to undo each incorrect step.

leave it where it is or simply insert it at the end of the agenda. We only need to know the proper first element. See if it is already on the agenda. Maintain the agenda sorted by rating. If it is better. compute the new rating and compare it against the top few Xe. If the task was not on the agenda. (b) Execute the task by devoting to it the number of resources determined by its importance. ii. once in a while.. For each of them. In addition. choose the first task on the agenda. Executing the task will probably generate additional tasks (successor nodes). five or ten) elements on the agenda. add it to the list. insert the node into its proper position at the top of the list. It is often useful to'associate with each justification a measure of how strong a reason it is. If so.g.can be represented in any desired form. One important question that arises in agenda-driven systems is how to find the most promising task on each cycle. If this justification was not already present. then see if this same reason for doing it is already on its list of justifications. Otherwise. or a new justification is added to an existing task. insert it. But this method 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 need perfect order. combining the evidence from all its justifications. ignore this current evidence. but it is significantly cheaper than the perfect method. At the beginning of each cycle. insert it into the agenda in-its proper place. recompute its rating and move it to the correct place in the list. The important resources to consider are time and space. When a new task is created. These measures are then combined at this step to produce an overall rating for the task. One way to do this is simple. When a task has its justifications changed. . Compute the new task's rating. If so. When a task is proposed. The following modified strategy may occasionally cause a task other than the best to be executed. do the following: i. go through the agenda and reorder it properly. Not all justifications need have equal weight. It can be thought of as an explicit statement of what to do next or simply as an indication of the next node to be expanded.

If. But the overhead for each task executed may be fairly high. Suppose each task is very small. the agenda mechanism provides a good way of focusing the attention of a complex system in the areas suggested by the greatest number of positive indicators. The exact choice of 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 too. But a smaller percentage of the total time will be" spent on the overhead of figuring out what to do. 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 bottom if new. If these negative weightings are used. Then we will never do even a very small thing unless it realjy is the best thing to do. There are some problem domains for which an agenda mechanism is inappropriate. The agenda"mechanism assumes that if there is good reason to do something now. As you can see. But we will spend a large percentage of our total effort on figuring out what to do next. negative justifications appear. particularly for systems that are interacting with people. This raises the question of (he proper grain size for the division of the entire problem-solving process into individual tasks. The following dialogue would not be acceptable to most people: Person: I don't want to read any more about China. Computer: What things about Italy are you interested in reading about? . Give me something ejse. But this is easy tq. Computer: OK. on the other hand. It often requires some experimentation to get right.do. This can be represented by justifications with negative weightings. the size of an individual task is very large. What else are you interested in? Person: How about Italy? I think I'd find Italy fascinating. then some effort may be spent finishing one task when there are more promising ones that could be done. But this is not always the case.An agenda-driven control structure is also useful if some tasks (or nodes) provide negative evidence about the merits of other tasks (or nodes). then there will also be the same good reason to do something later unless something better comes along in the interim.

Go to 1. else: 2.s-Queue) 3. topological distance) Value function on each Succ(Scurr) cost(path(S0. we abbreviate E(Scurr) General Form: 1. Snext:= Argmax[E(s-Queue)] 4. Manhattan.Q-3(a) Explain heuristic Search. Common Types of Heuristics "If-then" rules for state-transition selection Macro-operator formation [discussed later] Problem decomposition [e.SG))] Utility: value(S) – cost(S) Heuristic Search Value function: E(o-Path(S0. Quit if done (with success or failure). Their purpose is to minimize search on average. SG) Since S0 and SG are constant. Ans: Definition: A Heuristic is an operationally-effective nugget of information on how to direct search in a problem space. Heuristics are only approximately correct.g. Scurr)) + E[cost(path(Scurr. s-Queue:= F(Succ(Scurr). Euclidian. with Scurr:= Snext . (e. hypothesizing islands on the search path] Estimation of distance between Scurr and SG. Scurr.g. Scurr).

s-Queue) = Succ(Scurr) Snext:= Argmax[E(Succ(Scurr))] If Succ(Snext) is null. many animals and some machines. then backtrack Alternative: backtrack if E(Snext)<E(Scurr) Q-3(b) what is Intelligence and Artificial Intelligence? Ans: Intelligence: Intelligence is the computational part of the ability to achieve goals in the world. Varying kinds and degrees of intelligence occur in people.Steepest-Ascent Hill-Climbing F(Succ(Scurr). Artificial Intelligence: Artificial Intelligence (AI) is usually defined as the science of making computers do things that require intelligence when done by humans. . then stop Quintessential greedy search Max-Gradient Search "Informed" depth-first search Snext:= Argmax[E(Succ(Scurr))] But if Succ(Snext) is null.

Recall that preorder traversal simply visits each node before its children. which is closely related to preorder traversal of a tree.Q-3(c) List out merits & demerits of DFS & BFS. It is most easy to program as a recursive routine . Ans: Depth first search is another way of traversing graphs.

a list of nodes to be added to the tree.BFS: This can be throught of as being like Dijkstra's algorithm for shortest paths. We just keep a tree (the breadth first search tree). Nodes that do not have any children are called leaf nodes. They are also referred to as terminal nodes. trees are drawn growing downwards). A node is a structure which may contain a value. A free tree is a tree that is not rooted. A node has at most one parent. Q-3(d)(i)Construct The Semantic Net For The All Indian Likes Football Q-3(e) Ans: A Tree structure is a way of representing the hierarchical nature of a structure in a graphical form. a tree is a widely-used data structure that emulates a hierarchical tree structure with a set of linked nodes. which are below it in the tree (by convention. However it is a lot simpler and doesn't need any data structures. or superior). or represent a separate data structure (which could be a tree of its own). and markings (Boolean variables) on the vertices to tell whether they are in the tree or list. . a condition. Each node in a tree has zero or more child nodes. A node that has a child is called the child's parent node (or ancestor node. but with every edge having the same length. In computer science.

and assign an order to all the nodes. it is typically drawn at the top. The Expert System Shell is . This is commonly needed in the manipulation of the various self balancing trees. The 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. their parents. The result corresponds to a tree data structure. An expert system is. Being the topmost node. arbitrarily pick one of its vertices as the root. common representations represent the nodes as records allocated on the heap (not to be confused with the heap data structure) with pointers to their children. Conventionally. An internal node or inner node is any node of a tree that has child nodes and is thus not a leaf node. Picking a different root or different ordering produces a different one.The height of a node is the length of the longest downward path to a leaf from that node. and that no cycles are allowed.. trees and graphs are undirected. or both. We can take an arbitrary undirected tree. All other nodes can be reached from it by following edges or links. The Knowledge-base is a collection of rules encoded as metadata in a file system. whereas zero corresponds to a subtree with one node. AVL Trees in particular. a tree is a connected acyclic graph. its root path). the root node will not have parents. Tree representations There are many different ways to represent trees. composed of two major components. The topmost node in a tree is called the root node. In some trees. the root node has special properties. or more often in a relational database. typically. Relationship with trees in graph theory In graph theory. such as heaps. the Knowledge-base and the Expert System Shell. however. 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). Q-4(A) Explain Expert System Architecture In Artificial Intelligence. There is no one-to-one correspondence between such trees and trees as data structure. with relationships between them determined by their positions in the array Trees and graphs The tree data structure can be generalized to represent directed graphs by removing the constraints that a node may have at most one parent. the terms parent and child are usually replaced by different terminology. the value -1 corresponds to a subtree with no nodes. In diagrams. (In the formal definition. make all its edges directed by making them point away from the root node . Edges are still abstractly considered as pairs of nodes. Every node in a tree can be seen as the root node of the subtree rooted at that node. unless stated otherwise. each such path is also unique).e.producing an arborescence . or as items in an array. A sub tree of a tree T is a tree consisting of a node in T and all of its descendants in T.

• Execute business rules.2 Knowledge Base Editor The Knowledge-base Editor is a simple text editor. • Process requests for service from system users and application layer modules. build Abstract Syntax Trees during rule translation of business rules.).. Client Interface logic routes these requests to an appropriate shell program unit. Other service requests might schedule a rule. or some hybrid of these two types. when a subject matter expert wishes to create or edit a rule. or a group of rules. for execution by the Rule Engine. For example. etc. • Support the creation and modification of business rules by subject matter experts. and executing rules. 4. into machine-readable forms. 4. The shell portion includes software modules whose purpose it is to.a problem-independent component housing facilities for creating. and • Provide low-level support to expert system components (e. 4. It provides facilities that enable a subject matter expert to compose and add rules to the Knowledge-base. • Translate business rules.3 Rule Translator .1 Client Interface The Client Interface processes requests for service from system-users and from application layer components. editing.g. A software architecture for an expert system is illustrated in Figure 2. they use the Client Interface to dispatch the Knowledge-base Editor. a graphical editor. created by a subject matter experts. retrieve metadata from and save metadata to knowledge base.

. The AST representation of rules is the memory-resident data structure that guides execution of the inference engine when it comes time to apply a rule. Converting rules from one form to another is a function performed by the Rule Translator. like the one in Figure 4. The diagram in Figure 3 summarizes the several conversion operations the Rule Translator must perform as it adds rules to the Knowledge-base and as it retrieves rules from the Knowledge-base for execution. The specific scheme chosen for saving the metadata must permit the ASTs to be rapidly reconstructed using database queries. consider the arithmetic espression. The AST is an abstract data type designed to make its interpretation by the Rule Engine simple and efficient. In the AST representation. This abstract data type is very expressive and permits the construction of very complex and powerful rules. There is a third form in which rules may be expressed. that might form some part of a rule. as they are composed by subject matter experts. A rule AST is converted into an equivalent form suitable for storage in the Knowledge-base. Relational databases provide an especially convenient and efficient means for storing metadata. The way in which this information appears in the Knowledge-base depends on the storage technology. To make these ideas concrete. this portion of the rule would be expressed as a binary tree. The metadata corresponding to an AST in this case would reside in a collection of tables. (a-b) / [x*(c-d)] . are not directly executable. The translation of rules in their original form to a machine-readable form requires parsing the textual representation to obtain a data structure referred to as an Abstract Syntax Tree (AST).Rules. whose nodes are either arithmetic operators or operands. They must first be converted from their human-readable form into a form that can be interpreted by the Rule Engine.

The Rule Engine interpreter traverses the AST. The role of the Rule Translator in the rule editing process is illustrated in the data flow diagram of Figure 5. from its Knowledge-base representation or from its AST representation.4 Rule Engine The Rule Engine (often referred to as an inference engine in AI literature) is responsible for executing Knowledge-base rules. This process is depicted in Figure 6. exactly. It is always possible to recreate a human-readable rule.Once created. AST representations are converted into rule metadata and stored in the Knowledge-base. . Rule metadata is simply a compact representation of ASTs. It retrieves rules from the Knowledge-base. executing actions specified in the rule along the way. the structure of the original rule is never lost. In translating rules from one form to another. and then provides them to its rule interpreter for execution. converts them to ASTs. 4.

insert. Conversion of ASTs to rule metadata. . is a container for object classes supporting. and Knowledge-base operations (query. update. Conversion of rule metadata to ASTs.5 Rule Object Classes The shell component. AST construction. Rule Object Classes.4. • • • • • Rule editing. delete).

Q-4(b)Explain NLP A Closure View: Evaluation Of natural-language-understanding Systems: .

. Basic Idea Of AO* • First top-down graph growing picks out best available partial solution subgraph from explicit graph.Q-4(c)Explain AO* Algoritms. • Data Structure – Graph – Marked Connectors (down. unlike A*) – Costs q() maintained on nodes – SOLVED markings – Note: We’ll discuss on acyclic graphs.

End. Remove a node. add to S If s e TERM mark s Tracing the Algorithm: . Until s labeled SOLVED do: 1. n not in TERM. q(s) = h (s) SOLVED 2. Let S := {n}. 3. 2. 6. from S which has no descendent in G also in S (minimal node). 4. (check each connector from m) q(m)=min [c +q(n1)+…+q(nk )].• One leaf node of this graph is expanded Second. Select n in G’. reset q(n) := infinity ). Create G = <s> . Mark chosen connector. If all successors their connectors are SOLVED then mark m SOLVED. connector-marking. place successors in G. Label SOLVED all successors in TERM. 5. End. SOLVE-labeling AO* Algorithm: 1. 3. 4. n a leaf. bottom-up cost-revising. (If no successors. Until S = f do : 1. 2. Expand n . for each successor not already in G let q(successor)=h (successor). Revise cost for m. m. If m SOLVED or changed q(m) then all “preferred” parents of m. Compute G’ partial solution subgraph of G by tracing down marked connectors in G from s.

.

Que. . Ans. Explain nearest neighbour algorithm with example.6 A.

The sequence of the visited vertices is the output of the algorithm. from input to output. 6. In the worst case. set current vertex to V. 1. mark V as visited. but it can sometimes miss shorter routes which are easily noticed with human insight. then it is likely that there are much better tours. This type of organisation is also referred to as bottom-up or top-down. due to its "greedy" nature. From the remaining unvisited cities it selects the city closest to city two and so on. 1. Feedback networks are very powerful and can get extremely complicated.1 Feed-forward networks Feed-forward ANNs (figure 1) allow signals to travel one way only. Feedback networks are dynamic. Feed-forward ANNs tend to be straight forward networks that associate inputs with outputs. if they are much greater. then the tour is reasonable. To be precise.2 Feedback networks Feedback networks (figure 1) can have signals travelling in both directions by introducing loops in the network. then terminate. Moreover. if all the vertices in domain are visited. the output of any layer does not affect that same layer.e. 2. Explain architecture of ANN. Go to step 2. The nearest neighbor algorithm begins at the first city in your list of cities to visit. There is no feedback (loops) i. . It then selects the closest city to visit next. but usually not the optimal one. Ans. for every constant r there is an instance of the traveling salesman problem such that the length of the tour length computed by the nearest neighbour algorithm is greater than r times the length of the optimal tour. their 'state' is changing continuously until they reach an equilibrium point. 3. The nearest neighbour algorithm was one of the first algorithms used to determine a solution to the travelling salesman problem. Below is the application of nearest neighbour algorithm on TSP These are the steps of the algorithm: 1. They are extensively used in pattern recognition. for each number of cities there is an assignment of distances between the cities for which the nearest neighbor heuristic produces the unique worst possible tour B. It quickly yields a short tour. The nearest neighbour algorithm is easy to implement and executes quickly. the algorithm results in a tour that is much longer than the optimal tour. although the latter term is often used to denote feedback connections in single-layer organisations. As a general guide. They remain at the equilibrium point until the input changes and a new equilibrium needs to be found. Another check is to use an algorithm such as the lower bound algorithm to estimate if this tour is good enough. find out the lightest edge connecting current vertex and an unvisited vertex V.The nearest neighbor algorithm and the closely related repetitive nearest neighbor algorithm is a greedy algorithm for finding candidate solutions to the traveling salesman problem. Feedback architectures are also referred to as interactive or recurrent. 5. 4. if the last few stages of the tour are comparable in length to the first stages. stand on an arbitrary vertex as current vertex.

Perceptrons mimic the basic idea behind the mammalian visual system. The perceptron (figure 4. The activity of each hidden unit is determined by the activities of the input units and the weights on the connections between the input and the hidden units. and so by modifying these weights.4 .Ap are called association units and their task is to extract specific. of units: a layer of "input" units is connected to a layer of "hidden" units.4 Perceptrons The most influential work on neural nets in the 60's went under the heading of 'perceptrons' a term coined by Frank Rosenblatt. a hidden unit can choose what it represents We also distinguish single-layer and multi-layer architectures. Aj . which is connected to a layer of "output" units.3 Network layers The commonest type of artificial neural network consists of three groups. pre--processing. A2. fixed. in which all units are connected to one another.2 An example of a complicated network 1.4) turns out to be an MCP model ( neuron with weighted inputs ) with some additional. The behaviour of the output units depends on the activity of the hidden units and the weights between the hidden and output units. 1. Units labelled A1. units are often numbered by layer. The weights between the input and hidden units determine when each hidden unit is active.1 An example of a simple feedforward network Figure 1. This simple type of network is interesting because the hidden units are free to construct their own representations of the input. The single-layer organisation. They were mainly used in pattern recognition even though their capabilities extended a lot more. (see Figure 1.1) The activity of the input units represents the raw information that is fed into the network. localised featured from the input images.Figure 1. instead of following a global numbering. In multi-layer networks. or layers. constitutes the most general case and is of more potential computational power than hierarchically structured multi-layer organisations. Figure 1.

.. since there are plenty of traffic situations that can occur to slow down travel. Bus Time Tables How accurately do the schedules predict the actual travel time on the bus? Bus schedules are formulated on information that does not remain constant..m) if m(x) = 0. we wouldn't hear about cases of medical misdiagnosis.m) and the set is called its kernel. Unfortunately. traffic. It took me six hours to drive to Philadelphia last time. The question is. Therein lies the fuzzy logic. Many unforseen incidents can occur. Fuzzy set: A fuzzy set is a pair (A. The items in this list are more common applications that one may encounter in everyday life. An observant scheduler would take all these possibilities into account. Medical diagnoses How many of what kinds of symptoms will yield a diagnosis? How often are doctors in error? Surely everyone has seen those lists of symptoms for a horrible disease that say "if you have at least 5 of these symptoms. x is called fully included if m(x) = 1. accidents should all be added into the fuzzy equation to deliver a true estimate. Well. There is no guaranteed system to reach a diagnosis. more general variants of the notion of fuzzy set are used. so it should take me about that amount of time when I make the trip again. For a finite set A = {x1. For each . It is that formula which imposes the fuzziness Temperature control (heating/cooling) The trick in temperature control is to keep the room at the same temperature consistently. As with bus timetabling. Mention application of fuzzy logic.. Ans.[4] The set is called the support of (A. that seems pretty easy. There can be accidents.m(xn) / xn}. or the bus could break down. and include them in a formula for figuring out the approximate schedule. A major player in predicting travel time is previous experience. m(x) is called the grade of membership of x in (A. so the heat (or air conditioning) isn't in a constant state of turning on and off. That's why it is called an estimated time of arrival. Weather. Antilock Braking System It's probably something you hardly think about when you're slamming on the brakes in your car .m) is often denoted by {m(x1) / x1.m). usually it is required that L be at least a poset or lattice Crisp set: Application of fuzzy logic: There are countless applications for fuzzy logic. Membership in that set weakens as the room temperature varies from the set temperature. abnormal traffic backups. In fact. other factors are not typically considered.C. It is a hypochondriac's haven..xn}.m) where A is a set and . some claim that fuzzy logic is the encompassing theory over all types of logic. Once membership weakens to a certain point. with membership functions taking values in a (fixed or variable) algebra or structureL of a given kind. predicting ETA's is a great exercise in fuzzy logic. Let . Explain fuzzy set and crisp set. Predicting travel time This is especially difficult for driving. how do doctors go from that list of symptoms to a diagnosis? Fuzzy logic. construction.. temperature control kicks in to get the room back to the temperature it should be. They use fuzzy logic because it is impossible to give an exact answer to when the bus will be at a certain stop.. you are at risk".. Sometimes. right? But how much does a room have to cool off before the heat kicks in again? There must be some standard. The set is determined by what the temperature is actually set to. the fuzzy set (A. The diagnosis can only be some degree within the fuzzy set. If there were. and x is called fuzzy member if 0 <m(x) < 1. Then x is called not included in the fuzzy set (A.

The effect is undone if a new route is taken into the parent goal. We will first examine the effects of the cut/1 and then look at some practical reasons to use it . Here is the first test case. That is. data(pentiumIII) data(athlon). the times you want the ABS to really work are when you're driving fast and slam on the brakes. ?. The cut/1 effectively tells Prolog to freeze all the decisions made so far in this predicate. It is called the cut/1. There is. compare_cut_2(X) :data(X). This is the control case. which exhibits the normal behavior. a margin for error. which contained the cut/1. We will write some simple predicates that illustrate the behavior of the cut/1. compare_cut_1('last chip'). it re-routes backtracking. Note that it stops backtracking through both the data subgoal (left). and in the level above. first adding some data to backtrack over. Ans. represented by an exclamation point (!). pentiumIII no Next we put a cut/1 in the middle of two subgoals. pentiumIII–pentiumIII . When the cut/1 is encountered. It short-circuits backtracking in the goals to its left on its level. compare_cut_3(X. pentiumIII Athlon last chip no Next. compare_cut_3('last chip'). !. data(Y). if required to backtrack.compare_cut_2(X). write(X). The second data/1 to the right of (after) the cut is still free to backtrack.The point of an ABS is to monitor the braking system on the vehicle and release the brakes just before the wheels lock.Y). A computer is involved in determining when the best time to do this is. ?. of course. Note that the cut inhibits backtracking in the parent compare_cut_3/2 and in the goals to the left of before) the cut (first data). It has no cut/1 and will be used for comparison purposes. It is the job of the ABS to be "smart" enough to never allow the error go past the point when the wheels will lock D. That is.Y) :data(X). compare_cut_2('last chip'). compare_cut_1(X) :data(X). !. Prolog provides a predicate that performs this function. both the parent goal and the goals of the particular rule being execut/1ed are affected by the cut/1. Two main factors that go into determining this are the speed of the car when the brakes are applied. and the compare_cut_2/1 parent (above).compare_cut_3(X. write(X-Y). nl. Explain cut predicate in detail. Usually. it will automatically fail without trying other alternatives. ?. we put a cut/1 at the end of the first clause. write(X). nl.compare_cut_1(X). fail. and how fast the brakes are depressed. nl. fail. fail.

append('myotherfile.the ability to direct the inferential mechanisms into the most productive directions by storing appropriate guides. If myothertable.telling(X). cat lists file contents This is the first line Here is another line .the ability to acquire new knowledge using automatic methods wherever possible rather than reliance on human intervention. nl. there is no answer. usually the facts and rules of the program are stored in a (text) file. This is the first line. nl. too. Que. true. Example: ?. % the file mytable. When one wishes to stop writing to the file and resume writing on the screen. Various arguments can also be made as to its effect on code readability and maintainability. To direct this output to a file. a single line. The following properties should be possessed by a knowledge representation system.the ability to manipulate the knowledge represented to produce new knowledge corresponding to that inferred from the original. When one writes a Prolog program. write('Here is another line'). told.halt. nl. Representational Adequacy ->the ability to represent the required knowledge. we use the tell built-in predicate.data"). Subsequent writes will go to this file. putc. Suppose that we wish to write the table to a file called "mytable. It is often called the 'goto' of logic programming.data'). write('***** Table of results *****'). In this case you insert a cut/1 in the predicate at that point. you will use it when you want to force a predicate to fail in a certain situation. we tell Prolog that the new current output stream is to be the file "mytable.tell('mytable. tab and others to write out the table.data".bindsX to the name of the current output file. then X will be bound to something that indicates that the current output stream is the screen . Ans. Prolog has either found the only answer. the query ?. % cat myotherfile. but by default it will appear on the computer screen. For example. and then loaded into the Prolog interpreter.# is Unix comment char.data should now contain a single line of text as above The built-in Prolog predicate append/1 is like tell.5 A. X may be bound to the atom stdout (standard output. E. Acquisitional Efficiency . in Unix. rather than overwriting the file with the first subsequent write operation. By executing the (pseudo-)goal tell("mytable. This separates the logical purists from the pragmatists. except that it arranges for subsequent write operations to add data to the end of the specified file. Files have other uses in Prolog. or if it hasn't. If the current output stream is not a file. inferential Adequacy . You will most often use the cut/1 when you know that at a certain point in a given predicate. one uses the built-in predicate told (with no arguments). ?. Also.data". which is normally the screen).for example. say. we may wish to write out a table of results that have been computed for us by our Prolog program. and you don't want it to look any further. Inferential Efficiency . Similarly.data initially contains. Explain how file operation can be done in prolog? Ans.dat'). then append/1 works as follows: ?. One can use built-in predicates like write. Explain properties of good knowledge representation system.dat # .pentiumIII–Athlon no Performance is the main reason to use the cut/1.

Also.see('mydata.for example. Prolog binds the variable that was the argument to read to the special atom end_of_file. x[k]).c) k ← length(c) ifk = n thenreturn Λ elsereturn (c[1].s) k ← length(s) ifs[k] = m thenreturn Λ elsereturn (s[1]. The first and next procedures would then be functionfirst(P. nl. having been read from the file with read(X).bindsX to the name of the current input file.seeing(X).% The situation for reading from a file is analogous to writing (except that there is no analogue for append/1).text. 2. getc and others to read. …. Backtracking is a general algorithm for finding all (or some) solutions to some computational problem. the query ?. we tell Prolog that the new current input stream is to be the file mydata. The root candidate would then be the empty list ().c[2]. Term = end_of_file B. Subsequent reads will come from this file. for any k between 0 and n. If the current input stream is not a file. that satisfies some arbitrary constraint (boolean function) F. and the predicate F. Knowing this means that you can test after a read to make sure that you did not hit end of file. % the first Prolog term in the file mydata. that incrementally builds candidates to the solutions. …. one could define a partial candidate as a list of integers c = (c[1]. s[2]. then X will be bound to something that indicates that the current output stream is the screen . 1) functionnext(P. by default from the keyboard. …. 1 + s[k]) Here "length(c)" is the number of elements in the list c. Example: ?. … c[k]). c[2]. which is normally the keyboard). that are to be assigned to the first k variables x[1]. each in some range {1. write(X). …. and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution. in Unix. In a typical backtracking solution to this problem. read(X). …. s[k-1]. m}. x[n]). One can use built-in predicates like read. one uses the built-in predicate seen (with no arguments). Explain back tracing with example. What happens if you try to read from a file and there is nothing (left) to read. read(Term). and then % written to the screen with write(X) and nl. the instance data P would be the integersm and n. Ans. X may be bound to the atom stdin (standard input.dat'). Example:Constraint satisfaction The general constraint satisfaction problem consists in finding a list of integers x = (x[1]. By executing the (pseudo-)goal see('mydata.text').x[2]. or you have previously read everything there was to read in this file? In this case.text').x[2]. seen. c[k].text should now appear % on the screen. For this class of problems. When one wishes to stop reading from the file and resume reading from the keyboard. either because the file is empty. Example: ?. .see('empty.

domains integerlist=integer* predicates inter_union(integerlist. as it was changed before the choice point occurred.The call reject(P. it is unnecessary to revert the variable when the choice point is backtracked. WAP to form the union of two list. F = F[1] F[2] F[p]. Or Que. based on the values of the variables already assigned by it.5 A. Ans. then the reject procedure could simply check the terms F[i] that depend only on variables x[1]. or which have a greater impact on subsequent choices).integerlist) intersect(integerlist. It is generally better to order the list of variables so that it begins with the most critical ones (i. x[n].integerlist) member(integer. backtracking implementations commonly keep a variable trail. the ones with fewest value options. In fact.integerlist. without enumerating all those mn-kn-tuples. then accept(P. For example. One could also allow the next function to choose which variable should be assigned when extending a partial candidate. whether it has n elements. Further improvements can be obtained by the technique of constraint propagation. to record value change history. …. For backtracking to be effective. Assuming that reject is implemented as above. An alternative to the variable trail is to keep a timestamp of when the last change was made to the variable.e. x[k-1] will have been tested further up in the search tree. that is. The timestamp is compared to the timestamp of a choice point. since the terms that depend only on x[1]. x[k]. …. if F is the conjunction of several boolean predicates. …. In addition to retaining minimal recovery values used in backing up. If the choice point has an associated time later than that of the variable. and each F[i] depends only on a small subset of the variables x[1]. there must be a way to detect this situation. and return trueif any of those terms returns false.integerlist.c) should return true if the constraint F cannot be satisfied by any list of n integers that begins with the k elements of c.integerlist.integerlist) union(integerlist.L2):- . An efficient implementation will avoid creating a variable trail entry between two successive changes when there is no choice point. reject needs only check those terms that do depend on x[k]. at least for some candidatesc. as the backtracking will erase all of the changes as a single operation.integerlist) clauses inter_union(L1.c) needs only check whether c is complete.integerlist) delete(integer.

member(X.L2. delete(X.L2)).L2. delete(X. intersect([H|Tail1].[Y|Z]):- . write(L4). delete(H.L2.L2.Tail3):not(member(H.L3).L).L3.[]).L2.[X|_]).Tail3).L4).L2. write("\n Union\n").L2.Tail):!.L2). write(L4). union([H|Tail1].L2.L2.[Head|Tail]):not(X=Head).[H|Tail3]):member(H._. union(Tail1.L2.Tail). intersect([H|Tail1]. member(X. union(L1. intersect(Tail1.L2)). member(X.L4).[Y|Tail].[X|Tail]. union([].Tail3).write("Intersection\n").L.Tail3). nl. union([H|Tail1].[H|Tail3]):member(H. intersect(L1. intersect(Tail1. union(Tail1.L2).[H|Tail3]):not(member(H.Tail3). intersect([].

X.Xs):-!.[Y|Ys]):-minimum(Xs.[X|Zs]):-efface(Xs.14.minimum(Ys.Ys). efface([X|Xs].Z). Goal :seln_sort([1. minimum([_|Ys].Y.integer.integer) efface(list.X). Ans. minimum([].X.seln_sort(Zs.[]).Z):-Y<=X.integer. efface([Y|Xs].Z).efface([X|Xs].Y. minimum([Y|Ys].X.delete(X.3]X).Z):-minimum(Ys.Zs).X. seln_sort([].Tail.Y.list) clauses seln_sort([X|Xs]. B.X.Y.5.list) minimum(list. .!.Y.45.Z).Y).3.Zs). domains list=integer* predicates seln_sort(list. WAP to reverse the given list.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.