Expert Systems
What Are Expert Systems
● Expert systems are advanced computer applications that mimic the decision-
making ability of a human expert.
● Designed to solve complex problems by reasoning through bodies of
knowledge, represented mainly as if-then rules.
● The first expert systems were created in the 1970s and then proliferated in the
1980s.
● Help in decision making in fields where human expertise is limited or costly.
History of Expert System
● The software program Dendral is considered the first expert system because it automated the
decision-making process and problem-solving behavior of organic chemists.
● Its primary aim was to study hypothesis formation and discovery in science. For that, a
specific task in science was chosen help organic chemists in identifying unknown organic
molecules, by analyzing their mass spectra and using knowledge of chemistry.
● It was done at Stanford University by Edward Feigenbaum, Bruce G. Buchanan, Joshua
Lederberg, and Carl Djerassi, along with a team of highly creative research associates and
students.
● It began in 1965 and spans approximately half the history of AI research.
Plant Disease Diagnosis System
Various expert systems are used in agriculture to
diagnose plant diseases, recommend treatment,
and even predict disease development based on
symptoms, environmental factors, and crop
conditions.
Example: Making of a medical diagnosis expert system
A medical diagnosis expert system lets the user diagnose his disease without
going to a real doctor (but of course, user has to go to a real doctor for
treatment)
How does medical diagnosis expert system gain expertise?
Components of Expert Systems
Development of Expert Systems
Application of Expert System
Benefits of Expert Systems
● Availability
● Less Production Cost
● Speed
● Less Error rate
● Reducing Risk
● Steady Response
Limitations
⚫ Knowledge Acquisition
⚫ Handling Uncertain and Incomplete Information
⚫ Complexity of System Maintenance
⚫ Scalability
Search Algorithms
What Are Search Algorithms?
Definition: Search algorithms are methods for solving problems by exploring a
problem space to find a solution or a path to a solution.
Significance: Crucial for automating decision-making processes in AI and other
intelligent systems.
Essential for navigating through large data sets or complex problem spaces.
Role of Search Algorithms
Essential for navigating through large data
sets or complex problem spaces.
● Pathfinding: Pathfinding for robotics,
Finding the shortest path between two
points.
● Puzzle Solving: E.g., solving Sudoku or
the Rubik's Cube.
● Optimization: E.g., finding the best
configuration for network settings
Evaluating Search Algorithms
● Completeness: Can the algorithm always find a solution if one exists?
● Optimality: Does the algorithm find the best solution?
● Time Complexity: How does the algorithm scale with the size of the input?
● Space Complexity: How much memory does the algorithm require during
execution?
Uninformed Search Strategies
Uninformed search algorithms, also known as blind search, do not use additional
information about states beyond the defined problem space.
They operate under the assumption that all nodes are equally likely to lead to a
solution.
Examples:
● Breadth-First Search (BFS)
● Depth-First Search (DFS)
● Uniform Cost Search
Breadth First Search
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to
as a ‘search key’), and explores all of the neighbor nodes at the present depth prior to moving
on to the nodes at the next depth level.
It is of the most common search strategies. It generally starts from the root node and
examines the neighbor nodes and then moves to the next level. It uses First-in First-out
(FIFO) strategy as it gives the shortest path to achieving the solution.
BFS is used where the given problem is very small and space complexity is not considered.
Example
Example
Example
The above image depicts the end-to-end process of Breadth-First Search Algorithm. For an in-dept
explanation:
Assign ‘a’ as the root node and insert it into the Queue.
Extract node ‘a’ from the queue and insert the child nodes of ‘a’, i.e., ‘b’ and ‘c’.
Print node ‘a’.
The queue is not empty and has node ‘b’ and ‘c’. Since ‘b’ is the first node in the queue, let’s extract it and
insert the child nodes of ‘b’, i.e., node ‘d’ and ‘e’.
Repeat these steps until the queue gets empty. Note that the nodes that are already visited should not be
added to the queue again.
BFS Algorithm
Set a variable NODE to the initial state, i.e., the root node.
Set a variable GOAL which contains the value of the goal state.
Loop each node by traversing level by level until the goal state is not found.
While performing the looping, start removing the elements from the queue in FIFO
order.
If the goal state is found, return goal state otherwise continue the search.
Why do we need BFS Algorithm?
● There are numerous reasons to utilize the BFS Algorithm to use as searching for your dataset.
Some of the most vital aspects that make this algorithm your first choice are:
● BFS is useful for analyzing the nodes in a graph and constructing the shortest path of
traversing through these.
● BFS can traverse through a graph in the smallest number of iterations.
● The architecture of the BFS algorithm is simple and robust.
● The result of the BFS algorithm holds a high level of accuracy in comparison to other
algorithms.
● BFS iterations are seamless, and there is no possibility of this algorithm getting caught up in
an infinite loop problem.
Applications of BFS Algorithm
● Let’s take a look at some of the real-life applications where a BFS algorithm implementation can be highly
effective.
● Un-weighted Graphs: BFS algorithm can easily create the shortest path and a minimum spanning tree to visit
all the vertices of the graph in the shortest time possible with high accuracy.
● P2P Networks: BFS can be implemented to locate all the nearest or neighboring nodes in a peer to peer
network. This will find the required data faster.
● Web Crawlers: Search engines or web crawlers can easily build multiple levels of indexes by employing BFS.
BFS implementation starts from the source, which is the web page, and then it visits all the links from that
source.
● Navigation Systems: BFS can help find all the neighboring locations from the main or source location.
● Network Broadcasting: A broadcasted packet is guided by the BFS algorithm to find and reach all the nodes
it has the address for.
Depth-first search
The depth-first search uses Last-in, First-out (LIFO) strategy and hence it can be
implemented by using stack. DFS uses backtracking. That is, it starts from the
initial state and explores each path to its greatest depth before it moves to the
next path.
DFS will follow
Now, consider the same example tree on the side. The path of traversal is:
Here, it starts from the start state A and then travels to A —-> B —-> D —-> E —-> C —-> F
B and then it goes to D. After reaching
D, it backtracks to B. B is already visited, hence it goes
to the next depth E and then backtracks to B. as it is
already visited, it goes back to A. A is already visited.
So, it goes to C and then to F. F is our goal state and it
stops there.
DFS Algorithm
Set a variable NODE to the initial state, i.e., the root node.
Set a variable GOAL which contains the value of the goal state.
Loop each node by traversing deeply in one direction/path in search of the goal node.
While performing the looping, start removing the elements from the stack in LIFO order.
If the goal state is found, return goal state otherwise backtrack to expand nodes in
other direction.
DFS
Advantages of DFS
● It takes lesser memory as compared to BFS.
● The time complexity is lesser when compared to BFS.
● DFS does not require much more search.
Disadvantages of DFS
● DFS does not always guarantee to give a solution.
● As DFS goes deep down, it may get trapped in an infinite loop.
Application of DFS Algorithm
● For finding the path
● For finding the strongly connected components of a graph
● For detecting cycles in a graph
Difference between BFS and DFS
What is uniform-cost search?
Uniform-cost search is an uninformed search algorithm that uses the lowest
cumulative cost to find a path from the source to the destination. Nodes are
expanded, starting from the root, according to the minimum cumulative cost. The
uniform-cost search is then implemented using a Priority Queue.
Algorithm for uniform cost search:
Insert the root node into the priority queue
Repeat while the queue is not empty:
Remove the element with the highest priority
If the removed node is the destination, print total cost and stop the algorithm
Else, enqueue all the children of the current node to the priority queue, with their
cumulative cost from the root as priority
Example
Advantages & disadvantages of UCS
Advantages:
Uniform cost search is optimal because at every state the path with the least cost
is chosen.
Disadvantages:
It does not care about the number of steps involve in searching and only
concerned about path cost. Due to which this algorithm may be stuck in an infinite
loop.
Informed search algorithms
Informed search algorithm
The informed search algorithm is also called heuristic search or directed search. In
contrast to uninformed search algorithms, informed search algorithms require
details such as distance to reach the goal, steps to reach the goal, cost of the
paths which makes this algorithm more efficient.
Here, the goal state can be achieved by using the heuristic function.
The heuristic function is used to achieve the goal state with the lowest cost
possible. This function estimates how close a state is to the goal.
Heuristic function
The heuristic function is used in Informed Search, and it finds the most promising path. It takes the
current state of the agent as its input and produces the estimation of how close the agent is from
the goal. The heuristic method, however, might not always give the best solution, but it guaranteed
to find a good solution in a reasonable time. Heuristic function estimates how close a state is to
the goal. It is represented by h(n), and it calculates the cost of an optimal path between the pair of
states. The value of the heuristic function is always positive.
Admissibility of the heuristic function is given as:
h(n) <= h*(n)
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less
than or equal to the estimated cost.
1. Greedy best-first search algorithm
Greedy best-first search uses the properties of both depth-first search and
breadth-first search. Greedy best-first search traverses the node by selecting the
path which appears best at the moment. The closest path is selected by using the
heuristic function.
Consider the below
graph with the heuristic values.
Greedy best-first search algorithm
Greedy best-first search algorithm
Here, A is the start node and H is the goal node.
Greedy best-first search first starts with A and then examines the next neighbour B
and C. Here, the heuristics of B is 12 and C is 4. The best path at the moment is C
and hence it goes to C. From C, it explores the neighbours F and G. the heuristics
of F is 8 and G is 2. Hence it goes to G. From G, it goes to H whose heuristic is 0
which is also our goal state.
Greedy best-first search algorithm
Advantages of Greedy best-first search
● Greedy best-first search is more efficient compared with breadth-first search and depth-
first search.
Disadvantages of Greedy best-first search
● In the worst-case scenario, the greedy best-first search algorithm may behave like an
unguided DFS.
● There are some possibilities for greedy best-first to get trapped in an infinite loop.
● The algorithm is not an optimal one.
A* search algorithm
A* search algorithm is a combination of both uniform cost search and greedy best-
first search algorithms. It uses the advantages of both with better memory usage.
It uses a heuristic function to find the shortest path. A* search algorithm uses the
sum of both the cost and heuristic of the node to find the best path.
Example
Consider the following graph with the heuristics values as follows.
Example
Let A be the start node and H be the goal node.
First, the algorithm will start with A. From A, it Here, path A to C is of less cost. That is 6.
can go to B, C, H. Hence, A to C is chosen and other paths are kept
Note the point that A* search uses the sum of on hold.
path cost and heuristics value to determine the From C, it can now go to F or G.
path. From A to C to F, the cost is 2 + 3 + 3 = 8.
Here, from A to B, the sum of cost and heuristics From A to C to G, the cost is 2 + 2 + 1 = 5.
is 1 + 3 = 4. The lowest cost is 5 which is also lesser than
From A to C, it is 2 + 4 = 6. other paths which are on hold. Hence, path A to
From A to H, it is 7 + 0 = 7. G is chosen.
Here, the lowest cost is 4 and the path A to B is From G, it can go to H whose cost is 2 + 2 + 2 + 0
chosen. The other paths will be on hold. = 6.
Now, from B, it can go to D or E. Here, 6 is lesser than other paths cost which is
From A to B to D, the cost is 1 + 4 + 2 = 7. on hold.
From A to B to E, it is 1 + 6 + 6 = 13. Also, H is our goal state. The algorithm will
The lowest cost is 7. Path A to B to D is chosen terminate here.
and compared with other paths which are on
hold.
A* search algorithm
Advantages of A* search algorithm
● This algorithm is best when compared with other algorithms.
● This algorithm can be used to solve very complex problems also it is an optimal
one.
Disadvantages of A* search algorithm
● The A* search is based on heuristics and cost. It may not produce the shortest
path.
● The usage of memory is more as it keeps all the nodes in the memory.
END