Lecture 17 - State Machines, Combinatorics, Game Strategies Flashcards

1
Q

What does a finite state machine have? (4)

A
  • a set of states
  • a set of transitions between the states
  • an initial state
  • zero or more final (“accepting”) states
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are side effects of a state machine?

A

The actions taken on entering/leaving states

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can a state machine be between states?

A

No. State transitions are considered “atomic”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What are the externally visible parts of a state machine? (3)
  2. What’s not externally visible?
A

1.

  • – the events the state machine understands
  • – the guard conditions the machine checks
  • – the actions that the machine performss
  1. Everything else, including the machine’s current state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s a finite state transducer?

A

If the action on entering/leaving a state is to output a symbol, we call the FSM a finite state transducer. – it converts (transduces) the sequence of input symbols into a sequence of output symbols

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the types of FSTs? (2)

A
  • Mealy machines
  • Moore machines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s a mealy machine?

A

(output symbol is associated with transition)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s a Moore machine?

A

(output symbol is associated with state)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Compare Moore and Mealy machines (3)

A
  • Moore machines in general have many more states than the equivalent Mealy machine –
    • because output depends only on current state, not state+input
    • so we need to add states whenever the Mealy machine has different outputs for different transitions out of a state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s an example of a time when state machines are beneficial?

A
  • Retrieving content based on a user’s mouse click. During retrieval, they click something again.
  • The logic might get complicated in an ordinary flow chart, but a state machine wouldn’t accept this 2nd click because it’s in the fetching state, so the 2nd click wouldn’t cause problems.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the two common approaches for implementing state machines?

A
  • switch statement
  • transition table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why does the factorial function keep appearing in things we’ve been doing this semester?

A

It’s the number of permutations of N items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How many permutations are there of k elements from a set of n elements total

A

n! / (n-k)!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define combination

A

A combination is a subset of k elements from a set of n elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is n choose k?

A

a subset of k elements from a set of n elements

call the size of the set of all such subsets “n choose k”

17
Q

What is this?

A

n choose k

18
Q

How does the set of k-permutations compare to choose(n,k)?

A
19
Q

What’s the equation for n choose k?

A
20
Q

What is the power set?

A

the set of all subsets of a set, including both the set itself and the empty set

21
Q

What’s the size of the power set?

A

2|s| sets

22
Q

What’s the time complexity for generating power sets?

A

O(2n)

23
Q

What’s the strategy in take N marble game game strategy?…

  • For 4
  • In general
A

Take just enough to leave a multiple of 4

  • If players can take 1…N marbles, then whoever can leave a multiple of N+1 marbles for their opponent can force a win
    • whichever number K in 1…N your opponent chooses as their move, you choose L = (N+1)-K as your next move
24
Q

Based on the starting circumstances of the take N marbles game, which player can always win?

A
  • If the game starts with a multiple of N+1 marbles, player B can always win
  • If the game starts with something other than a multiple of N+1, player A can always win