Algorithms and how to write an algorithms

AhmedNobi95 363 views 20 slides Feb 22, 2019
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

This slide is about how to write algorithms, how to start to write as a beginner.


Slide Content

P.S:
It is always said any important presentation should start with black background. I don’t know why but we
do as it is said
Presented By: Ahmed Nobi ;

Ahmed nobi
-Android developer with one year experience
-Android Developer at Cleodev software House.
-programming instructor with three year experience in Luxor and Aswan.
-working on online course (programming school)
-former chair IEEE Aswan SB
-Ex Vice Student representative IEEE Egypt Section
contact me:
LinkedIn: www.linkedin.com/in/ahmed-nobi
Facebook: www.facebook.com/Ahmed.Nobi.Eltwins
mail: [email protected]
Co –instructor: Abdelrahman Ashraf
knowledge
Visual basic , c++, fortran, html , Photoshop, Adobe premier
Skills
Problem solving , video editor .
contact me:
Facebook:www.facebook.com/abdul.rhman.3720
Brief about me

You ask now how to start to code ?!
Before coding, we should start with algorithms.
What is the algorithms?!

Algorithms
•Analgorithmis a set of instructions designed to perform
a specific task
The algorithm may include instructions for how to:
•start
•accept information
•display information
•transformations
•how to select decisions
•how to repeat sub-tasks
•when to terminate

How can I write an algorithm ?
•The development of an algorithm (a plan) is a key step in solving a problem. Once we have
an algorithm, we can translate it into a computer program in some programming
language. Our algorithm development process consists of five major steps.
• Step 1: Obtain a description of the problem.
• Step 2: Analyze the problem.
• Step 3: Develop a high-level algorithm.
• Step 4: Refine the algorithm by adding more detail.
• Step 5: Review the algorithm.

A scope in details
1-Obtain a description of the problem.
This step is much more difficult than it appears. In the following discussion, the
wordclientrefers to someone who wants to find a solution to a problem, and the
worddeveloperrefers to someone who finds a way to solve the problem. The developer must
create an algorithm that will solve the client's problem.
2-Analyze the problem.
The purpose of this step is to determine both the starting and ending points for solving the
problem
When determining the starting point, we should start by seeking answers to the following
questions:
-What data are available?
-Where is that data?
-What formulas pertain to the problem?
-What rules exist for working with the data?
-What relationships exist among the data values?

When determining the ending point, we need to describe the characteristics of a solution. In other words, how will we know when
we're done? Asking the following questions often helps to determine the ending point.
-What new facts will we have?
-what items will have changed?
-What changes will have been made to those items?
-What things will no longer exist?
3-Develop a high-level algorithm.
An algorithm is a plan for solving a problem, but plans come in several levels of detail. It's usually better to start with ahigh-level
algorithm that includes the major part of a solution, but leaves the details until later.
4-Refine the algorithm by adding more detail.
A high-level algorithm shows the major steps that need to be followed to solve a problem. Now we need to add details to these steps,
but how much detail should we add? Unfortunately, the answer to this question depends on the situation.
5-Review the algorithm.
The final step is to review the algorithm

Let us do an activity
1.A Jeroostarts at (0, 0) facing East with no flowers in its pouch. There is a flower
at location (3, 0). Write a program that directs the Jerooto pick the flower and
plant it at location (3, 2). After planting the flower, the Jerooshould hop one
space East and stop. There are no other nets, flowers, or Jerooson the island.

Analysis of the Problem (Step 2)
1.The flower is exactly three spaces ahead of the jeroo.
2.The flower is to be planted exactly two spaces South of its current location.
3.The Jeroois to finish facing East one space East of the planted flower.
4.There are no nets to worry about.
High-level Algorithm (Step 3)
Let's name the JerooBobby. Bobby should do the following:
Get the flower
Put the flower
Hop East
Detailed Algorithm (Step 4)
Let's name the JerooBobby. Bobby should do the following:
Get the flower
Hop 3 times
Pick the flower
Put the flower
Turn right Hop 2 times Plant a flower
Hop East
Turn left Hop once
Review the Algorithm (Step 5)
1.The high-level algorithm partitioned the problem into three rather easy sub problems. This seems like a good
technique.
2.This algorithm solves a very specific problem because the Jerooand the flower are in very specific locations.
3.This algorithm is actually a solution to a slightly more general problem in which the Jeroostarts anywhere,
4.and the flower is 3 spaces directly ahead of the Jeroo.

2-Write an algorithm of summing two numbers. Get the values from user and display the result
-Analyze the problem (step 2)
1-Sum two numbers
2-there are no values to sum
3-giving summation’s value
High level algorithm (step 3)
1-define the variables
2-determine the expression
3-get numerical values to sum
4-get the final value
5-display the value
Detailed algorithm(step 4)
1-Define 3 variables
2 variables to sum and one for final
result: x, y and z respectively
2-determine the expression
z = x+ y
3-get numerical values to sum
Read from user 2 numerical values
4-Get the final value
z = x+ y
5-display the Value Display z
Review the algorithm (step 5)
compensate by value in
the expression

The per. solution is an ideal which we can use in the huge problems (program) so we can
simplify to that one:
Another solution:
1.define 3 variables x, y and z.
2.Determine the expression : z = x + y
3.Read x and y
4.Carrying out the expression
5.Display z
More Simple
•Define x, y,z
•Read | input x,y
•Z= x+y
•Display z
•end

start
accept information
display information
transformations
how to select decisions
how to repeat sub-tasks
when to terminate
What is next ?
So how to take Decision in Algorithms
Per example
Z= x+y

how to select decisions
So if you need to take decision, you must use “if “
So if you need to design an algorithm that tell you the given number is
positive or negative
After we analyze the problem
Solution :
Start
Define x ;
Read x
If (x>0)
Display “positive”
Else
Display “Negative”
end

how to select decisions
So if you need to take decision, you must use “if “
Design an algorithm that determine if the given number is odd or even
After we analyze the problem
Solution :
Start
Define x ;
Read x
If (x mod 2 == 0)
Display “even”
Else
Display “odd”
end

start
accept information
display information
transformations
how to select decisions
how to repeat sub-tasks
when to terminate
What is next ?
Per examples
Positive or negative
Even or odd
Per example
Z= x+y
How to repeat ? we use
loops

how to repeat sub-tasks
So if you need to repeat, we use loops
Design an algorithm that help you to write your little brother to do his
homework. The homework is to write the “the lion” lesson 10 times
After we analyze the problem
Solution :
Start
Define I,hw;
Read hw
For( I = 1 : 10 )
Display hw
end

……It is not the end

1.write an algorithm of multiplying two number .
2.Write an algorithm to calculate the area of circle ??????=????????????
2
.
3.Write an algorithm of program that display “hello world ” when user types a positive
number, and display “bye world ” when user types a negative number.
4.Write an algorithm to print numbers between 0 to 10
5.Write an algorithm to calculate the factorial of any given number x!.
6.Write a program that display the number of digits of number . Ex 321 , consists of 3 digits
7.Write an algorithm that calculate the sum of digits. Example 123 = 6
Let ‘s practice more with new ideas

Where we
can type our
code ?
•We edit our code on editor. IDE (integrated
development environment /compiler
•CodeBlocks

Next session, we
‘re going to edit
our first code 