SlideShare a Scribd company logo
1 of 34
Download to read offline
Analysis of Pathfinding Algorithms
Group SY4
Why Bother?
Applications
● Pathfinding on Maps
● Routing Systems
eg. Internet
● Pathfinding in Games
eg. Enemies, etc.
Dijkstra’s Algorithm
Overview
Dijkstra's algorithm - Works on both directed and undirected graphs. However, all edges
must have nonnegative weights.
Input:
Weighted graph G={E,V} and source vertex v∈V, such that all edge weights are
nonnegative
Output:
Lengths of shortest paths (or the shortest paths themselves) from a given source
vertex v∈V to all other vertices
Algorithm
1. Let distance of start vertex from start vertex = 0
2. Let distance of all other vertices from start = infinity
3. Repeat
a. Visit the unvisited vertex with the smallest known distance from the start
vertex
b. For the current vertex, examine its unvisited neighbours
c. For the current vertex, calculate distance of each neighbour from start
vertex
d. If the calculated distance of a vertex is less than the known distance,
update the shortest distance
e. Update the previous vertex for each of the updated distances
f. Add the current vertex to the list of visited vertices
4. Until all vertices visited
Time Complexity (List)
The simplest implementation of the Dijkstra's algorithm stores vertices in an ordinary linked list or
array
V vertices and E edges
Initialization O(V)
While loop O(V)
Find and remove min distance vertices O(V)
Potentially E updates
Update costs O(1)
Total time O(V2
+ E) = O(V2
)
Time Complexity (Priority Queue)
For sparse graphs, (i.e. graphs with much less than |V2
| edges) Dijkstra's implemented more
efficiently by priority queue
Initialization O(V) using O(V) buildHeap
While loop O(V)
Find and remove min distance vertices O(log V) using O(log V) deleteMin
Potentially E updates
Update costs O(log V) using decreaseKey
Total time O(VlogV + ElogV) = O(ElogV)
BFS
Overview
Breadth First Search Algorithm (BFS) is a traversing algorithm where you
should start traversing from a selected node (source or starting node) and
traverse the graph layerwise thus exploring the neighbour nodes (nodes which
are directly connected to source node). You must then move towards the
next-level neighbour nodes.
Approach
Idea: Traverse nodes in layers.
Problem: There are cycles in graphs, so each node will be visited infinite times.(does not
occur in trees.)
Approach:
1) Add root node to the queue, and mark it as visited(already explored).
2) Loop on the queue as long as it's not empty.
a) Get and remove the node at the top of the queue(current).
b) For every non-visited child of the current node, do the following:
i) Mark it as visited.
ii) Check if it's the goal node, If so, then return it.
iii) Otherwise, push it to the queue.
3) If queue is empty, then goal node was not found!
Steps by step BFS
Pseudocode
BFS (G, s) //Where G is the graph and s is the source node
let Q be queue.
Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked.
mark s as visited.
while ( Q is not empty) It will run ‘V’ times.
//Removing that vertex from queue,whose neighbour will be visited now
v = Q.dequeue( )
//processing all the neighbours of v
for all neighbours w of v in Graph G It will run ‘E’ times.
if w is not visited
Q.enqueue( w ) //Stores w in Q to further visit its neighbour
mark w as visited.
Time complexity
Time complexity of Breadth First Search is O( V + E ).
Where, V = Number of vertices.
E = Number of edges.
Depth First Search (DFS)
Overview
Depth-first search(DFS) is an algorithm for traversing or searching tree
or graph data structures. The algorithm starts at the root node
(selecting some arbitrary node as the root node in the case of a graph)
and explores as far as possible along each branch before backtracking.
Algorithm
1) Start by putting any one of the graphs vertices on the top of the stack.
2) Take the top item of the stack and add it to the visited list.
3) Create a list of that vertex adjacent nodes. Add the ones which aren’t in the
visited list to the top of the stack.
4) Keep repeating steps 2 and 3 until the stack is empty.
Example
Example
Time Complexity
The time complexity of DFS is the entire tree is traversed is
O(V) where V is the number of nodes. In the case of the
graph, the time complexity is O(V+E) where V is the number
of vertices and E is the number of edges
Best First Search
Overview
Best first search is a traversal technique that decides which node is to be
visited next by checking which node is the most promising one and then
check it.
How it works
● Best First Search falls under the
category of Heuristic Search or
Informed Search.
● It uses an evaluation function to
decide which adjacent is most
promising and then explore.
● Performance of the algorithm
depends on how well the cost
function is designed.
Example
Heuristic Function:
Greedy Best First Search
f(node)= Euclidean Distance between
B and E (Goal)
f(A)= 100
f(B)= 90
f(C)= 105
1
0
0
9
0
1
0
5
Pseudocode
Best-First-Search(Grah g, Node start)
1) Create an empty PriorityQueue
PriorityQueue pq;
2) Insert "start" in pq.
pq.insert(start)
3) Until PriorityQueue is empty
u = PriorityQueue.DeleteMin
If u is the goal
Exit
Else
Foreach neighbor v of u
If v "Unvisited"
Mark v "Visited"
pq.insert(v)
Mark u "Examined"
End procedure
Time Complexity
The worst case time complexity of the algorithm is given by O(n*logn)
Performance of the algorithm depends on the cost or evaluation function
A-star
Overview
A* is an informed search algorithm, or a best-first search, meaning that it is formulated in
terms of weighted graphs: starting from a specific starting node of a graph, it aims to find
a path to the given goal node having the smallest cost (least distance travelled, shortest
time, etc.). What A* search algorithm does it that at each step it picks the node according
to a value of F which is the sum of ‘g’ and ‘h’.at each step it picks the node having the
lowest ‘f’ and then process it.
f(n) = g(n) + h(n)
ALGORITHM
Step 1: Place the starting node into OPEN and find its f(n) value.
Step 2: Remove the node from OPEN, having the smallest f(n) value.
If it is a goal node then stop and return success.
Step 3: Else remove the node from OPEN, find all its successors.
Step 4: Find the f(n) value of all successors; place them into OPEN
and place the removed node into CLOSE.
Step 5: Go to Step-2.
Step 6: Exit.
Setup
To find the shortest path between A and J
TIME COMPLEXITY
When using the optimal heuristic, A* will be O(n) in both space and time complexity if
we disregard the complexity of the heuristic calculation itself. Again n is the length of
the solution path.
ADVANTAGES AND DISADVANTAGES
● It is the best one from other techniques to solve
very complex problems.
● It is optimally efficient, i.e. there is no other
optimal algorithm guaranteed to expand fewer
nodes than A*.
● This algorithm is complete if the branching factor
is finite and every action has fixed cost.
● The speed execution of A* search is highly
dependant on the accuracy of the heuristic
algorithm that is used to compute h (n).
Thank You

