Analysis of Pathfinding Algorithms

SigSegVSquad
SigSegVSquadSigSegVSquad
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
1 de 34

Recomendados

09 bsc-17 dsp lab 10-1 por
09 bsc-17 dsp lab 10-109 bsc-17 dsp lab 10-1
09 bsc-17 dsp lab 10-1Jannat41
53 visualizações6 slides
matlab code of shifting and folding of two sequences por
matlab code of shifting and folding of two sequencesmatlab code of shifting and folding of two sequences
matlab code of shifting and folding of two sequencesRakesh kumar jha
1.3K visualizações2 slides
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ... por
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...AAKASH KUMAR
491 visualizações13 slides
MATLAB CODE OF Shifting sequence por
MATLAB  CODE  OF Shifting sequenceMATLAB  CODE  OF Shifting sequence
MATLAB CODE OF Shifting sequenceRakesh kumar jha
468 visualizações3 slides
Directed Acyclic Graph por
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
6.5K visualizações100 slides
Graps 2 por
Graps 2Graps 2
Graps 2Saurabh Mishra
334 visualizações42 slides

Mais conteúdo relacionado

Mais procurados

2.5 graph dfs por
2.5 graph dfs2.5 graph dfs
2.5 graph dfsKrish_ver2
2.4K visualizações16 slides
Presentation on Breadth First Search (BFS) por
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
17.9K visualizações49 slides
Skiena algorithm 2007 lecture11 breadth deapth first search por
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchzukun
635 visualizações23 slides
Topological sort por
Topological sortTopological sort
Topological sortjabishah
84 visualizações21 slides
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS por
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
542 visualizações9 slides
Dijkstra's algorithm por
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
11.7K visualizações15 slides

Mais procurados(20)

2.5 graph dfs por Krish_ver2
2.5 graph dfs2.5 graph dfs
2.5 graph dfs
Krish_ver22.4K visualizações
Presentation on Breadth First Search (BFS) por Shuvongkor Barman
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman17.9K visualizações
Skiena algorithm 2007 lecture11 breadth deapth first search por zukun
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
zukun635 visualizações
Topological sort por jabishah
Topological sortTopological sort
Topological sort
jabishah84 visualizações
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS por AAKASH KUMAR
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR542 visualizações
Dijkstra's algorithm por gsp1294
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
gsp129411.7K visualizações
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS por AAKASH KUMAR
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR333 visualizações
Algorithms of graph por getacew
Algorithms of graphAlgorithms of graph
Algorithms of graph
getacew1.4K visualizações
Algorithmic Notations por Muhammad Muzammal
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
Muhammad Muzammal23.3K visualizações
Graph Traversal Algorithms - Depth First Search Traversal por Amrinder Arora
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora6.4K visualizações
Self Stabilizing Depth-first Search por Intan Dzikria
Self Stabilizing Depth-first SearchSelf Stabilizing Depth-first Search
Self Stabilizing Depth-first Search
Intan Dzikria1.8K visualizações
Breadth First Search (BFS) por Dhrumil Panchal
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal444 visualizações
Biconnected components (13024116056) por Akshay soni
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
Akshay soni3K visualizações
Matlab integration por pramodkumar1804
Matlab integrationMatlab integration
Matlab integration
pramodkumar1804474 visualizações
A star por minhaz uddin
A starA star
A star
minhaz uddin203 visualizações
Data structure por sumit singh
Data structureData structure
Data structure
sumit singh412 visualizações
Game Paper por Siddharth Gupta
Game PaperGame Paper
Game Paper
Siddharth Gupta415 visualizações
BFS por jyothimonc
BFSBFS
BFS
jyothimonc11.5K visualizações
Graph Algorithms: Breadth-First Search (BFS) por Md. Shafiuzzaman Hira
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
Md. Shafiuzzaman Hira483 visualizações

Similar a Analysis of Pathfinding Algorithms

Unit ii-ppt por
Unit ii-pptUnit ii-ppt
Unit ii-pptAravindharamanan S
852 visualizações24 slides
Lecture 16 - Dijkstra's Algorithm.pdf por
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdfiftakhar8
26 visualizações32 slides
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx por
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.docxwhittemorelucilla
5 visualizações18 slides
A star algorithms por
A star algorithmsA star algorithms
A star algorithmssandeep54552
779 visualizações14 slides
Graphs por
GraphsGraphs
GraphsKomalPaliwal3
66 visualizações44 slides
Lecture13 por
Lecture13Lecture13
Lecture13vaishali_singh
368 visualizações13 slides

Similar a Analysis of Pathfinding Algorithms(20)

