Answers.Body: <p>I think this is a problem with missing brackets in pseudocode &mdash; clearly the state is only added to the frontier if it hasn't been explored already, so it would be:</p>
  
  <pre><code>if not [contains(frontier, state) OR contains(explored, state)] then
  </code></pre>
  
  <p>which is equivalent to your interpretation of</p>
  
  <pre><code>if not [contains(frontier, state)] AND not [contains(explored, state)] then
  </code></pre>
  
  <p>(according to <a href="https://en.wikipedia.org/wiki/De_Morgan&#39;s_laws" rel="nofollow noreferrer">De Morgan's Laws</a>)</p>
  
  <p>Being half-way between a programming language and natural language, this is a case where pseudocode is not quite precise enough.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-07T15:15:39.290Z
Answers.LastActivityDate: 2020-02-07T15:15:39.290Z
Answers.UserDisplayName: Oliver Mason
Body: <p>On page 84 of Russell &amp; Norvig's book "Artificial Intelligence: A Modern Approach Book" (3rd edition), the pseudocode for uniform cost search is given. I provided a screenshot of it here for your convenience.</p>
  
  <p>I am having trouble understanding the highlighted line <code>if child.STATE is not in explored **or** frontier then</code></p>
  
  <p><a href="https://i.sstatic.net/PHchM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PHchM.png" alt="enter image description here"></a></p>
  
  <p>Shouldn't that be 
  <code>if child.STATE is not in explored **and** frontier then</code></p>
  
  <p>The way it's written, it seems to suggest that if the child node has already been explored, but not currently in the frontier, then we add it to the frontier, but I don't think that's correct. If it's already been explored, then it means we already found the optimal path for this node previously and should not be processing it again. Is my understanding wrong?</p>
  
Tags: <search><norvig-russell><uniform-cost-search><pseudocode>
Title: Understanding the pseudocode of uniform-cost search from the book "Artificial Intelligence: A Modern Approach"
UserDisplayName: anonuser01
ThreadText: # Understanding the pseudocode of uniform-cost search from the book "Artificial Intelligence: A Modern Approach"
  
  (Asked by: username_0 on 2020-02-07)
  
  On page 84 of Russell & Norvig's book "Artificial Intelligence: A Modern Approach Book" (3rd edition), the pseudocode for uniform cost search is given. I provided a screenshot of it here for your convenience.
  
  I am having trouble understanding the highlighted line `if child.STATE is not in explored **or** frontier then`
  
  [![enter image description here](https://i.sstatic.net/PHchM.png)](https://i.sstatic.net/PHchM.png)
  
  Shouldn't that be
  `if child.STATE is not in explored **and** frontier then`
  
  The way it's written, it seems to suggest that if the child node has already been explored, but not currently in the frontier, then we add it to the frontier, but I don't think that's correct. If it's already been explored, then it means we already found the optimal path for this node previously and should not be processing it again. Is my understanding wrong?
  
  **Tags:** search, norvig-russell, uniform-cost-search, pseudocode
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-07. Score: 2 | Accepted answer
  
  I think this is a problem with missing brackets in pseudocode — clearly the state is only added to the frontier if it hasn't been explored already, so it would be:
  if not [contains(frontier, state) OR contains(explored, state)] then
  
  which is equivalent to your interpretation of
  if not [contains(frontier, state)] AND not [contains(explored, state)] then
  
  (according to De Morgan's Laws)
  Being half-way between a programming language and natural language, this is a case where pseudocode is not quite precise enough.
  
  
  ---
  
  