More Related Content

What's hot

Лекция 9: Графы. Поиск кратчайшего пути в графе
Лекция 9: Графы. Поиск кратчайшего пути в графеЛекция 9: Графы. Поиск кратчайшего пути в графе
Лекция 9: Графы. Поиск кратчайшего пути в графе
Mikhail Kurnosov
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
 

What's hot (20)

Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
Лекция 9: Графы. Поиск кратчайшего пути в графе
Лекция 9: Графы. Поиск кратчайшего пути в графеЛекция 9: Графы. Поиск кратчайшего пути в графе
Лекция 9: Графы. Поиск кратчайшего пути в графе
 
Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)Depth first traversal(data structure algorithms)
Depth first traversal(data structure algorithms)
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
I.ITERATIVE DEEPENING DEPTH FIRST SEARCH(ID-DFS) II.INFORMED SEARCH IN ARTIFI...
I.ITERATIVE DEEPENING DEPTH FIRST SEARCH(ID-DFS) II.INFORMED SEARCH IN ARTIFI...I.ITERATIVE DEEPENING DEPTH FIRST SEARCH(ID-DFS) II.INFORMED SEARCH IN ARTIFI...
I.ITERATIVE DEEPENING DEPTH FIRST SEARCH(ID-DFS) II.INFORMED SEARCH IN ARTIFI...
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Depth First Search ( DFS )
Depth First Search ( DFS )Depth First Search ( DFS )
Depth First Search ( DFS )
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
 
AI Greedy and A-STAR Search
AI Greedy and A-STAR SearchAI Greedy and A-STAR Search
AI Greedy and A-STAR Search
 
