SlideShare una empresa de Scribd logo
1 de 32
Software Design and Development


Algorithms in SDD
Contents
             Course Specifications




 1. Algorithm description            5. Programming structure



 2. What is an algorithm?            6. Sequence



 3. Pseudocode                       7. Selection



 4. Flowcharts                       8. Repetition


NSW BOS Course Specifications        9. Subprograms
Methods of Algorithm Description
                       Contents


Introduction

There are many definitions of methods of algorithm description in existence,
some with many special symbols and keywords defined for special purposes.

This document presents two methods for describing algorithms:
            1. pseudocode
            2. flowcharts
Both methods must be used in the implementation of the Software Design and Development course. It
is expected that students are able to develop and interpret algorithms using both of these methods.



In assessing the quality of algorithm descriptions, general criteria such as:
            • the correctness of the algorithm
            • the clarity of the description
            • the use of appropriate control structures and
            • the embodiment of structured methods
     rather than the specific features of any method, should be taken into consideration.
Methods of Algorithm Description
                                                                                       continued
                      Contents




1. Clarity of description AND
2. Consistency
                 in the use of the components of the method chosen are of
                     far more importance than
                 • the actual shape of a flowchart element or
                 • the specific wording of a pseudocode statement.

The document presents standards that students should aim for in
publishing solutions to problems.
The same standards should be used by teachers when presenting algorithms to students.


In many cases there are alternatives that could be used and
it should be noted that students can expect to see methods of algorithm description with many
differences in detail published in books and magazines.

Teachers should ensure that the approach presented in textbooks, worksheets and examinations
does not contradict the standards that students use.
What is an Algorithm?
                    Contents




Algorithm: a step-by-step procedure for solving a problem; programming languages
are essentially a way of expressing algorithms.
Understanding Computers: Computer Languages,
by the editors of Time-Life Books, © 1988
Time-Life Books Inc.

In order that a task be carried out on a computer, a method or technique for the task
must be described very precisely in terms of the different steps. An algorithm is a
description of the steps of a task, using a particular technique. Writing an algorithm
is one of the first steps taken in preparing a task to be done by a computer.
Computing Science, Peter Bishop, Thomas Nelson UK, 1982

Informally, an algorithm is a collection of instructions which, when performed in a
specific sequence, produce the correct result. The study of algorithms is at the
heart of computer science.
Problem Solving and Computer Programming,
Peter Grogono & Sharon H Nelson,
© 1982 Addison-Wesley Publishing Company Inc.
Reproduced by the permission of the publisher.
Pseudocode
                        Contents




Pseudocode essentially is English with some defined rules of structure and some keywords that
make it appear a bit like program code. Some guidelines for writing pseudocode are as follows.

                                    Pseudocode Guidelines
           • The keywords used for pseudocode in this document are:
                1.   for start and finish
                     BEGIN MAINPROGRAM, END MAINPROGRAM
                2.   for initialisation
                     INITIALISATION, END INITIALISATION
                3.   for subprogram
                     BEGIN SUBPROGRAM, END SUBPROGRAM
                4.   for selection
                     IF, THEN, ELSE, ENDIF
                5.   for multi-way selection
                     CASEWHERE, OTHERWISE, ENDCASE
                6.   for pre-test repetition
                     WHILE, ENDWHILE
                7.   for post-test repetition
                     REPEAT, UNTIL
Pseudocode
                                                                                      continued
                       Contents




Pseudocode essentially is English with some defined rules of structure and some keywords that
make it appear a bit like program code. Some guidelines for writing pseudocode are as follows.

                           Pseudocode Guidelines (continued)


     • Keywords are written in CAPITALS.
     • Structural elements come in pairs, e.g.
              for every BEGIN there is an END
              for every IF there is an ENDIF, etc.
     • Indenting is used to show structure in the algorithm.
     • The names of subprograms are underlined.
            This means that when refining the solution to a problem,
            a word in an algorithm can be underlined and a subprogram developed.

     This feature enables the use of the ‘top-down’ development concept,
     where details for a particular process need only be considered within the
     relevant sub-routine.
Flowcharts
                    Contents




    Flowcharts are a diagrammatic method of representing algorithms.


They use an intuitive scheme of showing:

                  • operations in boxes
                  • connected by lines and arrows

             that graphically show the flow of control in an algorithm.


The Australian Standards for flowcharting indicate that
the main direction of flow is accepted as being:

                       1. top to bottom and
                       2. left to right.
Flowcharts
                                                                                            elements
                         Contents




Flowcharts are made up of the following box types connected by lines with arrowheads indicating the flow.
It is common practice only to show arrowheads where the flow is counter to the Australian standard.




 These should be thought of as the characters of flowcharts.
 1. Just as ordinary characters must be put together in certain ways to produce well-formed words,
 2. words must be put together in certain ways to produce well-structured sentences,
 3. these flowchart elements must be connected in certain ways to form accepted structures and
 4. the structures connected in certain ways to form well-structured algorithms.
Flowcharts
                                                                       elements (continued)
                      Contents


The main flowcharting structures are
                         1. Sequence
                         2. Selection
                         3. Repetition

It is considered good practice for a single flowchart
       never to exceed the bounds of one page.
