Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMSC 1041 Algorithms I An Introduction to Algorithms.

Similar presentations


Presentation on theme: "CMSC 1041 Algorithms I An Introduction to Algorithms."— Presentation transcript:

1 CMSC 1041 Algorithms I An Introduction to Algorithms

2 CMSC 1042 Problem Solving “Problem solving is the process of transforming the description of a problem into the solution of that problem by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem- solving strategies, techniques, and tools.”

3 CMSC 1043 Algorithms l An algorithm is a procedure with: oA specific finite sequence of definite actions, and oA definite criterion for ending.

4 CMSC 1044 Algorithms Specificity l Steps must be unambiguous oNot “Do the regular thing at this point.” l Steps should be robust --- “Unlikely to fail” oWhat happens when MARKUP = PRICE/COST and COST = 0.0?

5 CMSC 1045 Algorithms Stopping Rule l Algorithms must have a clear stopping rule. l The rule does not have to specify a definite number of steps --- but it must give an unambiguous criterion oGood: “Stop when F(x i )-F(x i-1 ) < EPS ” oBad: “Continue until done.”

6 CMSC 1046 Algorithms l Why bother writing an algorithm ? oTo recognize and understand the essence of a problem or a solution. oFor your own use in the future. (Why solve the same problem twice?) oSo others can solve the problem, even if they know very little about the principles behind how the solution was derived.

7 CMSC 1047 Algorithms Algorithms are Stored Thought.

8 CMSC 1048 Examples of Algorithms l Starting a car. l Washing machine instructions l Instructions for a ready-to-assemble piece of furniture l A Classic: GCD - Greatest Common Divisor - The Euclidean Algorithm

9 CMSC 1049 Starting a Car l Check to see if the car is an automatic l If it is an automatic oInsert key into ignition oDepress brake pedal oTurn key oDone! l If it is a manual oInsert key into ignition oDepress brake pedal oDepress clutch pedal oTurn key oDone! This isn’t a good algorithm. It stops when the key is turned, not when the car is started. What happens if the key doesn’t fit, the brake or clutch pedal can’t be depressed, or the key can’t be turned? Can you see how this algorithm can be simplified?

10 CMSC 10410 Washing Machine Instructions l Separate clothes into white clothes and colored clothes. l For white clothes: oSet water temperature knob to HOT. oPlace white laundry in tub. l For colored clothes: oSet water temperature knob to COLD oPlace colored laundry in tub. l Add 1 cup of powdered laundry detergent to the tub. l Close lid and press the start button.

11 CMSC 10411 Observations about the Washing Machine Instructions l There are a finite number of steps. l The steps are all clearly defined l When the steps are complete, the washing machine will be ready to start. l What is the relationship between this algorithm and clean clothes? l Do we want the washing machine to run until all of the clothes are clean ?

12 CMSC 10412 Refinement of the Definition l Our old definition: oAn algorithm is a step by step solution to a problem. l Adding our observations: oAn algorithm is a finite set of executable instructions that directs a terminating activity.

13 CMSC 10413 Instructions for a Ready-to-Assemble Piece of Furniture l "Align the marks on side A with the grooves on Part F “ l Why are these instructions typically so hard to follow ? oLack of proper tools - instructions are not executable oWhich side is A ? A & B look alike. Both line up with Part F - Ambiguous instructions.

14 CMSC 10414 Final Version of the Definition: An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity.

15 CMSC 10415 History of Algorithms l The study of algorithms began as a subject in mathematics. Abu Ja’far Mohammed ibn Musa al Khowarizmi Persian (c. 825 AD) l The search for algorithms was a significant activity of early mathematicians. l Goal: To find a single set of instructions that could be used to solve any problem of a particular type.

16 CMSC 10416 GCD - The Euclidean Algorithm l 1. Assign M and N the value of the larger and the value of the smaller of the two positive integer input values, respectively. l 2. Divide M by N and call the remainder R. l 3. If R is not 0, then assign M the value of N, assign N the value of R and return to step 2, otherwise the greatest common divisor is the value currently assigned to N.

17 CMSC 10417 Finding the GCD or 24 and 9 MNR 2496 9 63 630 So 3 is the GCD of 24 and 9.

18 CMSC 10418 Euclidean GCD Algorithm (continued) l Do we need to know the theory that Euclid used to come up with this algorithm in order to use it ? l What intelligence is required to find the GCD using this algorithm ?

19 CMSC 10419 The Idea Behind Algorithms l Once an algorithm behind a task has been discovered oDon't need to understand the principles. oTask is reduced to following the instructions. oIntelligence is "encoded into the algorithm” “An algorithm is stored thought.”

20 CMSC 10420 Algorithm Representation l Syntax and Semantics oSyntax refers to the representation itself. oSemantics refers to the concept represented.


Download ppt "CMSC 1041 Algorithms I An Introduction to Algorithms."

Similar presentations


Ads by Google