Algorithm and pseudo codes

Prepared By:
Mr. Richard R. Basilio
BSECE – Dip ICT
Algorithm and pseudo codes
   By wikipedia definition:
      ▪ an algorithm is a sequence of finite instructions,
        often used for calculation and data processing.
      ▪ It is formally a type of effective method in which a
        list of well-defined instructions for completing a
        task will, when given an initial state, proceed
        through a well-defined series of successive states,
        eventually terminating in an end-state.
Algorithm and pseudo codes
   First documented algorithm by Euclid (300 B.C.)
     to compute greatest common divisor (gcd).
     Example: gcd(3,21)=3
     Condition:
1. Let A and B be integers with A > B 0.
2. If B = 0, then the gcd is A and the algorithm ends.
3. Otherwise, find q and r such that
        A = qB + r where 0 r < B
   Note that we have 0 r < B < A and gcd(A,B) = gcd(B,r).
   Replace A by B, B by r. Go to step 2.
   Example No. 2:
     Find the greatest common divisor of A=40, B=15;
     using Euclidean algorithm;

         A = 2B + 10    A = 15 ; B = 10
         A = 1B + 5     A = 10 ; B = 5
         A = 2B + 0     A=5;B=0
         gcd is 5
   There are three properties of algorithm that
    must have to consider in solving a certain
    problem in programming:
       Finiteness
       Absence of Ambiguity
       Sequence Definition
       Input and Output Definition
       Effectiveness
       Scope of Definition
   Finiteness
     The execution of a programmed algorithm must
     be complete after a finite number of operations
     have been performed. Otherwise, we cannot
     claim that the execution produces a solution.
   Absence of Ambiguity
     The representation of every step of an algorithm
      should have a unique interpretation which also
      understand by the human.
     It is convenient to deal with algorithms presented
      in notational with sparse detail:
      ▪ Example:
       ▪ Pseudo code
       ▪ Flowcharts
   Sequence of Definition
     The sequence in which the steps of the algorithm
      are to carried out should be clearly specified.
     In algorithmic specifications, the instructions are
      performed from top to button, unless the
      instruction themselves otherwise specified.
   Input and Output Definition
     Inputs – are the data items that is presented in the
      algorithm.
     Outputs – are the data items presented to the
      outside world as the result of the execution of a
      program based on the algorithm.
     An algorithm ought to produce at least one
      output (otherwise, what use is it?...)
   Effectiveness
     it consists of basic instructions that are realizable.
      This means that the instructions can be
      performed by using the given inputs in a finite
      amount of time.
     The instructions of an algorithm may order the
      computer only to perform tasks that is capable of
      carrying out.
   Scope Definition
     An algorithm applies to the following:
      ▪ Specific problem or class of problem
      ▪ The range of inputs has to be predefined
      ▪ The range determines the generality of the algorithm.
   Algorithms can be expressed in many kinds of
    notation, including:
     Natural language
     Pseudo Code
     Flowcharts
     Programming Language
Algorithm and pseudo codes
   “Pseudo” means imitation or false and “code”
    refers to the instructions written in a
    programming language.
   Pseudocode is another programming analysis
    tool that is used for planning a program.
   Pseudocode is also called Program Design
    Language (PDL).
   By wikipedia definition:
     Pseudocode is a compact and informal
      high-level description of a computer
      programming algorithm that uses the
      structural conventions of some
      programming language, but is intended for
      human reading rather than machine
      reading.
   Pseudocode is made up of the following logic
    structures that have been proved to be
    sufficient for writing any computer program:
     Sequence Logic
     Selection Logic
     Iteration Logic
   It is used to perform instructions in a
    sequence, that is one after another.
   Thus, for sequence logic, pseudocode
    instructions are written in an order in which
    they are to be performed.
   The logic flow of pseudocode is from top to
    bottom.
Algorithm and pseudo codes
   It is used for making decisions and for
    selecting the proper path out of two or more
    alternative paths in program logic.
   It is also known as decision logic.
   Selection logic is depicted as either an
    IF...THEN or an IF...THEN...ELSE structure.
Algorithm and pseudo codes
Algorithm and pseudo codes
   It is used to produce loops when one or more
    instructions may be executed several times
    depending on some of the conditions.
   It uses structures called the DO_WHILE, FOR
    and the REPEAT_UNTIL.
