Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Problem Solving and Python Programming, Study notes of Computer Science

Problem-solving is the process of identifying a problem, creating an algorithm to solve the given problem, and finally implementing the algorithm to develop a computer program. An algorithm is a process or set of rules to be followed while performing calculations or other problem-solving operations.

Typology: Study notes

2021/2022

Available from 09/28/2022

aswathy-s-nair
aswathy-s-nair 🇮🇳

5 documents

Partial preview of the text

Download Problem Solving and Python Programming 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.
  1. Effective analysis: - With the help of flowchart, problem can be analyzed in more effective way.
  2. Proper documentation: - Program flowcharts serve as a good program documentation, which is needed for various purposes.
  3. Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and program development phase.
  4. Proper Debugging: - The flowchart helps in debugging process.
  5. Efficient Program Maintenance: - The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.

Disadvantages of flow chart:

  1. Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy.
  2. Alterations and Modifications: - If alterations are required the flowchart may require re-drawing completely.
  3. Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.
  4. Cost: F or large application the time and cost of flowchart drawing becomes costly.

PSEUDO CODE:

 Pseudo code consists of short, readable and formally styled English languages used for explain an algorithm.  It does not include details like variable declaration, subroutines.

 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

Syntax for For:

FOR( start-value to end-value) DO statement ... ENDFOR Example: Print n natural numbers BEGIN GET n INITIALIZE i= FOR (i<=n) DO PRINT i i=i+ ENDFOR END

Syntax for While:

WHILE (condition) DO statement ... ENDWHILE Example: Print n natural numbers BEGIN GET n

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