Problem Solving

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

PROBLEM SOLVING

Prepared by
Dr. Umakant Swami
• A tree data structure is a hierarchical data
structure that consists of nodes
connected by edges.
Tree Search • Each node can have multiple child nodes,
but only one parent node.
• The topmost node in the tree is called the
root node.
• A graph data structure is a collection of
nodes (also called vertices) and edges
that connect them.
Graph Search • Nodes can represent entities, such as
people, places, or things, while edges
represent relationships between those
entities.
Difference Between Graph and Tree
Feature Graph Tree

A collection of nodes (vertices) and edges, where A hierarchical data structure consisting of nodes
Definition
edges connect nodes. connected by edges with a single root node.
Can have cycles (loops) and disconnected No cycles; connected structure with exactly one
Structure
components. path between any two nodes.
No root node; nodes may have multiple parents or
Root Node Has a designated root node that has no parent.
no parents at all.
Parent-child relationship; each node (except the
Node Relationship Relationships between nodes are arbitrary.
root) has exactly one parent.
If there is n nodes then there would be n-
Edges Each node can have any number of edges.
1 number of edges
Traversal can be complex due to cycles and Traversal is straightforward and can be done in
Traversal Complexity
disconnected components. linear time.

Commonly used for hierarchical data


Used in various scenarios like social networks,
Application representation like file systems, organization
maps, network optimization, etc.
charts, HTML DOM, XML documents, etc.

Social networks, road networks, computer


Examples File systems, family trees, HTML DOM structure.
networks.
• Algorithms have information on the
goal state which helps in more
efficient searching.
• This information is obtained by a
function that estimates how close a
Informed state is to the goal state.
Search • Informed search in AI is a type of
search algorithm that uses additional
information to guide the search
process, allowing for more efficient
problem-solving compared to
uninformed search algorithms.
• Algorithms have no additional
information on the goal node other
than the one provided in the problem
definition.
• The plans to reach the goal state from
Uninformed the start state differ only by the order
Search and length of actions.
• Uninformed search in AI refers to a
type of search algorithm that does
not use additional information to
guide the search process.
Informed Search vs. Uninformed Search
Parameters Informed Search Uninformed Search

Known as It is also known as Heuristic Search. It is also known as Blind Search.


It doesn’t use knowledge for the searching
Using Knowledge It uses knowledge for the searching process.
process.
It finds solution slow as compared to an informed
Performance It finds a solution more quickly.
search.
Completion It may or may not be complete. It is always complete.

Cost Factor Cost is low. Cost is high.


It consumes less time because of quick It consumes moderate time because of slow
Time
searching. searching.
No suggestion is given regarding the solution in
Direction There is a direction given about the solution.
it.
Implementation It is less lengthy while implemented. It is more lengthy while implemented.
It is more efficient as efficiency takes into It is comparatively less efficient as incurred cost
Efficiency account cost and performance. The incurred cost is more and the speed of finding the Breadth-
is less and speed of finding solutions is quick. Firstsolution is slow.
Comparatively higher computational
Computational requirements Computational requirements are lessened.
requirements.
Having a wide scope in terms of handling large
Size of search problems Solving a massive search task is challenging.
search problems.
Greedy Search Depth First Search (DFS)

A* Search Breadth First Search (BFS)


Examples of Algorithms
AO* Search Branch and Bound

Hill Climbing Algorithm


• BFS, Breadth-First Search, is a vertex-
based technique for finding the
shortest path in the graph.
• It uses a Queue data structure that
Breadth- follows first in first out.
First Search • In BFS, one vertex is selected at a
(BFS): time when it is visited and marked
then its adjacent are visited and
stored in the queue.
• It is slower than DFS.
Example:
• DFS, Depth First Search, is an edge-
based technique.
Depth First • It uses the Stack data structure and
Search performs two stages, first visited
(DFS): vertices are pushed into the stack,
and second if there are no vertices
then visited vertices are popped.
Example:
Difference Between BFS and DFS:
Difference Between BFS and DFS:
Parameters BFS DFS

Stands for BFS stands for Breadth First Search. DFS stands for Depth First Search.

BFS(Breadth First Search) uses Queue data


Data Structure DFS(Depth First Search) uses Stack data structure.
structure for finding the shortest path.

DFS is also a traversal approach in which the


BFS is a traversal approach in which we first walk
traverse begins at the root node and proceeds
Definition through all nodes on the same level before
through the nodes as far as possible until we
moving on to the next level.
reach the node with no unvisited nearby nodes.

Conceptual Difference BFS builds the tree level by level. DFS builds the tree sub-tree by sub-tree.

It works on the concept of FIFO (First In First


Approach used It works on the concept of LIFO (Last In First Out).
Out).

BFS is more suitable for searching vertices closer DFS is more suitable when there are solutions
Suitable for
to the given source. away from source.

DFS is used in various applications such as acyclic


BFS is used in various applications such as
Applications graphs and finding strongly connected
bipartite graphs, shortest paths, etc.
components etc.
• The Branch and Bound Algorithm is a
method used in combinatorial optimization
problems to systematically search for the
best solution.
Informed • It works by dividing the problem into
search: smaller subproblems, or branches, and then
eliminating certain branches based on
Branch and bounds on the optimal solution.
Bound • This process continues until the best
solution is found or all branches have been
explored.
• Branch and Bound is commonly used in
problems like the traveling
salesman and job scheduling.
• In BFS and DFS, when we are at a node,
we can consider any of the adjacent as the
next node. So both BFS and DFS blindly
explore paths without considering any cost
Best First function.
Search • The idea of Best First Search is to use an
(Informed evaluation function to decide which
Search) adjacent is most promising and then
explore.

You might also like