Topological sort
Topological sortTopological sort
Topological sort
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Graph coloring Algorithm
Graph coloring AlgorithmGraph coloring Algorithm
Graph coloring Algorithm
 
Hypergraphs
HypergraphsHypergraphs
Hypergraphs
 
1.8 splay tree
1.8 splay tree 1.8 splay tree
1.8 splay tree
 

Similar to Analysis of Pathfinding Algorithms

graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 
IntroductionTopological sorting is a common operation performed .docx
IntroductionTopological sorting is a common operation performed .docxIntroductionTopological sorting is a common operation performed .docx
IntroductionTopological sorting is a common operation performed .docx
mariuse18nolet
 

Similar to Analysis of Pathfinding Algorithms (20)

Unit ii-ppt
Unit ii-pptUnit ii-ppt
Unit ii-ppt
 
Lecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdf
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
A star algorithms
A star algorithmsA star algorithms
A star algorithms
 
Graphs
GraphsGraphs
Graphs
 
Lecture13
Lecture13Lecture13
Lecture13
 
IntroductionTopological sorting is a common operation performed .docx
IntroductionTopological sorting is a common operation performed .docxIntroductionTopological sorting is a common operation performed .docx
IntroductionTopological sorting is a common operation performed .docx
 
Link Prediction in the Real World
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Graphs
GraphsGraphs
Graphs
 
Graps 2
Graps 2Graps 2
Graps 2
 
Unit 3 Informed Search Strategies.pptx
Unit  3 Informed Search Strategies.pptxUnit  3 Informed Search Strategies.pptx
Unit 3 Informed Search Strategies.pptx
 
Adsa u2 ver 1.0.
Adsa u2 ver 1.0.Adsa u2 ver 1.0.
Adsa u2 ver 1.0.
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Graph
GraphGraph
Graph
 
Topological Sort
Topological SortTopological Sort
Topological Sort
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
hospital management
hospital managementhospital management
hospital management
 
Heuristic Searching: A* Search
Heuristic Searching: A* SearchHeuristic Searching: A* Search
Heuristic Searching: A* Search
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

