SlideShare a Scribd company logo
1 of 9
Download to read offline
Dr. Maamoun Ahmed
© 2018
Example
Irbid
Rmth
Jers
Zrqa
amm
Krk
Maan
AQA
MFR
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
We need to go
From Ramtha (Rmth)
To Aqaba (AQA)
using the shortest path
How to?
 1st: we measure the real, straight-line distance from nodes
(cities) to destination.
(Theoretically, it can be done using the Euclidean distance
which finds the straight-line distance between two points)
Now, technology can help by using more accurate distance
using GPS.
These distances are called Heuristics (i.e. estimated values
of the straight line distance)
Example – Cont.
Irbid
Rmth
Jers
Zrqa
amm
Krk
Maan
AQA
MFR
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14 (Straight line distance)
11
15
11
5
8
9
4
When we compare distances,
We take combined heuristics
Instead of weight. Example:
Distance when we arrive Zrqa
Will be 3 (weight) + 11 (straight-
Line distance) = 14
This can be represented by the
Equation: f(n)=g(n)+h(n)
Let’s say: g is the graph weight,
And h is the heuristics distance
Example – Cont.
Irbi
d
Rmt
h
Jers
Zrq
a
am
m
Krk
Maan
AQ
A
MF
R
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14
11
15
11
5
8
9
4
Starting from Rmth, we assign
The following to it: Rmth | 0 |14
Where the 0 means the path cost
To Rmth, and the 14 is the distnace
To AQA.
Now we start to expand the path
Now Irbid: Irbid | 5 |16 where 5 is
The g distance and 16 is the 5+11
Add Irbid to the queue
Then Zrqa Zrqa | 3 |14 , we add it
To the queue. By comparing the 16
And 14, Zrqa is less (14), it goes to
The top of the queue.
Now MFR MFR| 2 |17 , we add it
To the queue. By comparing 16
14, and 17, the queue will have Zrqa
Then Irbid, then MFR
Example – Cont.
Irbi
d
Rmt
h
Jers
Zrq
a
am
m
Krk
Maan
AQ
A
MF
R
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14
11
15
11
5
8
9
4
Our queue
Zrqa | 3 |14
Irbid | 5 |16
MFR | 2 |17
We can add a flag that
represents where the path is
coming from
Zrqa | 3 |14 | Rmth
Irbid | 5 |16 |Rmth
MFR | 2 |17 |Rmth
Now we choose Zrqa, BUT!
From Zrqa we see Irbid and MFR,
so we should now pay attention
to graph cost (just like Dikstra’s):
From Rmth to Irbid via Zrqa =
3+6 >5, so we don’t update
From Rmth to MFR via Zrqa is
3+3=6>2, so we don’t update
Example – Cont.
Irbi
d
Rmt
h
Jers
Zrq
a
am
m
Krk
Maan
AQ
A
MF
R
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14
11
15
11
5
8
9
4
Now from
Zrqa | 3 |14 |Rmth
We can go to amm, with a
Graph cost of 3+4 (7), and
Heuristic of 9.
7+9=16
So we add to the queue:
Amm|7|16|Zrqa
Just like before, from amm
we can go to Irbid which we
visited before, considering
the graph cost to decide to
update or not.
Rmth > Zrqa >Amma >
Irbid = 3+4+3 = 10 which is
> 5, so again we don’t
update amm.
Example – Cont.
Irbi
d
Rmt
h
Jers
Zrq
a
am
m
Krk
Maan
AQ
A
MF
R
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14
11
15
11
5
8
9
4
Since Zrqa has visited
all, we remove it from
the queue. The queue
now:
Irbid | 5 | 16 | Rmth
amm| 7 | 16 | Zrqa
MFR | 2 |17 |Rmth
Since Irbid is in the top of
the queue, we choose it.
From Irbid we can go to
Zrqa but path is 6+3 (9),
greater than 3 (no update).
And to amm (5+3) greater
than 7, so no update.
No to Jers with 5+2 (7) Plus
8
So Jers: Jers| 7 | 15 | Irbid
This puts Jers on top of the queue, so we choose it.
Example – Cont.
Irbi
d
Rmt
h
Jers
Zrq
a
am
m
Krk
Maan
AQ
A
MF
R
5 2
3
2
6
9
4
10
3
2
4
4
3
2
3
7
14
11
15
11
5
8
9
4
From Jers| 7 | 15 |
Irbid we can go to
amm but 5+2+2 is
greater than 3+4 (no
update)
And Krk.
To Krk:
Krk | 9 (5+2+2) | 13 (9+4)
Krk | 9 | 13 | Jers
Again, we see if we can update path to
amm since Krk has a path to it, but this
path costs 5+2+2+4 which is greater than
3+4 (no update)
Now Krk has a combined heuristic of 13, which
puts it on the top of the queue.
From Krk we can go to AQA (destination)
AQA g(n) = 9+3 = 12
AQA h(n) = 0
AQA | 12 | 12| Krk IS THE SHORTEST PATH

More Related Content

More from Dr. Maamoun Ahmed

Minimum spanning trees – prim's and kruskal's algorithms
Minimum spanning trees – prim's and kruskal's algorithmsMinimum spanning trees – prim's and kruskal's algorithms
Minimum spanning trees – prim's and kruskal's algorithmsDr. Maamoun Ahmed
 
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approach
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approachFinding Minimum Spanning Tree using Prim's Algorithm - Matrix approach
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approachDr. Maamoun Ahmed
 
