0% found this document useful (0 votes)
16 views9 pages

Chapter 1 What Is An Algorithm

An algorithm is a step-by-step procedure for solving a problem, characterized by being finite, definite, and effective, with inputs and outputs. Flowcharts visually represent algorithms using symbols to illustrate processes, decisions, and the flow of control. The document provides examples of algorithms and flowcharts for tasks like adding numbers and finding the largest of two numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

Chapter 1 What Is An Algorithm

An algorithm is a step-by-step procedure for solving a problem, characterized by being finite, definite, and effective, with inputs and outputs. Flowcharts visually represent algorithms using symbols to illustrate processes, decisions, and the flow of control. The document provides examples of algorithms and flowcharts for tasks like adding numbers and finding the largest of two numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

What is an Algorithm?

An algorithm is a step-by-step procedure or set of


instructions to solve a problem or perform a task.

In simple words, it’s like a recipe that tells you what to do, step
by step, until the task is complete.

Characteristics of an Algorithm
1.​Finite – Must end after a limited number of steps.​

2.​Definite – Each step must be clear and unambiguous.​

3.​Input – Takes zero or more inputs.​

4.​Output – Produces at least one output.​

5.​Effective – Steps must be basic enough to be carried out.​


Steps in Writing an Algorithm
1.​Understand the problem​

2.​Decide inputs and outputs​

3.​Break the problem into small steps​

4.​Write the steps in order​

5.​Check correctness​

Example 1: Algorithm to Add Two Numbers


Problem: Write an algorithm to add two numbers and display the
result.

Algorithm:

1.​Start
2.​Input two numbers A and B
3.​Add A and B, store in SUM
4.​Print SUM
5.​End​
Example 2: Algorithm to Find the Largest of Two
Numbers
Problem: Given two numbers, find which is larger.

Algorithm:

1.​Start​

2.​Input two numbers A and B​

3.​If A > B, then​


→ Print “A is larger”​
Else​
→ Print “B is larger”​

4.​End​

Example 3: Algorithm for Factorial of a Number (n!)

Problem: Find factorial of a given number n.

Algorithm:

1.​Start​

2.​Input number n​

3.​Set FACT = 1​
4.​Repeat steps 5 and 6 while n > 0​

5.​FACT = FACT × n​

6.​Decrease n by 1​

7.​Print FACT​

8.​End

Flowchart in Detail
A flowchart is a diagram that represents a process, system, or algorithm using symbols,
shapes, and arrows to show the flow of control or steps.

It is widely used in programming, problem-solving, business processes, and system design


because it makes ideas visual and easy to understand.

Basic Flowchart Symbols


1.​ Oval (Terminator) → Used for Start and End​
Example: "Start", "End"​

2.​ Rectangle (Process) → Shows a process or action step​


Example: ▭ "Calculate total", "Read input"​

3.​ Diamond (Decision) → Used for yes/no or true/false decisions​


Example: ◇ "Is X > Y?"​

4.​ Parallelogram (Input/Output) → Represents input (from user) or output (display


result)​
Example: ⧍ "Enter number", "Print result"​
5.​ Arrow → Shows the flow of control (which step comes next)​

Steps in Creating a Flowchart


1.​ Define the problem (What process are you representing?)​

2.​ Identify the steps (What actions/decisions happen?)​

3.​ Arrange them in sequence​

4.​ Use symbols (start, process, decision, input/output)​

5.​ Connect with arrows​


6.​ Check logic flow (Does it cover all cases?)​

Example 1: Flowchart for Finding the Largest of Two


Numbers
Problem: Compare two numbers and print which is larger.

Steps:

1.​ Start​

2.​ Input number A and B​

3.​ Check: Is A > B?​

○​ If YES → Print "A is larger"​

○​ If NO → Print "B is larger"​


4.​ End​

Flowchart (Text version):


[Start]
|
v
[Input A,B]
|
v
[Is A > B?]---Yes---> [Print "A is larger"]
|
No
v
[Print "B is larger"]
|
v
[End]
Example 2: Flowchart for Simple Calculator (Add Two
Numbers)
Steps:

1.​ Start​

2.​ Input two numbers​

3.​ Add them​

4.​ Display result​

5.​ End​
Flowchart (Text version):
[Start]
|
v
[Input A, B]
|
v
[Sum = A + B]
|
v
[Print Sum]
|
v
[End]

You might also like