If a flowchart does not fit on one page,
       this is one instance in which the better solution is to use refinement
       which results in the creation of subprograms.

Subprograms on separate pages are more desirable than using a connector to join
flowcharts over more than one page.

A flowchart expressing the solution to an involved problem may have:
     1. the main program flowchart on one page
     2. with subprograms continuing the problem solution on subsequent pages.

Regardless of page size, it is also important to start any complex algorithm with:
    1. a clear, uncluttered main line.
    2. This should reference the required subroutines
    3. whose detail is shown in separate flowcharts.
Programming Structures
                 Contents



Each of the five acceptable structures can be built from the basic
elements as shown below.
Programming Structures
                                                                 continued
                 Contents



Each of the five acceptable structures can be built from the basic
elements as shown below.
Programming Structures
                                                                 continued
                 Contents



Each of the five acceptable structures can be built from the basic
elements as shown below.
Programming Structures
                                                                   continued
                  Contents



Each of the five acceptable structures can be built from the basic
elements as shown previously.


In all cases note there is:
              1. only one entry point to the structure
              2. and one exit point as indicated by the dashed boxes.


Since each structure can be thought of as a process
    (as shown by the dashed boxes containing the structure),

more complex algorithms can be constructed by
    replacing any single process by
     one or other of the structures.
Sequence
            Contents




                In a computer program or an algorithm,
              sequence involves simple steps which are
                  to be executed one after the other.
   The steps are executed in the same order in which they are written.

In pseudocode,                In a flowchart,
sequence is expressed as:     sequence is expressed as:
                              (The arrowheads are optional if the flow is top-to-bottom.)
process 1
process 2
…
…
process n
Sequence
                                                                               example
                       Contents



An Example Using Sequence

Problem: Write a set of instructions that describe how to make a pot of tea.

    Pseudocode                           Flowchart

    BEGIN
        fill a kettle with water
        boil the water in the kettle
        put the tea leaves in the pot
        pour boiling water in the pot
    END
Selection
                              Contents



                         Selection is used in a computer program or algorithm
                 to determine which particular step or set of steps is to be executed.

    A selection statement can be used to choose a specific path dependent on a condition.
    There are two types of selection:
                    1. binary (two-way branching) selection and
                    2. multi-way (many way branching) selection.

                                         Following is a description of each.
Binary Selection                                                          Multi-way Selection
As the name implies, binary selection allows the choice
      between two possible paths.                                         Multi-way selection allows for any
                                                                          number of possible choices, or
If the condition is met then one path is taken,                           cases.
       otherwise the second possible path is followed.
                                                                          The path taken is determined by
•     In the examples that follow, the first case described requires      the selection of the choice
      a process to be completed only if the condition is true.            which is true.
•     The process is ignored if the condition is false.
                                                                          Multi-way selection is often
In other words there is only one path that requires processing            referred to as a case structure.
to be done, so the processing free path is left out rather than
included saying ‘do nothing’.
Selection
                                                                          Binary (structure)
                    Contents



                 Selection is used in a computer program or algorithm
         to determine which particular step or set of steps is to be executed.


Binary Selection                         Binary Selection

In pseudocode, binary selection is       In flowcharts, binary selection is expressed in the
expressed in the following ways:         following ways:


1.    IF condition THEN
           process 1
      ENDIF



2.   IF condition THEN
            process 1
       ELSE
            process 2
       ENDIF
Selection
                                                                         Binary (structure)
                    Contents



                Selection is used in a computer program or algorithm
        to determine which particular step or set of steps is to be executed.


Binary Selection                        Binary Selection

In pseudocode, binary selection is      In flowcharts, binary selection is expressed in the
expressed in the following ways:        following ways:


1.   IF condition THEN
           process 1
     ENDIF



2.   IF condition THEN
           process 1
     ELSE
           process 2
     ENDIF
Selection
                                                                        Binary (flowchart structure)
                          Contents



Note: In a flowchart it is most important to indicate
    1. which path is to be followed when the condition is true, and
    2. which path to follow when the condition is false.
Without these indications the flowchart is open to more than one interpretation.

Note: There are two acceptable ways to represent a decision in all of the structures.
Either method is acceptable. For consistency, the method 1 is used throughout this document.

1. The condition is expressed as a                       2. The condition is expressed as a
   statement and the two possible                        question and the two possible outcomes
   outcomes are indicated by                             are indicated by
             • True                                                 • Yes
             • False                                                • No
Selection
                                                                        Binary (examples)
                        Contents



                    Selection is used in a computer program or algorithm
            to determine which particular step or set of steps is to be executed.

Examples Using Binary Selection
Problem 1: Write a set of instructions to describe when to answer the phone.


    Binary Selection                        Binary Selection
    Pseudocode                              Flowchart

    IF the telephone is ringing THEN
          answer the telephone
    ENDIF
Selection
                                                                            Binary (examples)
                         Contents



                    Selection is used in a computer program or algorithm
            to determine which particular step or set of steps is to be executed.

Examples Using Binary Selection
Problem 2: Write a set of instructions to follow when approaching a set of traffic control lights.


    Binary Selection                           Binary Selection
    Pseudocode                                 Flowchart

    IF the signal is green THEN
          proceed through the intersection
    ELSE
          stop the vehicle
    ENDIF
