1 / 10

ITM 352 Algorithms

ITM 352 Algorithms. We'll go into greater depth on this later. Today we will just see and play with some simple examples. A Brief Tour of Programming Logic and Algorithms. What is Programming?. Direct (specify) computer's actions in detail

klingbeil
Télécharger la présentation

ITM 352 Algorithms

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. ITM 352Algorithms

  2. We'll go into greater depth on this later. Today we will just see and play with some simple examples A Brief Tour of Programming Logic and Algorithms

  3. What is Programming? • Direct (specify) computer's actions in detail • Uses a language that humans can deal with and translates it into something the computer can process. • Builds a software representation of something (a model) that people value in some way (e.g. solves a problem).

  4. Qualities of Algorithms • An algorithm expects a defined set of inputs. • An algorithm produces a defined set of outputs. • An algorithm is guaranteed to terminate and produce a result. • Most algorithms are guaranteed to produce the correct result. • Algorithms may impose requirements on inputs (called preconditions). For example, a precondition might be that an algorithm will only accept positive numbers as an input. Programs are just a series of algorithms!

  5. Example Algorithm in Pseudo-Code get_dressed( int temperature ) { if( temperature > 75 ) /* it's hot out */ put_on( tshirt ); put_on( shorts ); put_on( sandals ); else if( temperature > 60 ) /* it's warm out */ putOn( blue_shirt ); putOn( blue_jeans ); putOn( white_socks ); putOn( sneakers ); else /* it's kind of cold */ putOn( sweatshirt ); putOn( blue_jeans ); putOn( wool_socks ); putOn( shoes ); putOn( jacket ); }

  6. Example (Bad) Algorithm • Preheat oven to 350 degrees. • Grease and flour a 9x9 inch pan. • In a medium bowl, cream together 1 cup sugar and ½ cup butter. • Beat in 2 eggs, one at a time, then stir in 2 tsp vanilla. • Bake until done.

  7. Example (Bad) Algorithm • Add shampoo to hair. • Lather. • Rinse. • Repeat.

  8. Example: Making Change • Everyone knows how to make change • When given an amount of change, we will all do exactly the same thing • Q: if you owe someone 73 cents and have a drawer full of pennies, nickels, dimes, and quarters, how many of each will you give?

  9. Example: Making Change - 2 • A: 2 quarters, 2 dimes, 3 pennies • Did anyone get a different answer? • Why not? • Because we are all using the same algorithm!

  10. Example: Making Change - 3 • Create the making change algorithm. • You know how to do it! The problem is writing it down clearly and unambiguously. • Assume you are giving this to someone who has never made change before (but who can do arithmetic). • So you must be very clear and explicit and assume nothing.

More Related