Answers.Body: <p>One of the more standard assumptions when first introducing new students to search algorithms (like Depth-First Search, Breadth-First Search which you've also likely heard about or will hear about soon, etc.) is indeed that our goal is to find some sort of solution, and only find one.</p>
  
  <p>If our intention is to find just a single solution, then yes, you will need to check at every node whether that is a solution node, and you can stop the search process once you've found one.</p>
  
  <p>In practice, there can be all kinds of variants of this idea. Maybe in a different case you are interested in finding <em>all</em> solutions, rather than a single one; in such a case you would naturally not stop the search process after finding the first one, but continue searching.</p>
  
  <p>So, to conclude, it really depends on exactly what you want, why are you using a search algorithm. If you only care about finding <em>a</em> solution, you can stop when you have one.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-07T13:12:21.293Z
Answers.LastActivityDate: 2018-09-07T13:12:21.293Z
Answers.UserDisplayName: Dennis Soemers
Body: <p>I'm a fresh learner of AI. I was told that depth-first search is not an optimal searching algorithm since "it finds the 'leftmost' solution, regardless of depth or cost". Therefore, does it mean that in practice, when we implement DFS, we should always have a checker to stop the search when it finds the first solution (also the leftmost one)?</p>
  
Tags: <search><implementation><depth-first-search>
Title: Does depth-first search always stop when it has found the leftmost solution?
UserDisplayName: Hang Chen
ThreadText: # Does depth-first search always stop when it has found the leftmost solution?
  
  (Asked by: username_0 on 2018-09-07)
  
  I'm a fresh learner of AI. I was told that depth-first search is not an optimal searching algorithm since "it finds the 'leftmost' solution, regardless of depth or cost". Therefore, does it mean that in practice, when we implement DFS, we should always have a checker to stop the search when it finds the first solution (also the leftmost one)?
  
  **Tags:** search, implementation, depth-first-search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-07. Score: 2 | Accepted answer
  
  One of the more standard assumptions when first introducing new students to search algorithms (like Depth-First Search, Breadth-First Search which you've also likely heard about or will hear about soon, etc.) is indeed that our goal is to find some sort of solution, and only find one.
  
  If our intention is to find just a single solution, then yes, you will need to check at every node whether that is a solution node, and you can stop the search process once you've found one.
  
  In practice, there can be all kinds of variants of this idea. Maybe in a different case you are interested in finding *all* solutions, rather than a single one; in such a case you would naturally not stop the search process after finding the first one, but continue searching.
  
  So, to conclude, it really depends on exactly what you want, why are you using a search algorithm. If you only care about finding *a* solution, you can stop when you have one.
  
  
  ---
  
  