SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Más de 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
 

Último

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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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