Solving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsSolving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsDr. Maamoun Ahmed
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Dr. Maamoun Ahmed
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Dr. Maamoun Ahmed
 
Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Dr. Maamoun Ahmed
 
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
Theory of Computation  - Strings and Languages and Proofs (Lecture 2)Theory of Computation  - Strings and Languages and Proofs (Lecture 2)
Theory of Computation - Strings and Languages and Proofs (Lecture 2)Dr. Maamoun Ahmed
 

More from Dr. Maamoun Ahmed (7)

Minimum spanning trees – prim's and kruskal's algorithms
Minimum spanning trees – prim's and kruskal's algorithmsMinimum spanning trees – prim's and kruskal's algorithms
Minimum spanning trees – prim's and kruskal's algorithms
 
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approach
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approachFinding Minimum Spanning Tree using Prim's Algorithm - Matrix approach
Finding Minimum Spanning Tree using Prim's Algorithm - Matrix approach
 
Solving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relationsSolving linear homogeneous recurrence relations
Solving linear homogeneous recurrence relations
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5
 
Theory of Computation - Lecture 3
Theory of Computation - Lecture 3Theory of Computation - Lecture 3
Theory of Computation - Lecture 3
 
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
Theory of Computation  - Strings and Languages and Proofs (Lecture 2)Theory of Computation  - Strings and Languages and Proofs (Lecture 2)
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
 

Recently uploaded

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

A* - Astar - A-Star

  • 2. Example Irbid Rmth Jers Zrqa amm Krk Maan AQA MFR 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 We need to go From Ramtha (Rmth) To Aqaba (AQA) using the shortest path
  • 3. How to?  1st: we measure the real, straight-line distance from nodes (cities) to destination. (Theoretically, it can be done using the Euclidean distance which finds the straight-line distance between two points) Now, technology can help by using more accurate distance using GPS. These distances are called Heuristics (i.e. estimated values of the straight line distance)
  • 4. Example – Cont. Irbid Rmth Jers Zrqa amm Krk Maan AQA MFR 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 (Straight line distance) 11 15 11 5 8 9 4 When we compare distances, We take combined heuristics Instead of weight. Example: Distance when we arrive Zrqa Will be 3 (weight) + 11 (straight- Line distance) = 14 This can be represented by the Equation: f(n)=g(n)+h(n) Let’s say: g is the graph weight, And h is the heuristics distance
  • 5. Example – Cont. Irbi d Rmt h Jers Zrq a am m Krk Maan AQ A MF R 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 11 15 11 5 8 9 4 Starting from Rmth, we assign The following to it: Rmth | 0 |14 Where the 0 means the path cost To Rmth, and the 14 is the distnace To AQA. Now we start to expand the path Now Irbid: Irbid | 5 |16 where 5 is The g distance and 16 is the 5+11 Add Irbid to the queue Then Zrqa Zrqa | 3 |14 , we add it To the queue. By comparing the 16 And 14, Zrqa is less (14), it goes to The top of the queue. Now MFR MFR| 2 |17 , we add it To the queue. By comparing 16 14, and 17, the queue will have Zrqa Then Irbid, then MFR
  • 6. Example – Cont. Irbi d Rmt h Jers Zrq a am m Krk Maan AQ A MF R 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 11 15 11 5 8 9 4 Our queue Zrqa | 3 |14 Irbid | 5 |16 MFR | 2 |17 We can add a flag that represents where the path is coming from Zrqa | 3 |14 | Rmth Irbid | 5 |16 |Rmth MFR | 2 |17 |Rmth Now we choose Zrqa, BUT! From Zrqa we see Irbid and MFR, so we should now pay attention to graph cost (just like Dikstra’s): From Rmth to Irbid via Zrqa = 3+6 >5, so we don’t update From Rmth to MFR via Zrqa is 3+3=6>2, so we don’t update
  • 7. Example – Cont. Irbi d Rmt h Jers Zrq a am m Krk Maan AQ A MF R 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 11 15 11 5 8 9 4 Now from Zrqa | 3 |14 |Rmth We can go to amm, with a Graph cost of 3+4 (7), and Heuristic of 9. 7+9=16 So we add to the queue: Amm|7|16|Zrqa Just like before, from amm we can go to Irbid which we visited before, considering the graph cost to decide to update or not. Rmth > Zrqa >Amma > Irbid = 3+4+3 = 10 which is > 5, so again we don’t update amm.
  • 8. Example – Cont. Irbi d Rmt h Jers Zrq a am m Krk Maan AQ A MF R 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 11 15 11 5 8 9 4 Since Zrqa has visited all, we remove it from the queue. The queue now: Irbid | 5 | 16 | Rmth amm| 7 | 16 | Zrqa MFR | 2 |17 |Rmth Since Irbid is in the top of the queue, we choose it. From Irbid we can go to Zrqa but path is 6+3 (9), greater than 3 (no update). And to amm (5+3) greater than 7, so no update. No to Jers with 5+2 (7) Plus 8 So Jers: Jers| 7 | 15 | Irbid This puts Jers on top of the queue, so we choose it.
  • 9. Example – Cont. Irbi d Rmt h Jers Zrq a am m Krk Maan AQ A MF R 5 2 3 2 6 9 4 10 3 2 4 4 3 2 3 7 14 11 15 11 5 8 9 4 From Jers| 7 | 15 | Irbid we can go to amm but 5+2+2 is greater than 3+4 (no update) And Krk. To Krk: Krk | 9 (5+2+2) | 13 (9+4) Krk | 9 | 13 | Jers Again, we see if we can update path to amm since Krk has a path to it, but this path costs 5+2+2+4 which is greater than 3+4 (no update) Now Krk has a combined heuristic of 13, which puts it on the top of the queue. From Krk we can go to AQA (destination) AQA g(n) = 9+3 = 12 AQA h(n) = 0 AQA | 12 | 12| Krk IS THE SHORTEST PATH