Lecture 16 - Dijkstra's Algorithm.pdf por iftakhar8
Lecture 16 - Dijkstra's Algorithm.pdfLecture 16 - Dijkstra's Algorithm.pdf
Lecture 16 - Dijkstra's Algorithm.pdf
iftakhar826 visualizações
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx por whittemorelucilla
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
whittemorelucilla5 visualizações
A star algorithms por sandeep54552
A star algorithmsA star algorithms
A star algorithms
sandeep54552779 visualizações
Graphs por KomalPaliwal3
GraphsGraphs
Graphs
KomalPaliwal366 visualizações
Lecture13 por vaishali_singh
Lecture13Lecture13
Lecture13
vaishali_singh368 visualizações
IntroductionTopological sorting is a common operation performed .docx por mariuse18nolet
IntroductionTopological sorting is a common operation performed .docxIntroductionTopological sorting is a common operation performed .docx
IntroductionTopological sorting is a common operation performed .docx
mariuse18nolet3 visualizações
Link Prediction in the Real World por Balaji Ganesan
Link Prediction in the Real WorldLink Prediction in the Real World
Link Prediction in the Real World
Balaji Ganesan272 visualizações
Unit 3 Informed Search Strategies.pptx por DrYogeshDeshmukh1
Unit  3 Informed Search Strategies.pptxUnit  3 Informed Search Strategies.pptx
Unit 3 Informed Search Strategies.pptx
DrYogeshDeshmukh111 visualizações
Prim's Algorithm on minimum spanning tree por oneous
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
oneous49.3K visualizações
Graph por Shakil Ahmed
GraphGraph
Graph
Shakil Ahmed1.8K visualizações
hospital management por guestbcbbb5c
hospital managementhospital management
hospital management
guestbcbbb5c2.6K visualizações
Heuristic Searching: A* Search por IOSR Journals
Heuristic Searching: A* SearchHeuristic Searching: A* Search
Heuristic Searching: A* Search
IOSR Journals608 visualizações
algorithm Unit 3 por Monika Choudhery
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
Monika Choudhery5.9K visualizações
Graph Representation por Ramkrishna bhagat
Graph RepresentationGraph Representation
Graph Representation
Ramkrishna bhagat210 visualizações
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr... por Khoa Mac Tu
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
Khoa Mac Tu371 visualizações

Último

nintendo_64.pptx por
nintendo_64.pptxnintendo_64.pptx
nintendo_64.pptxpaiga02016
6 visualizações7 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... por
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
8 visualizações46 slides
Introduction to Gradle por
Introduction to GradleIntroduction to Gradle
Introduction to GradleJohn Valentino
5 visualizações7 slides
Page Object Model por
Page Object ModelPage Object Model
Page Object Modelartembondar5
6 visualizações5 slides
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... por
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...TomHalpin9
6 visualizações29 slides
Introduction to Maven por
Introduction to MavenIntroduction to Maven
Introduction to MavenJohn Valentino
6 visualizações10 slides

Último(20)

nintendo_64.pptx por paiga02016
nintendo_64.pptxnintendo_64.pptx
nintendo_64.pptx
paiga020166 visualizações
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... por sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik8 visualizações
Introduction to Gradle por John Valentino
Introduction to GradleIntroduction to Gradle
Introduction to Gradle
John Valentino5 visualizações
Page Object Model por artembondar5
Page Object ModelPage Object Model
Page Object Model
artembondar56 visualizações
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... por TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 visualizações
Introduction to Maven por John Valentino
Introduction to MavenIntroduction to Maven
Introduction to Maven
John Valentino6 visualizações
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... por Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke35 visualizações
Playwright Retries por artembondar5
Playwright RetriesPlaywright Retries
Playwright Retries
artembondar55 visualizações
Airline Booking Software por SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta9 visualizações
MS PowerPoint.pptx por Litty Sylus
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptx
Litty Sylus7 visualizações
AI and Ml presentation .pptx por FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8714 visualizações
JioEngage_Presentation.pptx por admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254558 visualizações
FOSSLight Community Day 2023-11-30 por Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan6 visualizações
What is API por artembondar5
What is APIWhat is API
What is API
artembondar512 visualizações
The Era of Large Language Models.pptx por AbdulVahedShaik
The Era of Large Language Models.pptxThe Era of Large Language Models.pptx
The Era of Large Language Models.pptx
AbdulVahedShaik7 visualizações
How Workforce Management Software Empowers SMEs | TraQSuite por TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite6 visualizações
Dapr Unleashed: Accelerating Microservice Development por Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski13 visualizações
predicting-m3-devopsconMunich-2023.pptx por Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app8 visualizações
Benefits in Software Development por John Valentino
Benefits in Software DevelopmentBenefits in Software Development
Benefits in Software Development
John Valentino5 visualizações

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