Docsity

Problem Solving & Python Programming: Algorithms, Flowcharts, and Pseudocode, Study notes of Computer Science

Partial preview of the text

Download Problem Solving & Python Programming: Algorithms, Flowcharts, and Pseudocode and more Study notes Computer Science in PDF only on Docsity!

Chapter: Problem Solving and Python Programming : Algorithmic

Problem Solving

Notation

NOTATIONS

FLOW CHART

Flow chart is defined as graphical representation of the logic for problem solving. The purpose of flowchart is making the logic of the program clear in a visual representation.

Rules for drawing a flowchart

  1. The flowchart should be clear, neat and easy to follow.
  2. The flowchart must have a logical start and finish.
  3. Only one flow line should come out from a process symbol.
  4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave the decision symbol.
  5. Only one flow line is used with a terminal symbol.
  6. Within standard symbols, write briefly and precisely.
  7. Intersection of flow lines should be avoided.

Advantages of flowchart:

  1. Communication: - Flowcharts are better way of communicating the logic of a system to all concerned.

 It is easier to understand for the programmer or non programmer to understand the general working of the program, because it is not based on any programming language.  It gives us the sketch of the program before actual coding.  It is not a machine readable  Pseudo code can’t be compiled and executed.  There is no standard syntax for pseudo code. 

Guidelines for writing pseudo code:

 Write one statement per line  Capitalize initial keyword  Indent to hierarchy  End multiline structure  Keep statements language independent

Common keywords used in pseudocode

The following gives common keywords used in pseudocodes.

  1. //: This keyword used to represent a comment.
  2. BEGIN,END: Begin is the first statement and end is the last statement.
  3. INPUT, GET, READ : The keyword is used to inputting data.
  4. COMPUTE, CALCULATE : used for calculation of the result of the given expression. 5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
  1. OUTPUT, PRINT, DISPLAY : It is used to display the output of the program.
  2. IF, ELSE, ENDIF : used to make decision.
  3. WHILE, ENDWHILE : used for iterative statements.
  4. FOR, ENDFOR : Another iterative incremented/decremented tested automatically.

Syntax for if else:

IF (condition)THEN statement ... ELSE statement ... ENDIF Example: Greates of two numbers BEGIN READ a,b IF (a>b) THEN DISPLAY a is greater ELSE DISPLAY b is greater END IF END

INITIALIZE i= WHILE(i<=n) DO PRINT i i=i+ ENDWHILE END

Advantages:

 Pseudo is independent of any language; it can be used by most programmers.  It is easy to translate pseudo code into a programming language.  It can be easily modified as compared to flowchart.  Converting a pseudo code to programming language is very easy as comparedwith converting a flowchart to programming language.

Disadvantages:

 It does not provide visual representation of the program’s logic.  There are no accepted standards for writing pseudo codes.  It cannot be compiled nor executed.  For a beginner, It is more difficult to follow the logic or write pseudo code ascompared to flowchart. Example:

Addition of two numbers: BEGIN GET a,b ADD c=a+b PRINT c END