1 / 30

Algorithm 1: The Morning Routine Get out of bed Shower Bathe kids Prepare cereal . . .

B Smith: Required 45 to 50 minutes. Stirred up few questions. Needs to be more interactive and less general/abastract. Score 3 with improv, 2.5 if used as is. B Smith: Not used Fall05. Not needed; not helpful. Math 130 Intro to Computer Programming Algorithms Lecture # 01 01/21/05. B Smith:

Download Presentation

Algorithm 1: The Morning Routine Get out of bed Shower Bathe kids Prepare cereal . . .

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. B Smith: Required 45 to 50 minutes. Stirred up few questions. Needs to be more interactive and less general/abastract. Score 3 with improv, 2.5 if used as is. B Smith: Not used Fall05. Not needed; not helpful Math 130 Intro to Computer ProgrammingAlgorithmsLecture # 0101/21/05 B Smith: Great for independent study; not so great otherwise. Algorithm 1: The Morning Routine Get out of bed Shower Bathe kids Prepare cereal . . .

  2. Overview • Solving problems • mysterious or methodical • luck or by design • Algorithms • recipes • Values and variables • quantity and place holders

  3. How do we solve problems? • Largely empirical • “Doing heart surgery in this manner works” • History • “This is how Alice did it…” • Inspiration • “I don’t know how, but I solved it!” • Brute force • Trial-and-error • The scientific method

  4. Analysis Problemspecification Design Algorithm Implementation Program Compilation Executable (solution) B Smith: Use math as a useful application. How about finding the roots of 2x^2+3x-4 = 0? What would be the algorithm. The Problem-solving Process "Doctor, my head hurts" Patient has elevated pressure in anterior parietal lobe 1. Sterilize cranial saw 2. Anaesthetize patient 3. Remove top of skull 4. Get the big spoon... 5. etc., etc. sterilize(saw,alcohol); raise_hammer(); lower_hammer(fast); start(saw); /* etc. etc. */ 0100111010110010101010101001010101010100110010101010101001011010011101010101010010010111010011110101010111110101010001101…

  5. The Problem-solving Process Analysis Problem specification Design Algorithm Implementation Program Compilation Executable (solution)

  6. Algorithm • A sequence of instructions specifying the steps required to accomplish some task • Named after: • Muhammad ibn Mūsāal-Khwārizmi • Circa 780-850 C.E. (Common Era) http://jeff560.tripod.com/khowar.jpg

  7. Algorithm –History Muhammad ibn Musa al-Khwarizmi http://www-gap.dcs.st-andrews.ac.uk/~history/Mathematicians/Al-Khwarizmi.html • Book on arithmetic: • Hindu numeration, decimal numbers, use of zero, method for finding square root • Latin translation (c.1120 CE): “Algoritmi de numero Indorum” • Book on algebra • “Kitāb al-jabr wa’l-muqābala” • (“Rules of restoring and equating”)

  8. Algorithm – Working Definition • A sequence of instructions describing how to do a task As opposed to actually executing the instructions!

  9. The Problem-solving Process "Doctor, my head hurts" Patient has elevated pressure in anterior parietal lobe. Analysis Problem specification 1. Sterilize cranial saw 2. Anaesthetize patient 3. Remove top of skull 4. Get the big spoon... 5. etc., etc. Design Algorithm Implementation sterilize(saw,alcohol); raise_hammer(); lower_hammer(fast); start(saw); /* etc. etc. */ Program Compilation 010011101011001010101010100101010101010011001010101010100101101001110101010101001001011101001111010101011111010101000110100001101... Executable (solution)

  10. Algorithm -- Examples • A cooking recipe • Assembly instructions for a model car, boat, etc. • The rules of how to play a game • VCR instructions • Description of a martial arts technique • Directions for driving from A to B • A knitting pattern • A car repair manual

  11. Algorithm – Examples (cont) • Recipe for Almond and honey slice • Recipe for Arroz con pollo

  12. 1/2 quantity Shortcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelized evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  13. 1/2 quantity Shortcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelized evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice Instructions are given in the order in which they are performed (“executed”) From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  14. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken; to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole and bake in a moderate oven (350°F) for 20 minutes or until the rice is tender. Add beans and artichokes during last 10 minutes of cooking. Correct Algorithm? From: “Arroz Con Pollo” in The Margaret Fulton Cookbook, Hamlyn, Sydney, 1968.

  15. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken and to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole andbake in a moderate oven (350°F) for 20 minutes or until the rice is tender. Add beans and artichokes during last 10 minutes of cooking. Correct Algorithm? From: “Arroz Con Pollo” in The Margaret Fulton Cookbook, Hamlyn, Sydney, 1968.

  16. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken and to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole andbake in a moderate oven (350°F) for 10 minutes. Add beans and artichokes. Cover, and bake for another 10 minutes or until rice is tender. Correct Algorithm?

  17. Algorithm: A sequence of instructions describing how to do a task (or process) Problem C Program From Algorithms to Programs

  18. Components of an Algorithm • Variables and values • Instructions • Sequences • Procedures • Selections • Repetitions • Documentation

  19. Values • Representquantities, amounts, rates, etc. • May be numerical, alphabetical or even other items • A related unit may or may not be specified • Add 3 cups of flour • Pull rip-cord • Example: • Recipe ingredients (how big, how hot, how long)

  20. 1/2 quantity Shortcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelised evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  21. 1/2 quantity Shotcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelised evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  22. Variable Values 10 cookies 50 grams of sugar 3 slices of cake etc. This jar can contain Variables • Are containersfor values– placesto storevalues • Example:

  23. Restrictions on Variables • Variables may be restricted to contain a specific type of value

  24. Components of an Algorithm • Values and Variables • Instruction (a.k.a. primitive) • Sequence (of instructions) • Procedure (involving instructions) • Selection (between instructions) • Repetition (of instructions) • Documentation (beside instructions)

  25. Instructions(Primitives) • Some action that is simple... ...and unambiguous... ...that the system knows about... ...and should be able to actually do

  26. Instructions – Examples • Take offyourshoes • Countto10 • Cut alongdotted line • Knit1 • Purl 2 • Firmly Pullrip-cord • Sift 10 grams of sulfur Directions to perform specific actions on values and variables.

  27. Instructions -- Application • Some instructions can only be applied to specific types of values or variables • Examples: Chop

  28. Instructions(Primitives) -- Recommendations • When writing an algorithm, make each instruction simple and unambiguous • Example: Cut chicken into pieces. Heat olive oil in a casserole dish. Brown the chicken pieces in the casserole dish. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil.

  29. Instruction (Primitives) • When writing an algorithm, make the instructions simple and unambiguous. • Example: A “sequence” of simple instructions Cut chicken into pieces. Heat olive oil in a casserole dish. Brown the chicken pieces in the casserole dish. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil.

  30. Summary • Problem Solving Process • Algorithms • Components of Algorithms • Values and Variables • Instructions • to be continued... Reading Bronson, Ch 1 and Ch 2

More Related