Algorithm and pseudo codes
Algorithm and pseudo codes
Algorithm and pseudo codes
1. Write only one statement per line.
   Each statement in your pseudocode should
    express just one action for the computer.
   If the task list is properly drawn, then in
    most cases each task will correspond to one
    line of pseudocode.
   Examples
2. Capitalized initial keyword.
   In the example above, READ and WRITE
    are in caps.
   There are just a few keywords we will use:
    ▪ READ, WRITE, IF, ELSE, ENDIF, WHILE,
      ENDWHILE, REPEAT, UNTIL
3. Indent to show hierarchy.
   We will use a particular indentation pattern in
    each of the design structures:
    ▪ SEQUENCE: keep statements that are “stacked” in
      sequence all starting in the same column.
    ▪ SELECTION: indent the statements that fall inside the
      selection structure, but not the keywords that form the
      selection
    ▪ LOOPING: indent the statements that fall inside the
      loop, but not the keywords that form the loop
   Examples:
4. End multi-line structures.
 ▫ All the initial keyword must always in line with the
   last or end of the structure.
5. Keep statement language independent.
 ▫ Resist the urge to write in whatever language you
   are most comfortable with. There may be special
   features available in the language you plan to
   eventually write the program in; if you are SURE it
   will be written in that language, then you can use
   the features. If not, then avoid using the special
   features.
   In summary:
     Write only one statement per line.
     Capitalized initial keyword.
     Indent to show hierarchy.
     End multi-line structures.
     Keep statement language independent.
•   These are follows:
    ▫ Number each instruction.
       This is to enforce the notion, “well-ordered collection of
        ... operations.”
    ▫ Each instruction should be unambiguous.
       It means the computing agent, in this case the reader,
        should be capable of carrying out the instructions. And
        also, each instruction should be effectively computable
        (do-able).
    ▫ Completeness.
       Nothing should be left out.
   Following are some of the advantages of
    using pseudocode:
     Converting a pseudocode to a programming
      language is much more easier than converting a
      flowchart.
     As compared to flowchart, it is easier to modify a
      pseudocode of a program logic when program
      modifications are necessary.
   It also suffers from some of the limitations.
    These limitations are as follows:
     In the cases of pseudocode, a graphic
      representation of program logic is not available.
     There are no standard rules to follow for using a
      pseudocode. Different programmers use their
      own style of writing pseudocode and hence,
      communication problem occurs due to lack of
      standardization.
   To symbolize the arithmetic operators we use
    these symbols:
     Note: There is a precedence or hierarchy implied
     in this symbols.
   When we have to make a choice between
    actions, we almost always base that choice
    on a test.
   There is a universally accepted set of symbols
    used to represent these phrases:
Algorithm and pseudo codes
Algorithm and pseudo codes
Algorithm and pseudo codes
 It is more difficult to follow the
 logic of or write pseudocode as
 compared to flowcharting.
Prepare ½ crosswise yellow paper for
seatwork after the discussion.
1 de 44

Recomendados

Algorithm and flowchart por
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
7.1K vistas34 diapositivas
Algorithms and Flowcharts por
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
309.8K vistas31 diapositivas
Algorithm and flowchart por
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartElizabeth de Leon Aler
87.3K vistas9 diapositivas
ppt of flowchart por
ppt of flowchartppt of flowchart
ppt of flowchart140120109032
38.8K vistas19 diapositivas
Presentation on Function in C Programming por
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
14.3K vistas17 diapositivas
What is an algorithm? por
What is an algorithm?What is an algorithm?
What is an algorithm?Angela DeHart
18.4K vistas33 diapositivas

Más contenido relacionado

La actualidad más candente

Pseudocode flowcharts por
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowchartsnicky_walters
51.2K vistas13 diapositivas
Constants and variables in c programming por
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programmingChitrank Dixit
7.6K vistas9 diapositivas
Algorithm por
AlgorithmAlgorithm
AlgorithmIHTISHAM UL HAQ
7.5K vistas16 diapositivas
Basics of c++ Programming Language por
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
47.8K vistas78 diapositivas
Data types in C por
Data types in CData types in C
Data types in CTarun Sharma
33.8K vistas12 diapositivas
Introduction to flowchart por
Introduction to flowchartIntroduction to flowchart
Introduction to flowchartJordan Delacruz
70.7K vistas34 diapositivas

La actualidad más candente(20)

