Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.

Similar presentations


Presentation on theme: "What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each."— Presentation transcript:

1 What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each step can be carried out without creativity

2 What is an Algorithm? Formal definition: An algorithm is a well ordered collection of unambiguous and effectively computable operations that produces a result and halts in a finite amount of time.

3 An Algorithm is Well Ordered Each step of the algorithm is executed in the order in which it is written, or else the order is clearly stated. What is wrong with this algorithm to average two numbers? Step 1: Divide the sum by 2 Step 2: Add the two numbers

4 An Algorithm is Unambiguous The operation can be carried out without further explanation or simplification.

5 An Algorithm is Effectively Computable It must be possible for the computing agent to perform the operation and produce a result. The operation must be doable. Can’t ask to print out list of all prime numbers.

6 An Algorithm Must Halt in a Finite Amount of Time Even if it would take centuries to finish executing the algorithm, there is some point in time when the result would be produced. What is wrong with this algorithm? Step 1. Set X to –1 Step 2. Subtract 1 from X Step 3. If X is not 0, go back to Step 2.

7 More about Algorithms The order in which the steps of an algorithm are executed is one of the following: sequential conditional iterative

8 Sequential Order Each step is performed in the order in which it is written. Example: Algorithm for finding a sale price. Step 1. Multiply the regular price by the discount percent. Step 2. Subtract the result of Step 1 from the regular price.

9 Conditional Order Determines whether or not a condition is true; and, based on whether or not it is true, selects the next step to do. Example-- Algorithm for processing a bank check: Step 1. Determine if the amount of the check is greater than the checking account balance. Step 2. If Step 1 is true, print “Overdraft” Step 3. Otherwise, subtract the amount of the check from the balance.

10 Iterative Operation Repeat a set of steps over and over -- also called a “looping” operation. Example: Algorithm for counting the digits in a positive integer N. Step 1. Set the Count to 0 Step 2. Divide N by 10 (dropping any remainder) Step 3. Add 1 to the Count Step 4. If N is greater than 0, repeat steps 2-4

11 Attributes of Algorithms Correct Efficient –Time how long to solve problem –Space how much memory needed Easy to Understand –Program maintenance Elegant

12 Comparing Algorithms Possible to come up with several algorithms to solve same problem Which is “best” –Most time efficient –Most space efficient –Easiest to maintain

13 Measuring Efficiency 2 algorithms may be functionally correct 1 may be more efficient How is efficiency measured –Determine least computing time –Determine least amount of work (fundamental steps)


Download ppt "What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each."

Similar presentations


Ads by Google