Lesson 12 Flashcards
Finite State Machine
is a graphical approach to describe the behavior of an automated system.
The states of an FSM are represented as circles.
The action of the system when in a state is described in each circle
Translation between states are represented using arrow
Initial state should
To program a FSM in Python
- Initialize an integer variable to keep track of the current state
- Record input values ( sensor, key presses, etc.)
- Evaluate transition logic
- Update the state
- Apply the state actions
- Repeat from step 2
Sort
Problem: Arranging elements in collection
Common sorting algorithms
Insertion sort
Efficient for small or nearly sorted datasets
Bubble sort
simple to implement but slow for large datatsets
Selection sort
Minimal swaps but slow for large datasets
Merge Sort
Fast for large datasets but requires more memory
Quick sort
Fast on average but poor worst case performance
Insertion sort:
Pull elements from a list and insert them in order into a new list
Common search algorithms
Linear search: checks elements one by one. Works on unsorted lists
Binary search: fast on sorted lists
Jump search: faster than linear on sorted lists, but slower than binary
Interpolation search: faster than binary for uniformly distributed and sorted data
Binary search
Compare the middle of a sorted list with the target. If the target is greater than the middle element, it must appear to the right of the middle. Otherwise it must appear to the left of the middle. Repeat