Selection
                                                                       Multi-way (structure)
                     Contents



                Selection is used in a computer program or algorithm
        to determine which particular step or set of steps is to be executed.


Multi-way Selection                       Multi-way Selection

In pseudocode, multiple selection is      In flowcharts, multi-way selection is expressed as:
expressed as:

CASEWHERE expression evaluates to
    choice a :  process a
    choice b :  process b
       .            .
       .            .
       .            .
  OTHERWISE :   default process
ENDCASE

Note: As the flowchart version of the
multi-way selection indicates, only one
process on each pass is executed as a
result of the implementation of the
multi-way selection.
Selection
                                                                           Multi-way (examples)
                          Contents



                      Selection is used in a computer program or algorithm
              to determine which particular step or set of steps is to be executed.

 Example Using Multi-way Selection
 Problem: Write a set of instructions that describes how to:
          respond to all possible signals at a set of traffic control lights.

Multi-way Selection                               Multi-way Selection
Pseudocode                                        Flowchart

CASEWHERE signal is
    red      : stop the vehicle
    amber    : stop the vehicle
    green    : proceed through the intersection
  OTHERWISE : proceed with caution
ENDCASE
Repetition
             Contents



Repetition allows for a portion of an algorithm or computer program
                  to be done any number of times
              dependent on some condition being met.
       An occurrence of repetition is usually known as a loop.


               An essential feature of repetition is that
               each loop has a termination condition
                        to stop the repetition,
                   or the obvious outcome is that
        the loop never completes execution (an infinite loop).


       The termination condition can be checked or tested
       1. at the beginning and is known as a pre-test loop or
       2. at the end of the loop and is known as a post-test loop.
Repetition
                          Contents                                                 Pre-test   (structure)


                  Repetition allows for a portion of an algorithm or computer program
                                    to be done any number of times
                                dependent on some condition being met.
                         An occurrence of repetition is usually known as a loop.

Repetition: Pre-Test
                    A pre-tested loop is so named because the condition has to be met at
                   the very beginning of the loop or the body of the loop is not executed.
This construct is often called a guarded loop.
The body of the loop is executed repeatedly while the termination condition is true.

Repetition                                        Repetition

In pseudocode, pre-test repetition is             In flowcharting
expressed as:                                     pre-test repetition
                                                  is expressed as:
WHILE condition is true
    process(es)
ENDWHILE
Repetition
                          Contents                                               Post-test     (structure)


                  Repetition allows for a portion of an algorithm or computer program
                                    to be done any number of times
                                dependent on some condition being met.
                         An occurrence of repetition is usually known as a loop.

Repetition: Post-Test
•    A post-tested loop executes the body of the loop before testing the termination condition.
•    This construct is often referred to as an unguarded loop.
•    The body of the loop is repeatedly executed until the termination condition is true.
An important difference between a pre-test and post-test loop is that the statements of a post-test loop
are executed at least once even if the condition is originally true, whereas the body of the pre-test loop
may never be executed if the termination condition is originally true.
A close look at the representations of the two loop types makes this point apparent.
                                                 Repetition
Repetition
                                                 In a flowchart
In pseudocode, post-test repetition is
                                                 post-test repetition
expressed as:
                                                 is expressed as:
REPEAT
    process
UNTIL condition is true
Repetition
                         Contents                                                  Pre-test   (example)


                  Repetition allows for a portion of an algorithm or computer program
                                    to be done any number of times
                                dependent on some condition being met.
                         An occurrence of repetition is usually known as a loop.

An Example Using Pre-Test Repetition
Problem: Determine a safety procedure for travelling in a carriage on a moving train.

 Pre-test Repetition                             Pre-test Repetition
 Pseudocode                                      Flowchart

 WHILE the train is moving
     keep wholly within the carriage
 ENDWHILE
Repetition
                         Contents                                             Post-test   (example)


                  Repetition allows for a portion of an algorithm or computer program
                                    to be done any number of times
                                dependent on some condition being met.
                         An occurrence of repetition is usually known as a loop.

An Example Using Post-Test Repetition
Problem: Determine a procedure to beat egg whites until fluffy.

 Post-test Repetition                            Post-test Repetition
 Pseudocode                                      Flowchart

 REPEAT
     beat the egg whites
 UNTIL fluffy
Subprograms
                            Contents


                     Subprograms, as the name implies, are complete part-programs
                          that are used from within the main program section.

•   They allow the process of refinement to be used to develop solutions to problems that are easy to follow.
•   Sections of the solution are developed and presented in understandable chunks, and because of this,
•   subprograms are particularly useful when using the top-down method of solution development.

When using subprograms it is important that
1. the solution expression indicates where the main program branches to a subprogram.
2. It is equally important to indicate exactly where the subprogram begins.

In pseudocode,
the statement in the main program that is expanded in a subprogram is underlined to indicate that further
    explanation follows.
The expanded subprogram section should be identified by
1. using the keywords BEGIN SUBPROGRAM
      •   followed by the underlined title used in the main program.
2. The end of the subprogram is marked by the keywords END SUBPROGRAM
      •   and the underlined title used in the main program.

