Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms & FlowchartsLecture 10. Algorithm’s CONCEPT.

Similar presentations


Presentation on theme: "Algorithms & FlowchartsLecture 10. Algorithm’s CONCEPT."— Presentation transcript:

1 Algorithms & FlowchartsLecture 10

2 Algorithm’s CONCEPT

3 Solving Problems When faced with a problem: 1.We first clearly define the problem 2.Think of possible solutions 3.Select the one that we think is the best under the prevailing circumstances 4.And then apply that solution 5.If the solution works as desired, fine; else we go back to step 2

4 al.go.rithm Sequence of steps that can be taken to solve a given problem

5 Algorithm (Better Definition) 1 st Definition: Sequence of steps that can be taken to solve a problem Better Definition: A precise sequence of a limited number of unambiguous, executable steps that terminates in the form of a solution

6 Examples Addition Conversion from decimal to binary The process of boiling an egg The process of mailing a letter Sorting Searching

7 Informal definition of an algorithm used in a computer

8 Finding the largest integer among five integers

9 Defining actions in FindLargest algorithm

10 FindLargest refined

11 Generalization of FindLargest

12 THREE BUILDING BLOCKS

13 Sequences A sequence of instructions that are executed in the precise order they are written in: statement block 1 statement block 2 statement block 3 statement block 1 statement block 2 statement block 3

14 Decisions Select between alternate courses of action depending upon the evaluation of a condition If ( condition = true ) statement block 1 Else statement block 2 End if statement block 1 condition TrueFalse statement block 2

15 Repetitions/Loops Loop through a set of statements as long as a condition is true Loop while ( condition = true ) statement block End Loop condition True False statement block

16 Three building blocks

17 Algorithm TYPES

18 Greedy Algorithm An algorithm that always takes the best immediate, or local solution while finding an answer Greedy algorithms may find the overall or globally optimal solution for some optimization problems, but may find less-than-optimal solutions for some instances of other problems KEY ADVANTAGE: Greedy algorithms are usually faster, since they don't consider the details of possible alternatives

19 Deterministic Algorithm An algorithm whose behavior can be completely predicted from the inputs That is, each time a certain set of input is presented, the algorithm gives the same results as any other time the set of input is presented

20 Randomized Algorithm Any algorithm whose behavior is not only determined by the input, but also values produced by a random number generator These algorithms are often simpler and more efficient than deterministic algorithms for the same problem Simpler algorithms have the advantages of being easier to analyze and implement

21 Syntax & Semantics An algo. is “correct” if its: –Semantics are correct –Syntax is correct Semantics: The concept embedded in an algorithm (the soul!) Syntax: The actual representation of an algorithm (the body!) WARNINGS: 1. An algo. can be syntactically correct, yet semantically incorrect – very dangerous situation! 2. Syntactic correctness is easier to check as compared with semantic


Download ppt "Algorithms & FlowchartsLecture 10. Algorithm’s CONCEPT."

Similar presentations


Ads by Google