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

2022-Algorithms Lecture 5

The document discusses algorithm development for problem solving, defining an algorithm as a set of unambiguous logical steps to solve a specific problem. It provides examples of real-life algorithms and properties of efficient algorithms, then demonstrates algorithms for calculating the average of numbers, simple interest, the area of a triangle, and the perimeter and area of a rectangle.

Uploaded by

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

2022-Algorithms Lecture 5

The document discusses algorithm development for problem solving, defining an algorithm as a set of unambiguous logical steps to solve a specific problem. It provides examples of real-life algorithms and properties of efficient algorithms, then demonstrates algorithms for calculating the average of numbers, simple interest, the area of a triangle, and the perimeter and area of a rectangle.

Uploaded by

Carine Morcos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Socio-Computing Department

Faculty of Economics and Political Science


Cairo University

Computer Applications in Modern


Information Societies (2)
Part 2: Problem Solving Tools

Dr Ghada Deghedi

Lecture 5 2022-2023

1
Introduction
• In problem solving, algorithm development and coding we
tend to view problems at different levels of abstraction

2
Introduction
• In Part 1, we illustrated the working of problem
solving from a general perspective.
• In computing, we focus on the type of problems
categorically known as algorithmic problems,
where their solutions are expressible in the form
of well-defined procedure consisting of a set of
instructions, that takes some value or set of
values, as input, and produces some value or set
of values, as output.
Heuristic solutions: require reasoning built on knowledge and experience, and
a process of trial and error. (not guaranteed to be optimal put satisfactory)
3
Introduction
• A cooker, for instance, follows a procedure commonly known
as a recipe that converts the ingredients (input) into some
culinary dish (output), after a certain number of steps.

Inputs Procedure Output

4
Introduction
• An algorithm, is a form that embeds the complete
logic of the solution. Its formal written version is
called a computer program, or code.
• Thus, algorithmic problem solving actually
comes in two phases:
Derivation of an algorithm that solves the
problem

Conversion of the algorithm into code

5
Introduction
• Computer programming can be divided into
three distinct areas of activity:
• 1. Problem definition and problem solving
• 2. Creating a structured solution (or algorithm)
• 3. Coding (e.g. Java, Python, C++)

6
• Has no intelligence or thinking power.
• The Intelligence Quotient (I.Q) of a computer is zero.
• A computer performs many tasks exactly in the same manner as it is
told to do.
• People are better than computers at developing heuristic solutions.
• Computers are built to deal with algorithmic solutions, which are
often difficult or very time consuming for humans.
• The field of computers that deals with heuristic types of problems is
7
called artificial intelligence.
Introduction
• In order to instruct a computer program
correctly, the user must have clear
understanding of the problem to be solved.
Apart from this he should be able to develop a
method, in the form of series of sequential
steps, to solve it.
• Once the problem is well-defined and a
method of solving it is developed, then
instructing the computer to solve the problem
becomes relatively easier task.
8
Algorithms
• The word algorithm comes from the name of a
mathematician Abu Ja’far Mohammed ibn-i
Musa al Khowarizmi.

9
Algorithms: Real Life Examples
◼ Many Real-Life Examples
 Cooking: Recipe for preparing a dish
 Origami: The Art of Paper Folding
 Directions: How to go to Cairo Airport

 Example: how do you make a cup of tea?

1. Boil kettle
2. Put tea in cup
3. Pour boiling water
into cup

10
Informal definition of an algorithm
Computer Algorithms
A set of sequential steps usually written in Ordinary Language to
solve a given problem is called Algorithm. It is used for
obtaining a required output for any legitimate input in a finite
amount of time.

problem

algorithm

input “computer” output

12
Algorithm Definition
• An algorithm can be defined as “a complete,
unambiguous, finite number of logical steps
for solving a specific problem “

Unambiguous No room for subjective


interpretation

13
Algorithms
• It may be possible to solve to problem in more than
one way, resulting in more than one algorithm.
• The choice of various algorithms depends on the
factors like reliability, accuracy and easy to modify.
• The most important factor in the choice of algorithm
is the time requirement to execute it, after writing
code in High-level language with the help of a
computer. The algorithm which will need the least
time when executed is considered the best.

14
Steps involved in algorithm development
• Step1: Identification of input: For an algorithm, there are
quantities to be supplied called input and these are fed
externally. The input is to be identified first for any specified
problem.
• Step2: Identification of output: From an algorithm, at least
one quantity is produced, called for any specified problem.
• Step3: Identification the processing operations: All the
calculations to be performed in order to lead to output from the
input are to be identified in an orderly manner.

15
Properties of an efficient algorithm

16
Properties of an efficient algorithm
• Finiteness: An algorithm must terminate in a finite number of steps
• Definiteness: Each step of the algorithm must be clear and unambiguous.
• Effectiveness: Each step must be effective, in the sense that it should be
primitive easily convertible into program statement , can be performed
exactly in a finite amount of time.(steps must be doable).
• Input/output: Each algorithm must take zero, one or more quantities as
input data and produce one or more output values.
• Generality: The algorithm must be complete in itself so that it can be used
to solve problems of a specific type for any input data.

17
Three constructs
Example 1
Find the average of three numbers

• Step 1: Read the numbers a, b, c


• Step 2: Compute the sum of a, b and c
• Step 3: Divide the sum by 3
• Step 4: Store the result in variable d
• Step 5: Print the value of d
• Step 6: End
19
Example 2
Write an algorithm to calculate the simple interest using
the formula. Simple interest = P*N* R/100
Where P is principle Amount, N is the number of years and R is the
rate of interest.

• Step 1: Read the three input quantities’ P, N


and R.
• Step 2: Calculate simple interest as Simple
interest = P* N* R/100
• Step 3: Print simple interest.
• Step 4: End

20
Example 3
Write an algorithm to find the area of the
triangle. Let b, c be the sides of the triangle ABC and A
the included angle between the given sides.

• Step 1: Input the given


elements of the triangle
namely sides b, c and angle
between the sides A.
• Step 2: Area = (1/2) *b*C*
sin A
• Step 3: Output the Area
• Step 4: End
21
Example 4
Write an algorithm to calculate the perimeter and
area of rectangle. Given its length and width.
• Step 1: Read length of the rectangle.
• Step 2: Read width of the rectangle.
• Step 3: Calculate perimeter of the rectangle using
the formula perimeter = 2 * (length + width)
• Step 4: Calculate area of the rectangle using the
formula area = length*width.
• Step 5: Print perimeter.
• Step 6: Print area.
• Step 7: End 22

You might also like