Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BFS

Chen
November 09, 2022

 BFS

ECE 590

Chen

November 09, 2022
Tweet

More Decks by Chen

Other Decks in Science

Transcript

  1. BFS to find any string accepted 42 Queue 0 Start

    by putting start state+ info into queue Visited is empty set Visited Curr We add extra info to our queue. For this problem, a string “”
  2. BFS to find any string accepted 43 Queue 0 Visited

    Curr How we get newinfo from v + info is problem specific Here, we concatenate info with the symbol on the edge “” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  3. BFS to find any string accepted 44 Queue 0 Visited

    Curr “” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  4. BFS to find any string accepted 45 Queue 0 Visited

    Curr 1 2 3 0 “” “a” “b” “c” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  5. BFS to find any string accepted 46 Queue Visited Curr

    1 2 3 0 “b” “c” “a” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  6. BFS to find any string accepted 47 Queue Visited Curr

    1 2 3 0 1 2 1 1 “a” “b” “c” “aa” “ab” “ac” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  7. BFS to find any string accepted 48 Queue Visited Curr

    2 3 0 1 2 1 1 “b” “c” “aa” “ab” “ac” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  8. BFS to find any string accepted 49 Queue Visited Curr

    2 3 0 1 2 1 1 2 1 4 3 “b” “c” “aa” “ab” “ac” “bb” “ba” “bc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  9. BFS to find any string accepted 50 Queue Visited Curr

    3 0 1 2 1 1 2 1 4 3 “c” “aa” “ab” “ac” “bb” “ba” “bc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  10. BFS to find any string accepted 51 Queue Visited Curr

    3 0 1 2 1 1 2 1 4 3 0 2 3 3 “c” “aa” “ab” “ac” “bb” “ba” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  11. BFS to find any string accepted 52 Queue Visited Curr

    0 1 2 1 1 2 1 4 3 0 2 3 3 “aa” “ab” “ac” “bb” “ba” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  12. BFS to find any string accepted 53 Queue Visited Curr

    0 1 1 1 2 1 4 3 0 2 3 3 “ab” “ac” “bb” “ba” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  13. BFS to find any string accepted 54 Queue Visited Curr

    0 1 1 2 1 4 3 0 2 3 3 “ac” “bb” “ba” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  14. BFS to find any string accepted 55 Queue Visited Curr

    0 1 1 2 4 3 0 2 3 3 “bb” “ba” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  15. BFS to find any string accepted 56 Queue Visited Curr

    0 1 2 4 3 0 2 3 3 For this problem, goal = accepting state, The info is the string to get us there. “bb” “bc” “ca” “cb” “cc” Repeat until goal is met curr, info = dequeue from queue if curr is not in visited add curr to visited for each v where curr->v enqueue v, newinfo
  16. 57 Queue Visited Curr 0 1 2 4 3 0

    2 3 3 BFS will get us the shortest string to get To the accepting state. More generally, it gives a result with the fewest Edges along the path “bb” “bc” “ca” “cb” “cc” BFS to find any string accepted