Pseudocode flowcharts por nicky_walters
Pseudocode flowchartsPseudocode flowcharts
Pseudocode flowcharts
nicky_walters51.2K vistas
Constants and variables in c programming por Chitrank Dixit
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
Chitrank Dixit7.6K vistas
Basics of c++ Programming Language por Ahmad Idrees
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees47.8K vistas
Data types in C por Tarun Sharma
Data types in CData types in C
Data types in C
Tarun Sharma33.8K vistas
Introduction to flowchart por Jordan Delacruz
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
Jordan Delacruz70.7K vistas
Programming in c por indra Kishor
Programming in cProgramming in c
Programming in c
indra Kishor10.9K vistas
Pseudocode por grahamwell
PseudocodePseudocode
Pseudocode
grahamwell3.3K vistas
Introduction to data structures and Algorithm por Dhaval Kaneria
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
Dhaval Kaneria45.6K vistas
structured programming Introduction to c fundamentals por OMWOMA JACKSON
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
OMWOMA JACKSON15.4K vistas
Introduction to Algorithms & flow charts por Yash Gupta
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
Yash Gupta2.4K vistas
Pseudocode & flowchart examples por hayrikk
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
hayrikk18.6K vistas
C Programming: Control Structure por Sokngim Sa
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa14K vistas
Problem Solving Techniques and Introduction to C por Prabu U
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
Prabu U44.6K vistas

Destacado

Introduction to Pseudocode por
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to PseudocodeDamian T. Gordon
339.3K vistas64 diapositivas
Algorithms por
AlgorithmsAlgorithms
AlgorithmsLiam Dunphy
48.9K vistas32 diapositivas
Flowchart pseudocode-examples por
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examplesGautam Roy
62.6K vistas4 diapositivas
Algorithm and flowchart2010 por
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010Jordan Delacruz
22.5K vistas12 diapositivas
Algorithmsandflowcharts1 por
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1luhkahreth
49.7K vistas32 diapositivas
Flowchart and algorithm por
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithmSayali Shivarkar
69.8K vistas10 diapositivas

Destacado(7)

Introduction to Pseudocode por Damian T. Gordon
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
Damian T. Gordon339.3K vistas
Algorithms por Liam Dunphy
AlgorithmsAlgorithms
Algorithms
Liam Dunphy48.9K vistas
Flowchart pseudocode-examples por Gautam Roy
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
Gautam Roy62.6K vistas
Algorithm and flowchart2010 por Jordan Delacruz
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
Jordan Delacruz22.5K vistas
Algorithmsandflowcharts1 por luhkahreth
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
luhkahreth49.7K vistas

Similar a Algorithm and pseudo codes

3 algorithm-and-flowchart por
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchartRohit Shrivastava
15.1K vistas37 diapositivas
DAA Unit 1.pdf por
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdfNirmalavenkatachalam
70 vistas38 diapositivas
4 coding from algorithms por
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
12K vistas41 diapositivas
Introduction to programming c por
Introduction to programming cIntroduction to programming c
Introduction to programming cMd. Rakibuzzaman Khan Pathan
41 vistas25 diapositivas
Algorithms and flow charts por
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow chartsChinnu Edwin
178 vistas19 diapositivas
Improving Code Quality Through Effective Review Process por
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
721 vistas32 diapositivas

Similar a Algorithm and pseudo codes(20)

4 coding from algorithms por hccit
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
hccit12K vistas
Algorithms and flow charts por Chinnu Edwin
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu Edwin178 vistas
Improving Code Quality Through Effective Review Process por Dr. Syed Hassan Amin
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
PCCF UNIT 1.pptx por DivyaKS12
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptx
DivyaKS1214 vistas
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx por AbdelrahmanRagab36
Lec 2 -algorithms-flowchart-and-pseudocode1.pptxLec 2 -algorithms-flowchart-and-pseudocode1.pptx
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx
AbdelrahmanRagab3612 vistas
POLITEKNIK MALAYSIA por Aiman Hud
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud47 vistas
Fundamentals of programming with C++ por Seble Nigussie
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
Seble Nigussie244 vistas
265 ge8151 problem solving and python programming - 2 marks with answers por vithyanila
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
vithyanila457 vistas
Algorithm-Introduction ,Characterestics & Control Structures.pdf por MaryJacob24
Algorithm-Introduction ,Characterestics & Control Structures.pdfAlgorithm-Introduction ,Characterestics & Control Structures.pdf
Algorithm-Introduction ,Characterestics & Control Structures.pdf
MaryJacob2461 vistas
Programming Paradigm & Languages por Gaditek
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek396 vistas
Programming Paradigm & Languages por Gaditek
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek3.4K vistas

