meljun cortes algorithm funda of algorithm

Upload: meljun-cortes-mbampa

Post on 07-Aug-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    1/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 1 of 29

    Definition of algorithm

    Importance of studying algorithm

    Notion of algorithm

    Algorithm design and analysis process

    Types of computing problems

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    2/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 2 of 29

    a step-by-step problem-solving procedure,

    especially an established, recursive computational

    procedure for solving a problem in a finite number

    of steps

    used in many activities and come in many forms

    Examples: instructions for assembling kits,

    recipes, steps for processing credit card

    approvals, directions to a destination

    a well-defined procedure to solve a problem

    a fundamental area of computer science

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    3/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 3 of 29

    the study of algorithm and is more than a branch

    of computer science

    the core of computer, and, in all fairness, can besaid to be relevant to most business and

    technology [Har92], p.6.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    4/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 4 of 29

    Computer programs would not exist without

    algorithms.

    It is essential in different aspects such as

    professional and personal lives.

    It is useful in developing analytical skills.

    Algorithms can be seen as special kinds of

    solution to problems-not answered.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    5/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 5 of 29

    Instructions: implies that there is something  

    capable of understanding and following the given

    instructions.

    Algorithm tells the computer what specific steps to

    perform (in what specific order) in order to carry

    out a specified task, such as calculating  

    employee’s paychecks or printing   student’s report

    cards.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    6/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 6 of 29

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    7/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 7 of 29

    Problem: must be defined cautiously by describing 

    the set of instances it must work on

    Algorithm: solving the same problem can be

    represented with several algorithms

    Input: data is read from an input source or device

    Output: data is written to an output device

    Computer: process the implemented algorithm

    thru a computer program

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    8/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 8 of 29

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    9/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 9 of 29

    In a real world, we dealt with algorithm by giving

    instructions going to a particular place or following

    a recipe cook book.

    The example below is an algorithm for giving

    instructions in making a small sponge cake:

    Method

    EggSponge

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    10/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 10 of 29

    Some similarities of the recipe to algorithms used

    for programming:

    1. Steps 1 to 6 shows a sequence: a series of stepsperformed one after the other.

    2. Step 2 shows a reference to a commonly used

    task that is specified in detail elsewhere: Follow

    method for Egg Sponge from step a to step d.

    3. Step c shows repetition: "Beat egg white until stiff"

    - something is repeated until some condition ismet.

    4. Step 6 shows selection: "Ice with glace or melted

    butter icing" - one of two possible actions is taken.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    11/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 11 of 29

    An algorithm is represented using two common

    techniques:

    1. Flowchart

    2. Pseudocode

    Flowchart: a diagrammatic representation that

    illustrates the sequence of operations to be

    performed to get the solution of a problem.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    12/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 12 of 29

    Pseudocode a type of structured English that is

    used to specify an algorithm.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    13/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 13 of 29

    Algorithms are procedural solutions to different

    types of problem.

    Algorithm design and analysis process:

    emphasizes an exact, well-defined constructive

    procedures that makes computer science distinct

    from other disciplines.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    14/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 14 of 29

    The diagram shows the sequence of steps that

    typically goes through in designing and analyzing

    an algorithm.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    15/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 15 of 29

    Understanding the Problem

    Understand the problem completely before

    designing an algorithm.

    Read the problems description carefully and

    ask questions if you have any doubts about

    the problem, do a few small examples byhand, think about special cases, and ask

    questions again if needed.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    16/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 16 of 29

    Decide on Ascertaining the Capabilities of a

    Computational Device

    Once you completely understand a problem,

    you need to establish the capabilities of the

    computational device the algorithm is

    intended for.

    Sequential algorithms all instructions are

    executed one after another, one operation at

    a time

    Parallel algorithms all instructions are

    executed concurrently

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    17/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 17 of 29

    Decide on Choosing between Exact and

    Approximate Problem Solving

    Exact algorithm: algorithms used to find exact

    solutions

    Approximation algorithm: algorithms used tofind approximate solutions

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    18/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 18 of 29

    Decide on Deciding on Appropriate Data

    Structures

    As with all problems in computer science,

    there is more than one solution to which data

    structure should be used.

    Algorithms Data Structures = Programs

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    19/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 19 of 29

    Algorithm Design Techniques

    general approach to solving problems

    algorithmically that is applicable to a variety of

    problems from different areas of computing 

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    20/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 20 of 29

    Methods of Specifying an Algorithm

    Pseudocode

    Flowchart

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    21/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 21 of 29

    Proving an lgorithm’s Correctness

    Proving the correctness of an algorithm is

    similar to proving a mathematical theorem.

    Once an algorithm has been specified, you

    have to prove its correctness.

    That is, you have to prove that the algorithm

    yields a required result for every legitimate

    input in a finite amount of time.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    22/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 22 of 29

    Analyzing an Algorithm

    Qualities to be considered in analyzing an

    algorithm:

    • Correctness

    • Efficiency

    –Time efficiency: indicates how fastthe algorithms run

    –Space efficiency: indicates how much

    extra memory the algorithm needs.

    • Simplicity

    • Generality

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    23/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 23 of 29

    Coding an Algorithm

    Algorithms are created to be implemented as

    computer programs

    A running program provides an additional

    opportunity in allowing practical analysis of

    the underlying algorithm.

    Time efficiency: indicates how fast the

    algorithms run

    Space efficiency: indicates how much extra

    memory the algorithm needs.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    24/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 24 of 29

    The following are the different types of problems

    encountered in designing and analyzing

    algorithms:

    Sorting 

    Searching 

    String processing 

    Graph problems

    Combinatorial problems

    Geometrical problems

    Numerical problems

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    25/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 25 of 29

    The following are the different types of problems

    encountered in designing and analyzing

    algorithms:

    Sorting: requires to rearrange the items

    of a given list in ascending or descending

    order.

    Searching: deals with finding a given

    value called the key in a given list or set.

    String processing: deals with non-

    numerical that intensifies the interest ofresearchers and computing practitioners

    in string-handling algorithms.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    26/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 26 of 29

    Continuation:

    Graph problems: deal with objects and

    their connections like determining

    whether all of the locations are

    connected, visiting all of the locations

    that can be reached from a given

    location, or finding the shortest path fromone location to another.

    Combinatorial problems: most difficult

    problems in computing that ask

    (explicitly or implicitly) to find acombination of an object such as

    permutation, combination or a subset

    that satisfies certain constraints and has

    some desired property.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    27/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 27 of 29

    Continuation:

    Geometrical problems: deal with

    geometric objects such as points, lines

    and polygons that can be applied to

    computer graphics and robotics.

    Numerical problems: involve

    mathematical objects of continuous

    nature such as solving equations, system

    equations, computing definite integrals,

    evaluating functions etc

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    28/29

    Fundamentals of Algorithm

    Design and Analysis of Algorithm

    * Property of STI 

    Page 28 of 29

    Algorithm representation: Draw a flowchart and a

    pseudocode based on the given problems below.

    1. According to Plato, a man should marry a woman

    whose age is half his age plus seven years. Draw

    a flowchart and write pseudocode that will ask a

    man’s age as input and outputs the ideal age of 

    his wife.

    2. Given integer variables num1 and num2 and a

    character variable ch, input the values for num1,

    num2, and ch (the value of ch can be  ‘a’, ‘s’, ‘m’

    or ‘d’). Compute the output based on the ff:

    if ch = ’a’ perform addition;

    if ch = ‘s’ perform subtraction;if ch = ‘m’ perform multiplication; and

    if ch = ‘d’ perform division.

    3. Enter 10 integer values from 1 to 200. Find how

    many of these values fall in the range 1-50, 51-100, 101-150 and 151-200.

  • 8/21/2019 Meljun Cortes Algorithm Funda of Algorithm

    29/29

    Design and Analysis of Algorithm

    Research for the following topics:

    Definition of data structure

    Different types of data structure

    Types of Linear data structure

    Types of Graph data structure

    Types of Trees data structure

    Note: The research work should be in a printed

    copy compiled in a folder with a title page.