When using flowcharts,
a subprogram is shown by an additional vertical line on each side of the process box.
This indicates that the subprogram is expanded elsewhere.
The start and end of the subprogram flowchart uses the name of the subprogram in the termination boxes.
Subprograms
                                                                             examples
                    Contents


              Subprograms, as the name implies, are complete part-programs
                   that are used from within the main program section.


Subprograms                            Subprograms
Pseudocode                             Flowchart

BEGIN MAINPROGRAM
    process l
    process 2
    process 3
    process 4
END MAINPROGRAM

BEGIN SUBPROGRAM process 2
    do this
    do that
END SUBPROGRAM process 2
Subprograms
                                    Contents


                           Subprograms, as the name implies, are complete part-programs
                                that are used from within the main program section.

In many cases a subprogram can be written to do the same task at two or more points in an algorithm.
•    Each time the subprogram is called, it may operate on different data.
•    To indicate the data to be used one or more parameters are used.

The parameters allow the author to write a general algorithm using the formal parameters.
When the subprogram is executed, the algorithm carries out its task on the actual parameters given at the call.

The parameters to be used by a subprogram are provided as a list in parentheses after the name of the subprogram.
There is no need to include them at the end of the algorithm.

    Example of Using Subprograms with one Parameter in Pseudocode

    BEGIN MAINPROGRAM                        The first time that the subprogram ‘read’ is called:
          read (name)                        1. the characters are read into the array called ‘name’
          read (address)                     2. the second time, the data (characters) are read into the array called ‘address’.
    END MAINPROGRAM

    BEGIN SUBPROGRAM read (array)
          Set pointer to first position
          Get a character
          WHILE there is still more data AND there is room in the array
                 store data in the array at the position given by the pointer
                 Increment the pointer
                 get data
          ENDWHILE
    END SUBPROGRAM read (array)

Más contenido relacionado

La actualidad más candente

PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)Dr. Ahmed Al Zaidy
 
Programming language design and implemenation
Programming language design and implemenationProgramming language design and implemenation
Programming language design and implemenationAshwini Awatare
 
Multicore Computers
Multicore ComputersMulticore Computers
Multicore ComputersA B Shinde
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitabdosaidgkv
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahniHitesh Wagle
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programminghodcsencet
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingVIKASH MAINANWAL
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGSaqib Raza
 
Rotor Cipher and Enigma Machine
Rotor Cipher and Enigma MachineRotor Cipher and Enigma Machine
Rotor Cipher and Enigma MachineSaurabh Kaushik
 
Use case point ( Software Estimation Technique)
Use case point ( Software Estimation Technique)Use case point ( Software Estimation Technique)
Use case point ( Software Estimation Technique)Punjab University
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)Dushmanta Nath
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 

La actualidad más candente (20)

PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Debugging
DebuggingDebugging
Debugging
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)
 
Programming language design and implemenation
Programming language design and implemenationProgramming language design and implemenation
Programming language design and implemenation
 
Multicore Computers
Multicore ComputersMulticore Computers
Multicore Computers
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
 
Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling
 
Pthread
PthreadPthread
Pthread
 
Operating System lab
Operating System labOperating System lab
Operating System lab
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
 
Rotor Cipher and Enigma Machine
Rotor Cipher and Enigma MachineRotor Cipher and Enigma Machine
Rotor Cipher and Enigma Machine
 
Use case point ( Software Estimation Technique)
Use case point ( Software Estimation Technique)Use case point ( Software Estimation Technique)
Use case point ( Software Estimation Technique)
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
System software
System softwareSystem software
System software
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 

Destacado

Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to PseudocodeDamian T. Gordon
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowchartsnicky_walters
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basicsSabik T S
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010Jordan Delacruz
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1luhkahreth
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 

Destacado (10)

Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Pseudocode flowcharts
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
 
pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 

Similar a Algorithms

IRJET - Pseudocode to Python Translation using Machine Learning
IRJET - Pseudocode to Python Translation using Machine LearningIRJET - Pseudocode to Python Translation using Machine Learning
IRJET - Pseudocode to Python Translation using Machine LearningIRJET Journal
 
SWE-401 - 9. Software Implementation
SWE-401 - 9. Software ImplementationSWE-401 - 9. Software Implementation
SWE-401 - 9. Software Implementationghayour abbas
 
9. Software Implementation
9. Software Implementation9. Software Implementation
9. Software Implementationghayour abbas
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfMaryJacob24
 
APP_All Five Unit PPT_NOTES.pptx
APP_All Five Unit PPT_NOTES.pptxAPP_All Five Unit PPT_NOTES.pptx
APP_All Five Unit PPT_NOTES.pptxHaniyaMumtaj1
 
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...Sabrina Ball
 
Cs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ reportCs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ reportKhushboo Wadhwani
 

Similar a Algorithms (20)

Coding
CodingCoding
Coding
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
IRJET - Pseudocode to Python Translation using Machine Learning
IRJET - Pseudocode to Python Translation using Machine LearningIRJET - Pseudocode to Python Translation using Machine Learning
IRJET - Pseudocode to Python Translation using Machine Learning
 
