Algorithms and Flowcharts
Algorithms and Flowcharts
Computer Program
Set of instructions To design a program we need Instructions Order Data
Ex:
A, B C=A+B C
Algorithm
Finite sequence of explicit instructions, when provided with a set of inputs, produces an output and then terminates Finite number of steps Ex: Find the area of a rectangle. Step 1: Start Step 2: Input the length (l) and breadth (b) of the rectangle. Step 3: Find the area of the rectangle using the formula. Area l*b Step 4: Print the area of the rectangle. Step 5: Stop.
Algorithm
Characteristics of Algorithm Precise and unambiguous No infinite repetition Ensure termination Finite number of steps in sequence Normal English Qualities of good algorithm Time Memory Accuracy Sequence Generability
Flowchart
Pictorial representation of an algorithm in which the steps are drawn in the form of different shapes of boxes and the logical flow is indicated by interconnecting arrows Boxes operations Arrows sequence
Flowchart symbols
flow lines Terminal Input/Output Processing
Decision
Connector
Off-page Connector
Document
Annotation
Manual input
Manual operation
Online storage
Disk
Summing Junction
Flowchart
Benefits of flowchart Makes logic clear Communication Effective analysis Useful in coding Proper testing and debugging Appropriate documentation Limitations of flowchart Complex Costly Difficult to modify No update
Pseudocode
PDL (Program Design Language) Uses plain English statements to represent the processes of computer program. Input: READ, OBTAIN, GET, PROMPT Output: PRINT, DISPLAY, SHOW Compute: COMPUTE, CALCULATE, DETERMINE Initialise: SET, INITIALISE Add one: INCREMENT
Pseudocode
Benefits of Pseudocode language independent easier to develop easy to translate compact Limitations of Pseudocode does not provide visual representation no accepted standards no syntax rules
Print Z Action N
Stop
No Action 2 Action 1
If A > B
Output B
Output A
Stop
Count=0
Yes true
If count<10 No Stop
PROGRAMMING PARADIGMS
Programming paradigm refers to how a program is written in order to solve a problem. Programming can be classified into three categories: Unstructured Programming Structural Programming Object-Oriented Programming
Unstructured Programming
Unstructured style of programming refers to writing small and simple programs consisting of only one main program. All the actions such as inputs, outputs, and processing are done within one program only.
Structural Programming
Using structural programming, a program is broken down into small independent tasks that are small enough to be understood easily, without having to understand the whole program at once. Each task has its own functionality and performs a specific part of the actual processing. These tasks are developed independently, and each task can carry out the specified task on its own, without the help of any other task. When these tasks are completed, they are combined together to solve the problem
Object-Oriented Programming
Object-oriented programming is a style of computer programming, which promotes building of independent pieces of code that interact with each other. It allows pieces of programming code to be reused and interchanged between programs.
Programming Languages
Has to follow syntax rules to create an accurate program so that the computer can yield desired results. Rules are very rigid Types of programming languages Machine language Assembly language High level language
Assembler Source code (assembly language) to object code Variables are symbolic names Translates mnemonic codes to m/c code and register addresses to system addresses Checks syntax, assembles into main memory and provides linking facility