Lecture 17 - State Machines, Combinatorics, Game Strategies Flashcards
What does a finite state machine have? (4)
- a set of states
- a set of transitions between the states
- an initial state
- zero or more final (“accepting”) states
What are side effects of a state machine?
The actions taken on entering/leaving states
Can a state machine be between states?
No. State transitions are considered “atomic”
- What are the externally visible parts of a state machine? (3)
- What’s not externally visible?
1.
- – the events the state machine understands
- – the guard conditions the machine checks
- – the actions that the machine performss
- Everything else, including the machine’s current state
What’s a finite state transducer?
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
What are the types of FSTs? (2)
- Mealy machines
- Moore machines
What’s a mealy machine?
(output symbol is associated with transition)
What’s a Moore machine?
(output symbol is associated with state)
Compare Moore and Mealy machines (3)
- 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
What’s an example of a time when state machines are beneficial?
- 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.
What are the two common approaches for implementing state machines?
- switch statement
- transition table
Why does the factorial function keep appearing in things we’ve been doing this semester?
It’s the number of permutations of N items
How many permutations are there of k elements from a set of n elements total
n! / (n-k)!

Define combination
A combination is a subset of k elements from a set of n elements
What is n choose k?
a subset of k elements from a set of n elements
call the size of the set of all such subsets “n choose k”
What is this?

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

What’s the equation for n choose k?

What is the power set?
the set of all subsets of a set, including both the set itself and the empty set
What’s the size of the power set?
2|s| sets
What’s the time complexity for generating power sets?
O(2n)
What’s the strategy in take N marble game game strategy?…
- For 4
- In general
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
Based on the starting circumstances of the take N marbles game, which player can always win?
- 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