Coding
CodingCoding
Coding
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
Unit 2.pptx
Unit 2.pptxUnit 2.pptx
Unit 2.pptx
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
SWE-401 - 9. Software Implementation
SWE-401 - 9. Software ImplementationSWE-401 - 9. Software Implementation
SWE-401 - 9. Software Implementation
 
9. Software Implementation
9. Software Implementation9. Software Implementation
9. Software Implementation
 
Lecture No.1.pptx
Lecture No.1.pptxLecture No.1.pptx
Lecture No.1.pptx
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Aq4301224227
Aq4301224227Aq4301224227
Aq4301224227
 
Algorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdf
 
C question
C questionC question
C question
 
Programming
ProgrammingProgramming
Programming
 
APP_All Five Unit PPT_NOTES.pptx
APP_All Five Unit PPT_NOTES.pptxAPP_All Five Unit PPT_NOTES.pptx
APP_All Five Unit PPT_NOTES.pptx
 
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...A Program Transformation Technique to Support Aspect-Oriented Programming wit...
A Program Transformation Technique to Support Aspect-Oriented Programming wit...
 
Cs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ reportCs690 object oriented_software_engineering_team01_ report
Cs690 object oriented_software_engineering_team01_ report
 

Más de Liam Dunphy

Butterfly Struggles - An inspirational life lesson
Butterfly Struggles - An inspirational life lessonButterfly Struggles - An inspirational life lesson
Butterfly Struggles - An inspirational life lessonLiam Dunphy
 
Tm hills scarytasla-ming
Tm hills scarytasla-mingTm hills scarytasla-ming
Tm hills scarytasla-mingLiam Dunphy
 
Creative learning spaces
Creative learning spacesCreative learning spaces
Creative learning spacesLiam Dunphy
 
#ccGlobal for cesimeet
#ccGlobal for cesimeet#ccGlobal for cesimeet
#ccGlobal for cesimeetLiam Dunphy
 
Tm sydney north - collaboration
Tm sydney north - collaborationTm sydney north - collaboration
Tm sydney north - collaborationLiam Dunphy
 
Training presentation outlook 2007 manage your mailbox 3-move or copy message...
Training presentation outlook 2007 manage your mailbox 3-move or copy message...Training presentation outlook 2007 manage your mailbox 3-move or copy message...
Training presentation outlook 2007 manage your mailbox 3-move or copy message...Liam Dunphy
 
Training presentation outlook 2007 manage your mailbox 2-understand your choi...
Training presentation outlook 2007 manage your mailbox 2-understand your choi...Training presentation outlook 2007 manage your mailbox 2-understand your choi...
Training presentation outlook 2007 manage your mailbox 2-understand your choi...Liam Dunphy
 
Organising and dss steps in designing a spreadsheet solution
Organising and dss   steps in designing a spreadsheet solutionOrganising and dss   steps in designing a spreadsheet solution
Organising and dss steps in designing a spreadsheet solutionLiam Dunphy
 
Programming Languages
Programming LanguagesProgramming Languages
Programming LanguagesLiam Dunphy
 
Representational Tools
Representational ToolsRepresentational Tools
Representational ToolsLiam Dunphy
 
System Data Modelling Tools
System Data Modelling ToolsSystem Data Modelling Tools
System Data Modelling ToolsLiam Dunphy
 
Communications Systems
Communications SystemsCommunications Systems
Communications SystemsLiam Dunphy
 
Ipt Syllabus Changes Communications Systems
Ipt Syllabus Changes   Communications SystemsIpt Syllabus Changes   Communications Systems
Ipt Syllabus Changes Communications SystemsLiam Dunphy
 
Ipt Syllabus Changes
Ipt Syllabus ChangesIpt Syllabus Changes
Ipt Syllabus ChangesLiam Dunphy
 
Ipt Syllabus Changes Project Management
Ipt Syllabus Changes   Project ManagementIpt Syllabus Changes   Project Management
Ipt Syllabus Changes Project ManagementLiam Dunphy
 

Más de Liam Dunphy (20)

Butterfly Struggles - An inspirational life lesson
Butterfly Struggles - An inspirational life lessonButterfly Struggles - An inspirational life lesson
Butterfly Struggles - An inspirational life lesson
 
Tm hills scarytasla-ming
Tm hills scarytasla-mingTm hills scarytasla-ming
Tm hills scarytasla-ming
 
Creative learning spaces
Creative learning spacesCreative learning spaces
Creative learning spaces
 
#ccGlobal for cesimeet
#ccGlobal for cesimeet#ccGlobal for cesimeet
#ccGlobal for cesimeet
 
Tm sydney north - collaboration
Tm sydney north - collaborationTm sydney north - collaboration
Tm sydney north - collaboration
 
Training presentation outlook 2007 manage your mailbox 3-move or copy message...
Training presentation outlook 2007 manage your mailbox 3-move or copy message...Training presentation outlook 2007 manage your mailbox 3-move or copy message...
Training presentation outlook 2007 manage your mailbox 3-move or copy message...
 
Training presentation outlook 2007 manage your mailbox 2-understand your choi...
Training presentation outlook 2007 manage your mailbox 2-understand your choi...Training presentation outlook 2007 manage your mailbox 2-understand your choi...
Training presentation outlook 2007 manage your mailbox 2-understand your choi...
 
