title: Visiting a supermarket with a shopping list, get all items in the fastest way?
body: <p>Once in a while, my wife sends me to a REAL supermarket, with a shopping list (she writes me an a piece of paper, or texts me a message).</p>
  
  <p><strong>I was wondering is there a fast way to for-fill the list, without iterating the whole super a dozens of times, till I believe I've got everything.</strong></p>
  
  <p>(I found this question very helpful in life: <a href="https://stackoverflow.com/questions/14415881/pair-socks-from-a-pile-efficiently">pair-socks-from-a-pile-efficiently</a>, and hoped I can use the community's help in my own situation) </p>
  
  <blockquote>
    <p>I don't know/remember where each item is located in the supermarket, and the list I'm given is never sorted (for example, vegetables are listed all over the list, and not one after the other). Also, usually I get continuously text messages with more and more items to buy, while I'm still in the super.</p>
  </blockquote>
  
  <p>My approach is planning a path that would assure me I iterate the whole supermarket, and pick items from the list while walking that path.</p>
  
  <h2>Two ways I was thinking about:</h2>
  
  <ol>
  <li>foreach item in the super <code>(n)</code> I pass: check if I have such item in my list <strong>(m)</strong>, will give me an <code>O(n*m)</code> complicity, which not so efficient.</li>
  <li>"dividing" the shop to rows <code>(p)</code>: standing on the beginning of each row I can read the sign or see which sort of items I should find there, than iterate my list, trying to remember all items in list I should find in that row. than walk that row and add those items to my cart, should give me <code>O(p*m)</code> complicity. 
  <strong>but this never really happens</strong>: I can't remember more than three of four items from my list I'm expecting to find in that row, and even if I do, I often forget an item and have to use this algorithm again <strong>(lets say <code>q</code> times)</strong>, which comes to: <code>O(q*p*m)</code>.</li>
  </ol>
  
  <p>A couple of comments I'd like to add:</p>
  
  <ol>
  <li><em>when getting to the vegetable section for example, I found myself going over that section many times, cause my wife is a great cook and adds all kinds of vegetables in the list <code>(v)</code>. Sure I can't remember all those veggies, and rather not stop next to each vegetable in the market (or should I?), to check if I've got it in my list.</em></li>
  <li><em>Crossing out each item I put in my cart (or making a new list with all items I still don't have) is very time consuming for me, so I rather just go over the whole list each time I try to find if I still have an item to add to my cart.</em></li>
  <li><em>Another case is the second you get in your car before going on a family vacation. You remember you forgot to take this that and though, running back to your house, getting some of these items, forgetting others and going back again. Is this a similar case?</em></li>
  </ol>