Más de hermiraguilar

Introduction to programming concepts por
Introduction to programming conceptsIntroduction to programming concepts
Introduction to programming conceptshermiraguilar
2.4K vistas55 diapositivas
Programming process and flowchart por
Programming process and flowchartProgramming process and flowchart
Programming process and flowcharthermiraguilar
9.6K vistas34 diapositivas
Introduction to programming concepts por
Introduction to programming conceptsIntroduction to programming concepts
Introduction to programming conceptshermiraguilar
2.6K vistas55 diapositivas
Engineering drawing (geometric construction) lesson 4 por
Engineering drawing (geometric construction) lesson 4Engineering drawing (geometric construction) lesson 4
Engineering drawing (geometric construction) lesson 4hermiraguilar
77.6K vistas60 diapositivas
Engineering drawing (introduction of engineering drawing) lesson 1 por
Engineering drawing (introduction of engineering drawing) lesson 1Engineering drawing (introduction of engineering drawing) lesson 1
Engineering drawing (introduction of engineering drawing) lesson 1hermiraguilar
25K vistas39 diapositivas
Engineering drawing (engineering lettering) lesson 3 por
Engineering drawing (engineering lettering) lesson 3Engineering drawing (engineering lettering) lesson 3
Engineering drawing (engineering lettering) lesson 3hermiraguilar
137K vistas28 diapositivas

Más de hermiraguilar(7)

Introduction to programming concepts por hermiraguilar
Introduction to programming conceptsIntroduction to programming concepts
Introduction to programming concepts
hermiraguilar2.4K vistas
Programming process and flowchart por hermiraguilar
Programming process and flowchartProgramming process and flowchart
Programming process and flowchart
hermiraguilar9.6K vistas
Introduction to programming concepts por hermiraguilar
Introduction to programming conceptsIntroduction to programming concepts
Introduction to programming concepts
hermiraguilar2.6K vistas
Engineering drawing (geometric construction) lesson 4 por hermiraguilar
Engineering drawing (geometric construction) lesson 4Engineering drawing (geometric construction) lesson 4
Engineering drawing (geometric construction) lesson 4
hermiraguilar77.6K vistas
Engineering drawing (introduction of engineering drawing) lesson 1 por hermiraguilar
Engineering drawing (introduction of engineering drawing) lesson 1Engineering drawing (introduction of engineering drawing) lesson 1
Engineering drawing (introduction of engineering drawing) lesson 1
hermiraguilar25K vistas
Engineering drawing (engineering lettering) lesson 3 por hermiraguilar
Engineering drawing (engineering lettering) lesson 3Engineering drawing (engineering lettering) lesson 3
Engineering drawing (engineering lettering) lesson 3
hermiraguilar137K vistas
Engineering drawing (drafting instruments) lesson 2 por hermiraguilar
Engineering drawing (drafting instruments) lesson 2Engineering drawing (drafting instruments) lesson 2
Engineering drawing (drafting instruments) lesson 2
hermiraguilar35.8K vistas

Último

MemVerge: Gismo (Global IO-free Shared Memory Objects) por
MemVerge: Gismo (Global IO-free Shared Memory Objects)MemVerge: Gismo (Global IO-free Shared Memory Objects)
MemVerge: Gismo (Global IO-free Shared Memory Objects)CXL Forum
112 vistas16 diapositivas
[2023] Putting the R! in R&D.pdf por
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdfEleanor McHugh
38 vistas127 diapositivas
MemVerge: Memory Viewer Software por
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer SoftwareCXL Forum
118 vistas10 diapositivas
The Importance of Cybersecurity for Digital Transformation por
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital TransformationNUS-ISS
25 vistas26 diapositivas
Transcript: The Details of Description Techniques tips and tangents on altern... por
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
119 vistas15 diapositivas
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur por
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
"Thriving Culture in a Product Company — Practical Story", Volodymyr TsukurFwdays
40 vistas31 diapositivas

Último(20)