Mm expertise
Mm expertiseMm expertise
Mm expertise
 
Organising and dss steps in designing a spreadsheet solution
Organising and dss   steps in designing a spreadsheet solutionOrganising and dss   steps in designing a spreadsheet solution
Organising and dss steps in designing a spreadsheet solution
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
Meta Languages
Meta LanguagesMeta Languages
Meta Languages
 
Algorithms2
Algorithms2Algorithms2
Algorithms2
 
Iteration
IterationIteration
Iteration
 
Representational Tools
Representational ToolsRepresentational Tools
Representational Tools
 
System Data Modelling Tools
System Data Modelling ToolsSystem Data Modelling Tools
System Data Modelling Tools
 
Communications Systems
Communications SystemsCommunications Systems
Communications Systems
 
Ipt Syllabus Changes Communications Systems
Ipt Syllabus Changes   Communications SystemsIpt Syllabus Changes   Communications Systems
Ipt Syllabus Changes Communications Systems
 
Ipt Syllabus Changes
Ipt Syllabus ChangesIpt Syllabus Changes
Ipt Syllabus Changes
 
Ipt Syllabus Changes Project Management
Ipt Syllabus Changes   Project ManagementIpt Syllabus Changes   Project Management
Ipt Syllabus Changes Project Management
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 

Último

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 

Último (20)

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 

