SlideShare a Scribd company logo
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
Analysis of Pathfinding Algorithms
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

PPT
Regulafalsi_bydinesh
PPT
PPTX
CSGR(cluster switch gateway routing)
PDF
Mobile transportlayer
PPTX
Classical Sets & fuzzy sets
PPT
Graph theory
PDF
Kevin Knight, Elaine Rich, B. Nair - Artificial Intelligence (2010, Tata McGr...
PPTX
Application layer
Regulafalsi_bydinesh
CSGR(cluster switch gateway routing)
Mobile transportlayer
Classical Sets & fuzzy sets
Graph theory
Kevin Knight, Elaine Rich, B. Nair - Artificial Intelligence (2010, Tata McGr...
Application layer

What's hot (20)

PDF
Routing protocols in ad hoc network
PDF
B TREE ( a to z concept ) in data structure or DBMS
PPT
Lecture 6
PPTX
Iv defuzzification methods
PPTX
Distance Vector Routing Protocols
PPTX
AI - Local Search - Hill Climbing
PPT
Signal encoding techniques
PPTX
Switching techniques
PPTX
Destination Sequenced Distance Vector Routing (DSDV)
PPT
Routing algorithm network layer
PPT
Ee424 fading
PPTX
Introduction to Mobile Ad hoc Networks
PDF
Clock Synchronization in Distributed Systems
PPT
Deadlock Detection
PDF
introduction to graph theory
PPTX
Lecture 16 memory bounded search
PPTX
Security in wireless sensor network
PPT
Datalinklayer tanenbaum
PPTX
partialderivatives
PPT
Cyclic Groups and Subgroups in abstract algebra.ppt
Routing protocols in ad hoc network
B TREE ( a to z concept ) in data structure or DBMS
Lecture 6
Iv defuzzification methods
Distance Vector Routing Protocols
AI - Local Search - Hill Climbing
Signal encoding techniques
Switching techniques
Destination Sequenced Distance Vector Routing (DSDV)
Routing algorithm network layer
Ee424 fading
Introduction to Mobile Ad hoc Networks
Clock Synchronization in Distributed Systems
Deadlock Detection
introduction to graph theory
Lecture 16 memory bounded search
Security in wireless sensor network
Datalinklayer tanenbaum
partialderivatives
Cyclic Groups and Subgroups in abstract algebra.ppt
Ad

Similar to Analysis of Pathfinding Algorithms (20)

PPTX
Heuristic Searching Algorithms Artificial Intelligence.pptx
PDF
Ai1.pdf
PPTX
Unit ii-ppt
PDF
What is A * Search? What is Heuristic Search? What is Tree search Algorithm?
PPTX
informed search.pptx
PPTX
6CS4_AI_Unit-1.pptx helo to leairn dsa in a eay
PPTX
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PDF
artificial intelligence MTE E06_lec 3 _250225_114726.pdf
PPTX
A star algorithms
PPTX
Lec 15-graph Searching in data structure and lgorithm.pptx
PPTX
HEURISTIC SEARCH and other technique.pptx
PPTX
Basic Graph Algorithms Vertex (Node): lk
PPTX
Problem Solving through Search - Uninformed Search
PPTX
UNIT II ARTIFICIQL INTELLIGENCE SEARCH STRATEGIES OSMANIA UNIVERSITY
PDF
UNIT 2 - Artificial intelligence merged.pdf
PPTX
Best First Search.pptx
PPTX
BFS,DFS,Depth bound,Beam search,Iterative.pptx
PPT
artificial intelligence
PPTX
Search Algorithms in AI.pptx
PDF
Presentation on the artificial intelligenc
Heuristic Searching Algorithms Artificial Intelligence.pptx
Ai1.pdf
Unit ii-ppt
What is A * Search? What is Heuristic Search? What is Tree search Algorithm?
informed search.pptx
6CS4_AI_Unit-1.pptx helo to leairn dsa in a eay
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
artificial intelligence MTE E06_lec 3 _250225_114726.pdf
A star algorithms
Lec 15-graph Searching in data structure and lgorithm.pptx
HEURISTIC SEARCH and other technique.pptx
Basic Graph Algorithms Vertex (Node): lk
Problem Solving through Search - Uninformed Search
UNIT II ARTIFICIQL INTELLIGENCE SEARCH STRATEGIES OSMANIA UNIVERSITY
UNIT 2 - Artificial intelligence merged.pdf
Best First Search.pptx
BFS,DFS,Depth bound,Beam search,Iterative.pptx
artificial intelligence
Search Algorithms in AI.pptx
Presentation on the artificial intelligenc
Ad

Recently uploaded (20)

PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
history of c programming in notes for students .pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Essential Infomation Tech presentation.pptx
PDF
Complete React Javascript Course Syllabus.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Materi-Enum-and-Record-Data-Type (1).pptx
ISO 45001 Occupational Health and Safety Management System
history of c programming in notes for students .pptx
Online Work Permit System for Fast Permit Processing
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms I-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
2025 Textile ERP Trends: SAP, Odoo & Oracle
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Essential Infomation Tech presentation.pptx
Complete React Javascript Course Syllabus.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
How to Migrate SBCGlobal Email to Yahoo Easily
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

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
  • 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).