200 likes | 280 Views
CS 498 (242). Lecture 3. Last Lecture. Made too many assumptions Was too broad Did not cover timing in enough detail to be useful Did not cover important parts of optimization in enough detail. Important Points. Optimization priorities: Improve the algorithm if you can
E N D
CS 498 (242) Lecture 3
Last Lecture • Made too many assumptions • Was too broad • Did not cover timing in enough detail to be useful • Did not cover important parts of optimization in enough detail
Important Points • Optimization priorities: • Improve the algorithm if you can • Concentrate your effort on the code that is executed most (it was obvious in last assignment) • Eliminate unnecessary instructions (things that don’t change from one iteration to next) • Order conditionals so those most likely to fail come first
FSM • Example - Vending machine • Accepts nickels only • $0.15 dispense product
Pseudo-code While machine on inputTotal = 0 While (inputTotal < PRODUCT_PRICE) inputTotal += AcceptCoin(coin) DispenseProduct
AcceptCoin(coin) • Is it a nickel? • Yes – return(5) • RejectCoin(coin) • Return(0)
AcceptCoin(coin) • Is it a nickel? • Yes – return(5) • Is it a dime? • Yes – return(10) • Is it a quarter? • Yes – return(25) • RejectCoin(coin) • Return(0)
Outline Introduction I have a couple of points to make Topic 1 key point 1 first detail of my first point second detail of my first point second key point Conclusion
Tree Data Structure • Root node (outline) • Children: • Introduction • Topic(s) • Conclusion
Tree Data Structure • Topic(s) • Key point(s) • Detail(s)
Tree Data Structure • Key point(s) • Detail(s)
Example <outline> <outlinename>My Outline</outlinename> <introduction>I have a couple of points to make</introduction> <topic> <topicname>Topic 1</topicname> <keypoint> <keypointtitle>key point 1(/keypointtitle> <detail>first detail of my first point</detail> <detail>second detail of my first point</detail> </keypoint> <keypoint><keypointtitle>second key point</keypointtitle> </keypoint> </topic> </outline>
What signals you to start a state? • A tag • Example - <topic>
What signals you to exit a state? • Matching end tag • Example - </topic>
<topic> • Get next tag • Is it: • Topicname • Keypoint • </topic> We don’t worry if it’s a “<conclusion>” or anything else. Those are not valid inputs to transition states.