MemVerge: Gismo (Global IO-free Shared Memory Objects) por CXL Forum
MemVerge: Gismo (Global IO-free Shared Memory Objects)MemVerge: Gismo (Global IO-free Shared Memory Objects)
MemVerge: Gismo (Global IO-free Shared Memory Objects)
CXL Forum112 vistas
[2023] Putting the R! in R&D.pdf por Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 vistas
MemVerge: Memory Viewer Software por CXL Forum
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer Software
CXL Forum118 vistas
The Importance of Cybersecurity for Digital Transformation por NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 vistas
Transcript: The Details of Description Techniques tips and tangents on altern... por BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada119 vistas
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur por Fwdays
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
"Thriving Culture in a Product Company — Practical Story", Volodymyr Tsukur
Fwdays40 vistas
Future of Learning - Khoong Chan Meng por NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS31 vistas
AMD: 4th Generation EPYC CXL Demo por CXL Forum
AMD: 4th Generation EPYC CXL DemoAMD: 4th Generation EPYC CXL Demo
AMD: 4th Generation EPYC CXL Demo
CXL Forum126 vistas
TE Connectivity: Card Edge Interconnects por CXL Forum
TE Connectivity: Card Edge InterconnectsTE Connectivity: Card Edge Interconnects
TE Connectivity: Card Edge Interconnects
CXL Forum96 vistas
Empathic Computing: Delivering the Potential of the Metaverse por Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst449 vistas
JCon Live 2023 - Lice coding some integration problems por Bernd Ruecker
JCon Live 2023 - Lice coding some integration problemsJCon Live 2023 - Lice coding some integration problems
JCon Live 2023 - Lice coding some integration problems
Bernd Ruecker67 vistas
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy por Fwdays
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
"Role of a CTO in software outsourcing company", Yuriy Nakonechnyy
Fwdays40 vistas
Micron CXL product and architecture update por CXL Forum
Micron CXL product and architecture updateMicron CXL product and architecture update
Micron CXL product and architecture update
CXL Forum27 vistas
CXL at OCP por CXL Forum
CXL at OCPCXL at OCP
CXL at OCP
CXL Forum208 vistas
Business Analyst Series 2023 - Week 3 Session 5 por DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10165 vistas
Photowave Presentation Slides - 11.8.23.pptx por CXL Forum
Photowave Presentation Slides - 11.8.23.pptxPhotowave Presentation Slides - 11.8.23.pptx
Photowave Presentation Slides - 11.8.23.pptx
CXL Forum126 vistas
Liqid: Composable CXL Preview por CXL Forum
Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum121 vistas
GigaIO: The March of Composability Onward to Memory with CXL por CXL Forum
GigaIO: The March of Composability Onward to Memory with CXLGigaIO: The March of Composability Onward to Memory with CXL
GigaIO: The March of Composability Onward to Memory with CXL
CXL Forum126 vistas

