Problems Solving with Programming - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Problems Solving with Programming

Description:

... everyday life : -cooking recipes ; calculation of formulas ; ... appetizers : grapefruit cocktail ; salmon sandwiches. Problems Solving with Programming ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 20
Provided by: wwwitiCsU
Category:

less

Transcript and Presenter's Notes

Title: Problems Solving with Programming


1
Problems Solving with Programming
  • What is programming ?
  • Algorithms Properties
  • Algorithms Specification
  • Algorithms Design
  • Algorithms Construction
  • Algorithms Description

2
Problems Solving with Programming
  • Programming means solving problems with the help
    of a computer
  • PROBLEM ? COMPUTER ?

  • SOLUTION

3
Problems Solving with Programming
  • Designing an algorithm
  • Writing the problem
  • Feeding the program and data into the computer

4
Problems Solving with Programming
  • Algorithms are instructions for the solving of
    problems
  • Examples from everyday life -cooking recipes
    calculation of formulas rules of a game.
  • An instruction is called an algorithm, when the
    following applies

5
Problems Solving with Programming
  • Condition 1 The description is of finite
    length.
  • Condition 2 The process will come to an end
    after the execution of a finite number of
    operations. (Counterexample Repeat the steps 1
    to 3 until you have won 1 Million (1) Fill in a
    lottery coupon (2) hand it in at a lottery
    agency (3) wait for the next draw and collect
    your winnings).

6
Problems Solving with Programming
  • Condition 3 The sequence in which the
    operations have to be applied must be determined
    unambiguously.
  • Prepare the soup according to the
    instructions on the can. At the end add some
    asparagus pieces. Cut the ham in strips (It is
    not quite clear when the operation Put in some
    pieces of esparagus has to be executed.

7
Problems Solving with Programming
  • Condition 4 The effect of each operation has
    been defined unambiguously.
  • Otherwise there could be unwelcome results.
  • Important properties of an algorithm - Finite
    description , - Efficiency , - Definite effect
    , - Termination.

8
Problems with Solving Programming
  • The inner structure of an algorithm can be
    described by listing the steps that have to be
    done
  • ALGORITHM Inner structure Do this then
    do that
  • A so-called outer behaviour of an algorithm
    takes only the effect of algorithm into account.
    It is also called the specification of an
    algorithm.

9
Problems Solving with Programming
  • Algorithm
  • Input Data (Outer behaviour)
  • Do this data do that (Inner structure) BLACK
    BOX
  • Output Data (Outer behaviour)
  • The outer behaviour of an algorithm has to be
    described before the inner structure.
  • The relation between input and output data is
    important for the specification. There are two
    conditions for the specification precondition V
    and postcondition N.

10
Problems Solving with Programming
  • Consider the following example of a specification
  • (LIST is a list of 100 numbers) Outer
    behaviour
  • SORT
  • (for all I between 1 and 99 LISTI lt
    LISTI1) Outer behaviour .
  • SORT The specification indicates that the
    algorithm SORT no matter what is looks like
    will sort a list of 100 numbers into ascending
    order.

11
Problems Solving with Programming
  • General form of specification V A N
    with
  • V precondition
  • A desired algorithm
  • N postcondition

12
Problems Solving with Programming
  • Algorithms Design Of all the steps of
    programming, the first is the most difficult.
  • Designing an algorithm
  • Writing the program
  • Feeding the program and data into the computer.

13
Problems Solving with Programming
  • How do you find an algorithm for a given problem
    ?
  • Phase 1 A problem is reduced to simple
    subproblems.
  • Phase 2 Searching for algorithms for the
    simple problems and putting them together to form
    the whole algorithm.
  • Example for the reduction of problems You Have
    invited guests for dinner and are planning a
    menu.
  • The first question What is the menu to consist
    of ?
  • Menu appetizers --- main course ---
    dessert.
  • appetizers grapefruit cocktail salmon
    sandwiches.

14
Problems Solving with Programming
  • Algorithms design
  • Counterpart for the Top-Down-Strategy is called
    Bottom-Up-Strategy.
  • The Bottom-Up-Strategy deals with putting smaller
    problems together

15
Problems Solving with Programming
  • Algorithms are usually made up of three
    constructs of smaller partial algorithms
  • Composition sequential execution
  • Selection alternative execution
  • Iteration repeated execution .
  • By nesting these constructs even complicated
    algorithms can be represented.

16
Problems Solving with Programming
  • Composition A1 and A2 are two algorithms.
    With composition, A1 is started first. When A1
    is finished, A2 is them started.
  • It is important that A1 terminates (finishes)
    after a finite amount of time, otherwise A2
    cannot ever be started.
  • Selection (alternative execution)
  • Selection A1, A2 and A3 are algorithms. A1 is
    executed first, depending on the result either A2
    or A3 is started.

17
Problems Solving with Programming
  • Iteration repeated execution.
  • A1 and A2 are algorithms. A1, A2 are repeated
    until A1 becomes FALSE.

18
Problems Solving with Programming
  • Algorithm description An algorithm can be
    presented
  • In colloquial form
  • As a graphical representation
  • Using programming languages .
  • Colloquial language is not quite suitable for the
    presentation of algorithms, because of the
    following problems
  • Ambiguities
  • Incompleteness
  • inaccuracy

19
Problems Solving with Programming
  • 2. Graphical presentation by means of
  • Flows charts are nets of individual symbols
    with definite meanings
  • Structograms consists of nestings of
    individual symbols with definite meanings.
  • 3. If algorithms are to be executed by computers
    they have to be represented in a certain
    programming language.
Write a Comment
User Comments (0)
About PowerShow.com