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 step by step solution to a problem l Why bother writing an algorithm ? oFor your own use in the future - Don't have to rethink the problem. oSo others can solve the problem, even if they know very little about the principles behind how the solution was derived.

4 CMSC 1044 Examples of Algorithms l Washing machine instructions l Instructions for a ready-to-assemble piece of furniture l A Classic: GCD - Greatest Common Divisor - The Euclidean Algorithm

5 CMSC 1045 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.

6 CMSC 1046 Observations about the Washing Machine Instructions l There are a finite number of steps. l We are capable of doing each of the instructions. l When we have followed all of the steps, the washing machine will wash the clothes and then will stop. l Are all of the clothes clean ? l Do we want the washing machine to run until all of the clothes are clean ?

7 CMSC 1047 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.

8 CMSC 1048 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.

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

10 CMSC 10410 History of Algorithms l The study of algorithms began as a subject in mathematics. 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.

11 CMSC 10411 GCD - The Euclidean Algorithm  Assign M and N the value of the larger and the value of the smaller of the two positive integer input values, respectively.  Divide M by N and call the remainder R.  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.

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

13 CMSC 10413 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 ?

14 CMSC 10414 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"

15 CMSC 10415 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