SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Depth-First Search (DFS) ,[object Object],[object Object],[object Object],[object Object]
DFS Algorithm ,[object Object],[object Object],[object Object],u v w1 w2 w3
DFS Algorithm Flag all vertices as not visited Flag yourself as visited For unvisited neighbors, call RDFS(w) recursively We can also record the paths using pred[ ].
Example Adjacency List source Visited Table (T/F) Initialize visited table (all False) Initialize Pred to -1 Pred 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F - - - - - - - - - -
Example Adjacency List source Visited Table (T/F) Mark 2 as visited Pred RDFS( 2 ) Now visit RDFS(8) 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F - - - - - - - - - -
Example Adjacency List source Visited Table (T/F) Mark 8 as visited mark Pred[8] Pred RDFS( 2 ) RDFS(8) 2 is already visited, so visit RDFS(0) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F T F - - - - - - - - 2 -
Example Adjacency List source Visited Table (T/F) Mark 0 as visited Mark Pred[0] Pred RDFS( 2 ) RDFS(8) RDFS(0) -> no unvisited neighbors, return to call RDFS(8) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T F 8 - - - - - - - 2 -
Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) Now visit 9 -> RDFS(9) Recursive calls Back to 8 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T F 8 - - - - - - - 2 -
Example Adjacency List source Visited Table (T/F) Mark 9 as visited Mark Pred[9] Pred RDFS( 2 ) RDFS(8) RDFS(9)   -> visit 1, RDFS(1) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T T 8 - - - - - - - 2 8
Example Adjacency List source Visited Table (T/F) Mark 1 as visited Mark Pred[1] Pred RDFS( 2 ) RDFS(8) RDFS(9)   RDFS(1) visit RDFS(3) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F F F F F T T 8 9 - - - - - - 2 8
Example Adjacency List source Visited Table (T/F) Mark 3 as visited Mark Pred[3] Pred RDFS( 2 ) RDFS(8) RDFS(9)   RDFS(1) RDFS(3) visit RDFS(4) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T F F F F T T 8 9 - 1 - - - - 2 8
Example RDFS( 2 ) RDFS(8) RDFS(9)   RDFS(1) RDFS(3) RDFS(4)    STOP all of 4’s neighbors have been visited return back to call RDFS(3) Adjacency List source Visited Table (T/F) Mark 4 as visited Mark Pred[4] Pred Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F F T T 8 9 - 1 3 - - - 2 8
Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) RDFS(9)   RDFS(1) RDFS(3) visit 5 -> RDFS(5)  Recursive calls Back to 3 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F F T T 8 9 - 1 3 - - - 2 8
Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) RDFS(9)   RDFS(1) RDFS(3) RDFS(5) 3 is already visited, so visit 6 -> RDFS(6) Recursive calls Mark 5 as visited Mark Pred[5] 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F F T T 8 9 - 1 3 3 - - 2 8

Weitere ähnliche Inhalte

Mehr von Saurabh Mishra (8)

Sorting2
Sorting2Sorting2
Sorting2
 
Sorting
SortingSorting
Sorting
 
Presentation1
Presentation1Presentation1
Presentation1
 
Graps 2
Graps 2Graps 2
Graps 2
 
Graphs
GraphsGraphs
Graphs
 
Data structures
Data structuresData structures
Data structures
 
Trees
TreesTrees
Trees
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Searching

  • 1.
  • 2.
  • 3. DFS Algorithm Flag all vertices as not visited Flag yourself as visited For unvisited neighbors, call RDFS(w) recursively We can also record the paths using pred[ ].
  • 4. Example Adjacency List source Visited Table (T/F) Initialize visited table (all False) Initialize Pred to -1 Pred 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F F F F F F F F F - - - - - - - - - -
  • 5. Example Adjacency List source Visited Table (T/F) Mark 2 as visited Pred RDFS( 2 ) Now visit RDFS(8) 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F F F - - - - - - - - - -
  • 6. Example Adjacency List source Visited Table (T/F) Mark 8 as visited mark Pred[8] Pred RDFS( 2 ) RDFS(8) 2 is already visited, so visit RDFS(0) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 F F T F F F F F T F - - - - - - - - 2 -
  • 7. Example Adjacency List source Visited Table (T/F) Mark 0 as visited Mark Pred[0] Pred RDFS( 2 ) RDFS(8) RDFS(0) -> no unvisited neighbors, return to call RDFS(8) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T F 8 - - - - - - - 2 -
  • 8. Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) Now visit 9 -> RDFS(9) Recursive calls Back to 8 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T F 8 - - - - - - - 2 -
  • 9. Example Adjacency List source Visited Table (T/F) Mark 9 as visited Mark Pred[9] Pred RDFS( 2 ) RDFS(8) RDFS(9) -> visit 1, RDFS(1) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T F T F F F F F T T 8 - - - - - - - 2 8
  • 10. Example Adjacency List source Visited Table (T/F) Mark 1 as visited Mark Pred[1] Pred RDFS( 2 ) RDFS(8) RDFS(9) RDFS(1) visit RDFS(3) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T F F F F F T T 8 9 - - - - - - 2 8
  • 11. Example Adjacency List source Visited Table (T/F) Mark 3 as visited Mark Pred[3] Pred RDFS( 2 ) RDFS(8) RDFS(9) RDFS(1) RDFS(3) visit RDFS(4) Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T F F F F T T 8 9 - 1 - - - - 2 8
  • 12. Example RDFS( 2 ) RDFS(8) RDFS(9) RDFS(1) RDFS(3) RDFS(4)  STOP all of 4’s neighbors have been visited return back to call RDFS(3) Adjacency List source Visited Table (T/F) Mark 4 as visited Mark Pred[4] Pred Recursive calls 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F F T T 8 9 - 1 3 - - - 2 8
  • 13. Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) RDFS(9) RDFS(1) RDFS(3) visit 5 -> RDFS(5) Recursive calls Back to 3 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T F F F T T 8 9 - 1 3 - - - 2 8
  • 14. Example Adjacency List source Visited Table (T/F) Pred RDFS( 2 ) RDFS(8) RDFS(9) RDFS(1) RDFS(3) RDFS(5) 3 is already visited, so visit 6 -> RDFS(6) Recursive calls Mark 5 as visited Mark Pred[5] 2 4 3 5 1 7 6 9 8 0 0 1 2 3 4 5 6 7 8 9 T T T T T T F F T T 8 9 - 1 3 3 - - 2 8