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

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

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 FresherRemote DBA Services
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[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.pdfhans926745
 
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.pptxHampshireHUG
 
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 productivityPrincipled Technologies
 
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 WorkerThousandEyes
 
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 educationjfdjdjcjdnsjd
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

KĂŒrzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[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
 
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
 
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
 
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
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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