Algorithm 1
Algorithm 1
Understanding Algorithms
An algorithm is a formal sequence of instructions given to a computer to solve a
problem.
The user interacts with the computer, but the programmer is responsible for
providing the computer with a clear set of instructions.
The goal is to make the instructions so clear that the "dumb machine" thechild
cannot make a mistake.
Page 1
Created by Turbolearn AI
For an algorithm to make sense to the "dumb machine," it must have the following
characteristics:
Algorithms
Defining Algorithms
An algorithm is a list of instructions that are clear, finite, precise,
unambiguous, and have a proper flow that terminates with an output.
Page 2
Created by Turbolearn AI
1. Input: The input could be data from a keyboard, such as numbers to be added.
2. Process: The process is the operation that needs to be performed on the input.
filters, are translated into numbers represented as ones and zeros. We convert these
grouped numbers into inputs, send them to the processor, and the processor
performs mathematical operations to produce an output that is displayed on the
screen.
1. Define the Problem: Clearly state what the program needs to do.
When instructing a computer, instructions must be very clear to avoid any mistakes.
Defining Diagram I P O
A defining diagram, based on the IPO model, helps in figuring out how a program
will work. It determines what input is needed, the process to be performed, and the
output that will be generated.
Page 3
Created by Turbolearn AI
1. Create Boxes: Create boxes variables to hold the numbers. Let's call them a, b,
and c.
2. Input: Ask the user to input numbers into boxes a, b, and c.
The user provides the numbers, not the programmer.
For example, the user might input 3 into 'a', 9 into 'b', and 6 into 'c'.
3. Processing: Tell the computer how to process the numbers.
Instruct the computer to look inside boxes a, b, and c and add the
numbers.
The computer performs the math: 3 + 9 + 6 = 18.
4. Output: Tell the computer to output the result.
Store the result in another box, 'd'.
Instruct the computer to output the value in box 'd'.
Algorithm Basis
Page 4
Created by Turbolearn AI
You provide the computer with instructions on how to do it. The user provides the
input.
For instance, if the user inputs 2, 4, and 8, the computer follows your instructions:
1. a = 2
2. b = 4
3. c = 8
Real-Life Application
When you give the computer a set of instructions, it could be a program for almost
anything, like applying a filter to a picture. Once you figure out the process and give
the computer a list of things to do, it will follow your instructions to the best of its
ability.
Page 5
Created by Turbolearn AI
3. Calculate Total: Add the price to the VAT, then subtract the discount.
T otal = P rice + V AT − Discount
Defining Diagram
This is the basic foundation of everything. If you know about variables and constants,
that's good, but we'll get to that later.
Every program that was ever written is aimed at getting the computer to
do the processing part of a task. The user puts in the input and the user
gets the output, but the instructions, the whole set of instructions are
done by you theprogrammer.
Defining Diagrams
Page 6
Created by Turbolearn AI
a = l ⋅ w
Narrative
Pseudocode
Flowcharts
Code
Trace Tables
Page 7