You are on page 1of 21

Contents

• Algorithm
• flowchart
Goals
By the end of this lecture you should …
• Understand the role of a computer as a tool in Computer
Science.
• Understand the study of algorithms.
• Be able to identify how algorithms are developed &
evaluated.
• Flowcharts
What is Computer Science?

• NOT about coding or hardware or software!


• Computer Science is about Problem Solving
• Computer Science is about Developing Algorithms to solve
complex problems
What is an Algorithm?

• An algorithm is a well-developed, organized approach to


solving a complex problem.
• It refers to the logic of the program .
• It is a step by step solution to a given problem
Characteristics of Algorithm:
• Each instruction should be precise and clear.
• Each instruction should be executed in a finite time.
• One or more instructions should not be repeated Infinitely.
• After executing the instructions the desired result are
obtained.
• It range from Simple to the Complex.
Now Create an Algorithm!!
• Problem: Dad said you to buy books from a shop 10km from
your house.
• Step 1: Get The Name Of Book
• Step2: Get Money From Dad
• Step 3: Get The Address Of The Shop
• Step4: Take Bus To Shop
• Step 5: Search For The Book In Shop
• Step 6: Buy The Book From Shopkeeper
• Step 7: Come Back To Home
Developing an Algorithm
1. Identify inputs to the system.
2. Identify output of the system.
3. Identify the process.
4. Break the solution to steps.
1. Identify the Inputs
• What data do I need?
• How will I get the data?
• In what format will the data be?
2. Identify the Outputs
• What outputs do I need to return to the user?
• What format should the outputs take?
3. Identify the Processes
• How can I manipulate data to produce meaningful results?
• Data vs. Information
4. Break the Solution to steps.

By breaking the solution to the steps we can easily understand


the logic of program.
Example 1
Algorithm to find the sum of two numbers:
• step 1 : start
• step 2 : input number A=5 and B=10
• Step 3: do sum=A+B
• Step 4: print the “sum” value
• step 5 : stop
Example 2
Algorithm to find out a number is odd or even:
• step 1 : start
• step 2 : input number
• step 3 : rem=number mod 2
• step 4 : if rem=0 then
               print "number even"
           else
             print "number odd"
        endif
• step 5 : stop
Flowchart
• A Flowchart is a pictorial or graphical representation of an
algorithm.
• The First flowchart is made by John Von Newman in 1945.
• It is a symbolic diagram of operation sequence, dataflow,
control flow and processing logic in information processing.
• The symbol used are simple and easy to learn.
• It is a very helpful tool for programmers and beginners.
Purpose of flowchart:
• Provide Communication.
• Provide an overview.
• Show all elements and its relationship.
• Quick method of showing program flow.
• Check program logic.
• Facilitate coding.
• Provide program revision.
• Provide Program documentation.
Advantages of flowchart:
• Communication.
• Effective analysis.
• Proper documentation.
• Efficient coding.
• Proper debugging.
• Efficient program maintenance.
• Easy and clear presentation.
Limitation of flowchart:
• Complex logic.
• Drawing is time consuming.
• Alteration and modification.
• Redrawn many times.
• Difficult to draw and remember.
• Reproduction ( replica ).
• Technical detail.
FLOW CHART SYMBOLS
Name Symbol Use in Flowchart

Oval Denotes the beginning or end of the program

Parallelogram Denotes an input operation /output operations

Rectangle Denotes a process to be carried out


e.g. addition, subtraction, division etc.

Diamond Denotes a decision (or branch) to be made.


The program should continue along one of
two routes. (e.g. IF/THEN/ELSE)

Hybrid Denotes an output operation

Flow line Denotes the direction of logic flow in the program


Example1
Flowchart showing sum of two numbers:

START

INPUT VALUE OF A
and B

SUM=A+B

PRINT :SUM

STOP
Example2
Flowchart showing sum of two numbers:
The End

You might also like