Algorithm and pseudo codes

  • 1. Prepared By: Mr. Richard R. Basilio BSECE – Dip ICT
  • 3. By wikipedia definition: ▪ an algorithm is a sequence of finite instructions, often used for calculation and data processing. ▪ It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state.
  • 5. First documented algorithm by Euclid (300 B.C.) to compute greatest common divisor (gcd).  Example: gcd(3,21)=3  Condition: 1. Let A and B be integers with A > B 0. 2. If B = 0, then the gcd is A and the algorithm ends. 3. Otherwise, find q and r such that A = qB + r where 0 r < B Note that we have 0 r < B < A and gcd(A,B) = gcd(B,r). Replace A by B, B by r. Go to step 2.
  • 6. Example No. 2:  Find the greatest common divisor of A=40, B=15; using Euclidean algorithm; A = 2B + 10 A = 15 ; B = 10 A = 1B + 5 A = 10 ; B = 5 A = 2B + 0 A=5;B=0 gcd is 5
  • 7. There are three properties of algorithm that must have to consider in solving a certain problem in programming:  Finiteness  Absence of Ambiguity  Sequence Definition  Input and Output Definition  Effectiveness  Scope of Definition
  • 8. Finiteness  The execution of a programmed algorithm must be complete after a finite number of operations have been performed. Otherwise, we cannot claim that the execution produces a solution.
  • 9. Absence of Ambiguity  The representation of every step of an algorithm should have a unique interpretation which also understand by the human.  It is convenient to deal with algorithms presented in notational with sparse detail: ▪ Example: ▪ Pseudo code ▪ Flowcharts
  • 10. Sequence of Definition  The sequence in which the steps of the algorithm are to carried out should be clearly specified.  In algorithmic specifications, the instructions are performed from top to button, unless the instruction themselves otherwise specified.
  • 11. Input and Output Definition  Inputs – are the data items that is presented in the algorithm.  Outputs – are the data items presented to the outside world as the result of the execution of a program based on the algorithm.  An algorithm ought to produce at least one output (otherwise, what use is it?...)
  • 12. Effectiveness  it consists of basic instructions that are realizable. This means that the instructions can be performed by using the given inputs in a finite amount of time.  The instructions of an algorithm may order the computer only to perform tasks that is capable of carrying out.
  • 13. Scope Definition  An algorithm applies to the following: ▪ Specific problem or class of problem ▪ The range of inputs has to be predefined ▪ The range determines the generality of the algorithm.
  • 14. Algorithms can be expressed in many kinds of notation, including:  Natural language  Pseudo Code  Flowcharts  Programming Language
  • 16. “Pseudo” means imitation or false and “code” refers to the instructions written in a programming language.  Pseudocode is another programming analysis tool that is used for planning a program.  Pseudocode is also called Program Design Language (PDL).
  • 17. By wikipedia definition:  Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading.
  • 18. Pseudocode is made up of the following logic structures that have been proved to be sufficient for writing any computer program:  Sequence Logic  Selection Logic  Iteration Logic
  • 19. It is used to perform instructions in a sequence, that is one after another.  Thus, for sequence logic, pseudocode instructions are written in an order in which they are to be performed.  The logic flow of pseudocode is from top to bottom.
  • 21. It is used for making decisions and for selecting the proper path out of two or more alternative paths in program logic.  It is also known as decision logic.  Selection logic is depicted as either an IF...THEN or an IF...THEN...ELSE structure.
  • 24. It is used to produce loops when one or more instructions may be executed several times depending on some of the conditions.  It uses structures called the DO_WHILE, FOR and the REPEAT_UNTIL.
  • 28. 1. Write only one statement per line.  Each statement in your pseudocode should express just one action for the computer.  If the task list is properly drawn, then in most cases each task will correspond to one line of pseudocode.
  • 29. Examples
  • 30. 2. Capitalized initial keyword.  In the example above, READ and WRITE are in caps.  There are just a few keywords we will use: ▪ READ, WRITE, IF, ELSE, ENDIF, WHILE, ENDWHILE, REPEAT, UNTIL
  • 31. 3. Indent to show hierarchy.  We will use a particular indentation pattern in each of the design structures: ▪ SEQUENCE: keep statements that are “stacked” in sequence all starting in the same column. ▪ SELECTION: indent the statements that fall inside the selection structure, but not the keywords that form the selection ▪ LOOPING: indent the statements that fall inside the loop, but not the keywords that form the loop
  • 32. Examples:
  • 33. 4. End multi-line structures. ▫ All the initial keyword must always in line with the last or end of the structure. 5. Keep statement language independent. ▫ Resist the urge to write in whatever language you are most comfortable with. There may be special features available in the language you plan to eventually write the program in; if you are SURE it will be written in that language, then you can use the features. If not, then avoid using the special features.
  • 34. In summary:  Write only one statement per line.  Capitalized initial keyword.  Indent to show hierarchy.  End multi-line structures.  Keep statement language independent.
  • 35. These are follows: ▫ Number each instruction.  This is to enforce the notion, “well-ordered collection of ... operations.” ▫ Each instruction should be unambiguous.  It means the computing agent, in this case the reader, should be capable of carrying out the instructions. And also, each instruction should be effectively computable (do-able). ▫ Completeness.  Nothing should be left out.
  • 36. Following are some of the advantages of using pseudocode:  Converting a pseudocode to a programming language is much more easier than converting a flowchart.  As compared to flowchart, it is easier to modify a pseudocode of a program logic when program modifications are necessary.
  • 37. It also suffers from some of the limitations. These limitations are as follows:  In the cases of pseudocode, a graphic representation of program logic is not available.  There are no standard rules to follow for using a pseudocode. Different programmers use their own style of writing pseudocode and hence, communication problem occurs due to lack of standardization.
  • 38. To symbolize the arithmetic operators we use these symbols:  Note: There is a precedence or hierarchy implied in this symbols.
  • 39. When we have to make a choice between actions, we almost always base that choice on a test.  There is a universally accepted set of symbols used to represent these phrases:
  • 43.  It is more difficult to follow the logic of or write pseudocode as compared to flowcharting.
  • 44. Prepare ½ crosswise yellow paper for seatwork after the discussion.