Analysis of Pathfinding Algorithms

  • 1. Analysis of Pathfinding Algorithms Group SY4
  • 3. Applications ● Pathfinding on Maps ● Routing Systems eg. Internet ● Pathfinding in Games eg. Enemies, etc.
  • 5. Overview Dijkstra's algorithm - Works on both directed and undirected graphs. However, all edges must have nonnegative weights. Input: Weighted graph G={E,V} and source vertex v∈V, such that all edge weights are nonnegative Output: Lengths of shortest paths (or the shortest paths themselves) from a given source vertex v∈V to all other vertices
  • 6.
  • 7. Algorithm 1. Let distance of start vertex from start vertex = 0 2. Let distance of all other vertices from start = infinity 3. Repeat a. Visit the unvisited vertex with the smallest known distance from the start vertex b. For the current vertex, examine its unvisited neighbours c. For the current vertex, calculate distance of each neighbour from start vertex d. If the calculated distance of a vertex is less than the known distance, update the shortest distance e. Update the previous vertex for each of the updated distances f. Add the current vertex to the list of visited vertices 4. Until all vertices visited
  • 8. Time Complexity (List) The simplest implementation of the Dijkstra's algorithm stores vertices in an ordinary linked list or array V vertices and E edges Initialization O(V) While loop O(V) Find and remove min distance vertices O(V) Potentially E updates Update costs O(1) Total time O(V2 + E) = O(V2 )
  • 9. Time Complexity (Priority Queue) For sparse graphs, (i.e. graphs with much less than |V2 | edges) Dijkstra's implemented more efficiently by priority queue Initialization O(V) using O(V) buildHeap While loop O(V) Find and remove min distance vertices O(log V) using O(log V) deleteMin Potentially E updates Update costs O(log V) using decreaseKey Total time O(VlogV + ElogV) = O(ElogV)
  • 10. BFS
  • 11. Overview Breadth First Search Algorithm (BFS) is a traversing algorithm where you should start traversing from a selected node (source or starting node) and traverse the graph layerwise thus exploring the neighbour nodes (nodes which are directly connected to source node). You must then move towards the next-level neighbour nodes.
  • 12. Approach Idea: Traverse nodes in layers. Problem: There are cycles in graphs, so each node will be visited infinite times.(does not occur in trees.) Approach: 1) Add root node to the queue, and mark it as visited(already explored). 2) Loop on the queue as long as it's not empty. a) Get and remove the node at the top of the queue(current). b) For every non-visited child of the current node, do the following: i) Mark it as visited. ii) Check if it's the goal node, If so, then return it. iii) Otherwise, push it to the queue. 3) If queue is empty, then goal node was not found!
  • 14. Pseudocode BFS (G, s) //Where G is the graph and s is the source node let Q be queue. Q.enqueue( s ) //Inserting s in queue until all its neighbour vertices are marked. mark s as visited. while ( Q is not empty) It will run ‘V’ times. //Removing that vertex from queue,whose neighbour will be visited now v = Q.dequeue( ) //processing all the neighbours of v for all neighbours w of v in Graph G It will run ‘E’ times. if w is not visited Q.enqueue( w ) //Stores w in Q to further visit its neighbour mark w as visited.
  • 15. Time complexity Time complexity of Breadth First Search is O( V + E ). Where, V = Number of vertices. E = Number of edges.
  • 17. Overview Depth-first search(DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking.
  • 18. Algorithm 1) Start by putting any one of the graphs vertices on the top of the stack. 2) Take the top item of the stack and add it to the visited list. 3) Create a list of that vertex adjacent nodes. Add the ones which aren’t in the visited list to the top of the stack. 4) Keep repeating steps 2 and 3 until the stack is empty.
  • 21. Time Complexity The time complexity of DFS is the entire tree is traversed is O(V) where V is the number of nodes. In the case of the graph, the time complexity is O(V+E) where V is the number of vertices and E is the number of edges
  • 23. Overview Best first search is a traversal technique that decides which node is to be visited next by checking which node is the most promising one and then check it.
  • 24. How it works ● Best First Search falls under the category of Heuristic Search or Informed Search. ● It uses an evaluation function to decide which adjacent is most promising and then explore. ● Performance of the algorithm depends on how well the cost function is designed.
  • 25. Example Heuristic Function: Greedy Best First Search f(node)= Euclidean Distance between B and E (Goal) f(A)= 100 f(B)= 90 f(C)= 105 1 0 0 9 0 1 0 5
  • 26. Pseudocode Best-First-Search(Grah g, Node start) 1) Create an empty PriorityQueue PriorityQueue pq; 2) Insert "start" in pq. pq.insert(start) 3) Until PriorityQueue is empty u = PriorityQueue.DeleteMin If u is the goal Exit Else Foreach neighbor v of u If v "Unvisited" Mark v "Visited" pq.insert(v) Mark u "Examined" End procedure
  • 27. Time Complexity The worst case time complexity of the algorithm is given by O(n*logn) Performance of the algorithm depends on the cost or evaluation function
  • 29. Overview A* is an informed search algorithm, or a best-first search, meaning that it is formulated in terms of weighted graphs: starting from a specific starting node of a graph, it aims to find a path to the given goal node having the smallest cost (least distance travelled, shortest time, etc.). What A* search algorithm does it that at each step it picks the node according to a value of F which is the sum of ‘g’ and ‘h’.at each step it picks the node having the lowest ‘f’ and then process it. f(n) = g(n) + h(n)
  • 30. ALGORITHM Step 1: Place the starting node into OPEN and find its f(n) value. Step 2: Remove the node from OPEN, having the smallest f(n) value. If it is a goal node then stop and return success. Step 3: Else remove the node from OPEN, find all its successors. Step 4: Find the f(n) value of all successors; place them into OPEN and place the removed node into CLOSE. Step 5: Go to Step-2. Step 6: Exit.
  • 31. Setup To find the shortest path between A and J
  • 32. TIME COMPLEXITY When using the optimal heuristic, A* will be O(n) in both space and time complexity if we disregard the complexity of the heuristic calculation itself. Again n is the length of the solution path.
  • 33. ADVANTAGES AND DISADVANTAGES ● It is the best one from other techniques to solve very complex problems. ● It is optimally efficient, i.e. there is no other optimal algorithm guaranteed to expand fewer nodes than A*. ● This algorithm is complete if the branching factor is finite and every action has fixed cost. ● The speed execution of A* search is highly dependant on the accuracy of the heuristic algorithm that is used to compute h (n).