Algorithms

  • 1. Software Design and Development Algorithms in SDD
  • 2. Contents Course Specifications 1. Algorithm description 5. Programming structure 2. What is an algorithm? 6. Sequence 3. Pseudocode 7. Selection 4. Flowcharts 8. Repetition NSW BOS Course Specifications 9. Subprograms
  • 3. Methods of Algorithm Description Contents Introduction There are many definitions of methods of algorithm description in existence, some with many special symbols and keywords defined for special purposes. This document presents two methods for describing algorithms: 1. pseudocode 2. flowcharts Both methods must be used in the implementation of the Software Design and Development course. It is expected that students are able to develop and interpret algorithms using both of these methods. In assessing the quality of algorithm descriptions, general criteria such as: • the correctness of the algorithm • the clarity of the description • the use of appropriate control structures and • the embodiment of structured methods rather than the specific features of any method, should be taken into consideration.
  • 4. Methods of Algorithm Description continued Contents 1. Clarity of description AND 2. Consistency in the use of the components of the method chosen are of far more importance than • the actual shape of a flowchart element or • the specific wording of a pseudocode statement. The document presents standards that students should aim for in publishing solutions to problems. The same standards should be used by teachers when presenting algorithms to students. In many cases there are alternatives that could be used and it should be noted that students can expect to see methods of algorithm description with many differences in detail published in books and magazines. Teachers should ensure that the approach presented in textbooks, worksheets and examinations does not contradict the standards that students use.
  • 5. What is an Algorithm? Contents Algorithm: a step-by-step procedure for solving a problem; programming languages are essentially a way of expressing algorithms. Understanding Computers: Computer Languages, by the editors of Time-Life Books, © 1988 Time-Life Books Inc. In order that a task be carried out on a computer, a method or technique for the task must be described very precisely in terms of the different steps. An algorithm is a description of the steps of a task, using a particular technique. Writing an algorithm is one of the first steps taken in preparing a task to be done by a computer. Computing Science, Peter Bishop, Thomas Nelson UK, 1982 Informally, an algorithm is a collection of instructions which, when performed in a specific sequence, produce the correct result. The study of algorithms is at the heart of computer science. Problem Solving and Computer Programming, Peter Grogono & Sharon H Nelson, © 1982 Addison-Wesley Publishing Company Inc. Reproduced by the permission of the publisher.
  • 6. Pseudocode Contents Pseudocode essentially is English with some defined rules of structure and some keywords that make it appear a bit like program code. Some guidelines for writing pseudocode are as follows. Pseudocode Guidelines • The keywords used for pseudocode in this document are: 1. for start and finish BEGIN MAINPROGRAM, END MAINPROGRAM 2. for initialisation INITIALISATION, END INITIALISATION 3. for subprogram BEGIN SUBPROGRAM, END SUBPROGRAM 4. for selection IF, THEN, ELSE, ENDIF 5. for multi-way selection CASEWHERE, OTHERWISE, ENDCASE 6. for pre-test repetition WHILE, ENDWHILE 7. for post-test repetition REPEAT, UNTIL
  • 7. Pseudocode continued Contents Pseudocode essentially is English with some defined rules of structure and some keywords that make it appear a bit like program code. Some guidelines for writing pseudocode are as follows. Pseudocode Guidelines (continued) • Keywords are written in CAPITALS. • Structural elements come in pairs, e.g. for every BEGIN there is an END for every IF there is an ENDIF, etc. • Indenting is used to show structure in the algorithm. • The names of subprograms are underlined. This means that when refining the solution to a problem, a word in an algorithm can be underlined and a subprogram developed. This feature enables the use of the ‘top-down’ development concept, where details for a particular process need only be considered within the relevant sub-routine.
  • 8. Flowcharts Contents Flowcharts are a diagrammatic method of representing algorithms. They use an intuitive scheme of showing: • operations in boxes • connected by lines and arrows that graphically show the flow of control in an algorithm. The Australian Standards for flowcharting indicate that the main direction of flow is accepted as being: 1. top to bottom and 2. left to right.
  • 9. Flowcharts elements Contents Flowcharts are made up of the following box types connected by lines with arrowheads indicating the flow. It is common practice only to show arrowheads where the flow is counter to the Australian standard. These should be thought of as the characters of flowcharts. 1. Just as ordinary characters must be put together in certain ways to produce well-formed words, 2. words must be put together in certain ways to produce well-structured sentences, 3. these flowchart elements must be connected in certain ways to form accepted structures and 4. the structures connected in certain ways to form well-structured algorithms.
  • 10. Flowcharts elements (continued) Contents The main flowcharting structures are 1. Sequence 2. Selection 3. Repetition It is considered good practice for a single flowchart never to exceed the bounds of one page. If a flowchart does not fit on one page, this is one instance in which the better solution is to use refinement which results in the creation of subprograms. Subprograms on separate pages are more desirable than using a connector to join flowcharts over more than one page. A flowchart expressing the solution to an involved problem may have: 1. the main program flowchart on one page 2. with subprograms continuing the problem solution on subsequent pages. Regardless of page size, it is also important to start any complex algorithm with: 1. a clear, uncluttered main line. 2. This should reference the required subroutines 3. whose detail is shown in separate flowcharts.
  • 11. Programming Structures Contents Each of the five acceptable structures can be built from the basic elements as shown below.
  • 12. Programming Structures continued Contents Each of the five acceptable structures can be built from the basic elements as shown below.
  • 13. Programming Structures continued Contents Each of the five acceptable structures can be built from the basic elements as shown below.
  • 14. Programming Structures continued Contents Each of the five acceptable structures can be built from the basic elements as shown previously. In all cases note there is: 1. only one entry point to the structure 2. and one exit point as indicated by the dashed boxes. Since each structure can be thought of as a process (as shown by the dashed boxes containing the structure), more complex algorithms can be constructed by replacing any single process by one or other of the structures.
  • 15. Sequence Contents In a computer program or an algorithm, sequence involves simple steps which are to be executed one after the other. The steps are executed in the same order in which they are written. In pseudocode, In a flowchart, sequence is expressed as: sequence is expressed as: (The arrowheads are optional if the flow is top-to-bottom.) process 1 process 2 … … process n
  • 16. Sequence example Contents An Example Using Sequence Problem: Write a set of instructions that describe how to make a pot of tea. Pseudocode Flowchart BEGIN fill a kettle with water boil the water in the kettle put the tea leaves in the pot pour boiling water in the pot END
  • 17. Selection Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. A selection statement can be used to choose a specific path dependent on a condition. There are two types of selection: 1. binary (two-way branching) selection and 2. multi-way (many way branching) selection. Following is a description of each. Binary Selection Multi-way Selection As the name implies, binary selection allows the choice between two possible paths. Multi-way selection allows for any number of possible choices, or If the condition is met then one path is taken, cases. otherwise the second possible path is followed. The path taken is determined by • In the examples that follow, the first case described requires the selection of the choice a process to be completed only if the condition is true. which is true. • The process is ignored if the condition is false. Multi-way selection is often In other words there is only one path that requires processing referred to as a case structure. to be done, so the processing free path is left out rather than included saying ‘do nothing’.
  • 18. Selection Binary (structure) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Binary Selection Binary Selection In pseudocode, binary selection is In flowcharts, binary selection is expressed in the expressed in the following ways: following ways: 1. IF condition THEN process 1 ENDIF 2. IF condition THEN process 1 ELSE process 2 ENDIF
  • 19. Selection Binary (structure) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Binary Selection Binary Selection In pseudocode, binary selection is In flowcharts, binary selection is expressed in the expressed in the following ways: following ways: 1. IF condition THEN process 1 ENDIF 2. IF condition THEN process 1 ELSE process 2 ENDIF
  • 20. Selection Binary (flowchart structure) Contents Note: In a flowchart it is most important to indicate 1. which path is to be followed when the condition is true, and 2. which path to follow when the condition is false. Without these indications the flowchart is open to more than one interpretation. Note: There are two acceptable ways to represent a decision in all of the structures. Either method is acceptable. For consistency, the method 1 is used throughout this document. 1. The condition is expressed as a 2. The condition is expressed as a statement and the two possible question and the two possible outcomes outcomes are indicated by are indicated by • True • Yes • False • No
  • 21. Selection Binary (examples) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Examples Using Binary Selection Problem 1: Write a set of instructions to describe when to answer the phone. Binary Selection Binary Selection Pseudocode Flowchart IF the telephone is ringing THEN answer the telephone ENDIF
  • 22. Selection Binary (examples) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Examples Using Binary Selection Problem 2: Write a set of instructions to follow when approaching a set of traffic control lights. Binary Selection Binary Selection Pseudocode Flowchart IF the signal is green THEN proceed through the intersection ELSE stop the vehicle ENDIF
  • 23. Selection Multi-way (structure) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Multi-way Selection Multi-way Selection In pseudocode, multiple selection is In flowcharts, multi-way selection is expressed as: expressed as: CASEWHERE expression evaluates to choice a : process a choice b : process b . . . . . . OTHERWISE : default process ENDCASE Note: As the flowchart version of the multi-way selection indicates, only one process on each pass is executed as a result of the implementation of the multi-way selection.
  • 24. Selection Multi-way (examples) Contents Selection is used in a computer program or algorithm to determine which particular step or set of steps is to be executed. Example Using Multi-way Selection Problem: Write a set of instructions that describes how to: respond to all possible signals at a set of traffic control lights. Multi-way Selection Multi-way Selection Pseudocode Flowchart CASEWHERE signal is red : stop the vehicle amber : stop the vehicle green : proceed through the intersection OTHERWISE : proceed with caution ENDCASE
  • 25. Repetition Contents Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. An essential feature of repetition is that each loop has a termination condition to stop the repetition, or the obvious outcome is that the loop never completes execution (an infinite loop). The termination condition can be checked or tested 1. at the beginning and is known as a pre-test loop or 2. at the end of the loop and is known as a post-test loop.
  • 26. Repetition Contents Pre-test (structure) Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. Repetition: Pre-Test A pre-tested loop is so named because the condition has to be met at the very beginning of the loop or the body of the loop is not executed. This construct is often called a guarded loop. The body of the loop is executed repeatedly while the termination condition is true. Repetition Repetition In pseudocode, pre-test repetition is In flowcharting expressed as: pre-test repetition is expressed as: WHILE condition is true process(es) ENDWHILE
  • 27. Repetition Contents Post-test (structure) Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. Repetition: Post-Test • A post-tested loop executes the body of the loop before testing the termination condition. • This construct is often referred to as an unguarded loop. • The body of the loop is repeatedly executed until the termination condition is true. An important difference between a pre-test and post-test loop is that the statements of a post-test loop are executed at least once even if the condition is originally true, whereas the body of the pre-test loop may never be executed if the termination condition is originally true. A close look at the representations of the two loop types makes this point apparent. Repetition Repetition In a flowchart In pseudocode, post-test repetition is post-test repetition expressed as: is expressed as: REPEAT process UNTIL condition is true
  • 28. Repetition Contents Pre-test (example) Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. An Example Using Pre-Test Repetition Problem: Determine a safety procedure for travelling in a carriage on a moving train. Pre-test Repetition Pre-test Repetition Pseudocode Flowchart WHILE the train is moving keep wholly within the carriage ENDWHILE
  • 29. Repetition Contents Post-test (example) Repetition allows for a portion of an algorithm or computer program to be done any number of times dependent on some condition being met. An occurrence of repetition is usually known as a loop. An Example Using Post-Test Repetition Problem: Determine a procedure to beat egg whites until fluffy. Post-test Repetition Post-test Repetition Pseudocode Flowchart REPEAT beat the egg whites UNTIL fluffy
  • 30. Subprograms Contents Subprograms, as the name implies, are complete part-programs that are used from within the main program section. • They allow the process of refinement to be used to develop solutions to problems that are easy to follow. • Sections of the solution are developed and presented in understandable chunks, and because of this, • subprograms are particularly useful when using the top-down method of solution development. When using subprograms it is important that 1. the solution expression indicates where the main program branches to a subprogram. 2. It is equally important to indicate exactly where the subprogram begins. In pseudocode, the statement in the main program that is expanded in a subprogram is underlined to indicate that further explanation follows. The expanded subprogram section should be identified by 1. using the keywords BEGIN SUBPROGRAM • followed by the underlined title used in the main program. 2. The end of the subprogram is marked by the keywords END SUBPROGRAM • and the underlined title used in the main program. When using flowcharts, a subprogram is shown by an additional vertical line on each side of the process box. This indicates that the subprogram is expanded elsewhere. The start and end of the subprogram flowchart uses the name of the subprogram in the termination boxes.
  • 31. Subprograms examples Contents Subprograms, as the name implies, are complete part-programs that are used from within the main program section. Subprograms Subprograms Pseudocode Flowchart BEGIN MAINPROGRAM process l process 2 process 3 process 4 END MAINPROGRAM BEGIN SUBPROGRAM process 2 do this do that END SUBPROGRAM process 2
  • 32. Subprograms Contents Subprograms, as the name implies, are complete part-programs that are used from within the main program section. In many cases a subprogram can be written to do the same task at two or more points in an algorithm. • Each time the subprogram is called, it may operate on different data. • To indicate the data to be used one or more parameters are used. The parameters allow the author to write a general algorithm using the formal parameters. When the subprogram is executed, the algorithm carries out its task on the actual parameters given at the call. The parameters to be used by a subprogram are provided as a list in parentheses after the name of the subprogram. There is no need to include them at the end of the algorithm. Example of Using Subprograms with one Parameter in Pseudocode BEGIN MAINPROGRAM The first time that the subprogram ‘read’ is called: read (name) 1. the characters are read into the array called ‘name’ read (address) 2. the second time, the data (characters) are read into the array called ‘address’. END MAINPROGRAM BEGIN SUBPROGRAM read (array) Set pointer to first position Get a character WHILE there is still more data AND there is room in the array store data in the array at the position given by the pointer Increment the pointer get data ENDWHILE END SUBPROGRAM read (array)