0% found this document useful (0 votes)
2 views

Algorithm 1

An algorithm is a formal sequence of instructions for a computer to solve a problem, requiring clear and precise directions. The process involves a user, a computer, and a programmer, with characteristics such as finiteness, precision, and unambiguity being essential for effective algorithms. The document also discusses the input-process-output model and provides examples of automating tasks through algorithms.

Uploaded by

9db7m95yxv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Algorithm 1

An algorithm is a formal sequence of instructions for a computer to solve a problem, requiring clear and precise directions. The process involves a user, a computer, and a programmer, with characteristics such as finiteness, precision, and unambiguity being essential for effective algorithms. The document also discusses the input-process-output model and provides examples of automating tasks through algorithms.

Uploaded by

9db7m95yxv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Created by Turbolearn AI

Understanding Algorithms
An algorithm is a formal sequence of instructions given to a computer to solve a
problem.

An algorithm is a set of instructions that solves a problem.

The Computer as a "Dumb Machine"


The computer is referred to as a "dumb machine" because it follows instructions
literally and without understanding. Think of a computer like a three-year-old child
who can follow instructions but needs very clear and specific directions.

The Algorithm Process ‍


The algorithm process involves three key players:

1. User: The person who wants the problem solved.


2. Computer: The "dumb machine" that executes the instructions.
3. Programmer: The "smart person" who writes the instructions algorithm for the
computer.

The user interacts with the computer, but the programmer is responsible for
providing the computer with a clear set of instructions.

Analogy: Serving at a Restaurant


Imagine you're telling a child how to serve people at a restaurant:

You theprogrammer give very specific instructions to the child thecomputer.


For example: "Take this bowl with this and carry it to table number seven, put it
on top of the table, and then come back."

The goal is to make the instructions so clear that the "dumb machine" thechild
cannot make a mistake.

Characteristics of a Good Algorithm

Page 1
Created by Turbolearn AI

For an algorithm to make sense to the "dumb machine," it must have the following
characteristics:

Characteristic Description Example

Instead of saying "go to the...",


Finite The steps must have an end.
specify "go to table number 7".
The steps must be exact and
Instead of saying "go to the table,"
Precise clearly state what needs to be
say "go to table number 17".
done.
No unnecessary information
"Go to table 17 and put the plate
Unambiguous should be missing, ensuring there
on the table" clearandspecif ic.
is no room for misinterpretation.
First, "get the food," then "go to the
The instructions must flow in a
Flow table," and finally, "put it on the
logical order.
table."
The steps must terminate After putting the plate on the table,
Termination somewhere, meaning there must the final instruction should be
be an end. "come back here".
The algorithm must have an After following the instructions, the
output or something that proves customer at table 17 should
Output there was an effect after receive their plate with food. This
following the series of steps in shows there was an output from
the algorithm. the algorithm.

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.

When writing an algorithm, remember you are giving instructions to a computer,


which requires you to think in terms of:

Input: What data is provided.


Process: What operations are performed on the data.
Output: What result is produced.

Page 2
Created by Turbolearn AI

IPO I nput, P rocess, Output


The input-process-output I P O model is used to conceptualize how a computer
program works.

1. Input: The input could be data from a keyboard, such as numbers to be added.

Example: The numbers two and two.

2. Process: The process is the operation that needs to be performed on the input.

Example: Addition of the two numbers.

3. Output: The output is the result of the process.

Example: The sum of two and two, which is four.

Computers fundamentally perform mathematical calculations using binary numbers


onesandzeros. All data, including colorful displays, DLSS, gaming visuals, emojis, and

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.

Program Design and Problem Definition


When designing a program, you need to:

1. Define the Problem: Clearly state what the program needs to do.

Example: Find the sum of three numbers.

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

Input: What do you need to put into the system?


Process: What steps do you need to take to achieve the desired outcome?
Output: What do you want to get out of the system?

Defining the Problem Using IPO


Consider the problem of finding the sum of three numbers, a, b, and c.

Instead of manually calculating the sum of specific numbers like 3, 9, and 6


every time, we create a program that allows the user to input any three
numbers, and the computer will calculate the sum.
This way, the user can ask the computer for the sum of different sets of
numbers without needing constant assistance.

Automating Processes with Algorithms


The main goal in programming is to automate processes. Instead of manually
performing tasks, we write programs with algorithms, which are sets of instructions,
to automate them.

Finding the Sum of Three Numbers


To find the sum of any three numbers using a computer, you need to instruct the
computer how to do it.

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

The basis of algorithms is understanding:

1. Input: What is going in.


2. Process: What process you're trying to do.
3. Output: What you expect to get out.

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

The computer calculates 2 + 4 + 8 = 14 and outputs 14.

Solving Problems with Programs


Every program aims to solve a problem that humans can't or don't want to solve
manually. You instruct the computer to do the processing. The user provides the input
and receives the output.

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.

Calculating Price with VAT and Discount


Here's an example of calculating the price of something with Value Added Tax V AT
and a discount:

Page 5
Created by Turbolearn AI

1. Input Price: The user inputs the price of an item.


2. Calculate VAT: Multiply the price by the VAT rate e. g. , 12.5.
V AT = 0.125 ∗ P rice

3. Calculate Total: Add the price to the VAT, then subtract the discount.
T otal = P rice + V AT − Discount

4. Output Total: Output the total to the user.

This process is similar to what happens in a restaurant or with a calculator app.

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

Finding the Average of Two Numbers


To find the average of two numbers, we define the input, process, and output.

Input: Two numbers, a and b.

Process: The average is calculated as:


a+b
average =
2

Output: The calculated average.

Finding the Average Time Through Traffic


To find the average time it takes to get through traffic with four obstacles, we again
define the input, process, and output.

Page 6
Created by Turbolearn AI

Input: Times for four obstacles: Obstacle 1, Obstacle 2, Obstacle 3, and


Obstacle 4.

Process: The average time is calculated as:


Obstacle1+Obstacle2+Obstacle3+Obstacle4
average =
4

Output: The calculated average.

Calculating the Area of a Square


To calculate the area of a square given any length and width:

Input: Length $l$ and Width $w$.

Process: The area $a$ is calculated as:

a = l ⋅ w

Output: The calculated area.

Representing Algorithms N extSteps


Next, we'll cover methods of representing algorithms:

Narrative
Pseudocode
Flowcharts
Code
Trace Tables

Page 7

You might also like