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

DFS

Chen
November 09, 2022

 DFS

ECE 590

Chen

November 09, 2022
Tweet

More Decks by Chen

Other Decks in Science

Transcript

  1. DFS to find any string accepted
    60
    Stack
    0
    Put start state + info into stack
    Visited is an empty set
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “”

    View full-size slide

  2. DFS to find any string accepted
    61
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  3. DFS to find any string accepted
    62
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  4. DFS to find any string accepted
    63
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “” 0
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  5. DFS to find any string accepted
    64
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “” 0
    3 “c”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  6. DFS to find any string accepted
    65
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “” 0
    3 “c”
    2 “b”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  7. DFS to find any string accepted
    66
    Stack
    0
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “” 0
    3 “c”
    2 “b”
    1 “a”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  8. DFS to find any string accepted
    67
    Stack
    1
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “a” 0
    3 “c”
    2 “b”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  9. DFS to find any string accepted
    68
    Stack
    1
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “a” 0
    1
    3 “c”
    2 “b”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  10. DFS to find any string accepted
    69
    Stack
    1
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “a” 0
    1
    1 “ab”
    3 “c”
    2 “b”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  11. DFS to find any string accepted
    70
    Stack
    1
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “a” 0
    1
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  12. DFS to find any string accepted
    71
    Stack
    1
    Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    “a” 0
    1
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    2 “aa”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  13. DFS to find any string accepted
    72
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2 “aa”
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  14. DFS to find any string accepted
    73
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2 “aa”
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  15. DFS to find any string accepted
    74
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2 “aa”
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  16. DFS to find any string accepted
    75
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2 “aa”
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    4 “aab”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  17. DFS to find any string accepted
    76
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2 “aa”
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    4 “aab”
    1 “aaa”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  18. DFS to find any string accepted
    77
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    4 “aab”
    1 “aaa”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  19. DFS to find any string accepted
    78
    Stack Visited
    Curr
    We add extra info to our stack.
    For this problem, a string
    0
    1
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    4 “aab”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo

    View full-size slide

  20. DFS to find any string accepted
    79
    Stack Visited
    Curr
    0
    1
    2
    1 “ab”
    3 “c”
    2 “b”
    1 “ac”
    3 “aac”
    4 “aab”
    Repeat until goal is met
    curr, info = pop from stack
    if curr is not in visited
    add curr to visited
    for each v adjacent to curr
    push v, newinfo
    For this problem, goal = accepting state,
    The info is the string to get us there.

    View full-size slide