Data Structure and Algorithm - Fundamental Programing Part 1
Data Structure and Algorithm - Fundamental Programing Part 1
⚫ A sequence of instructions.
⚫ A procedure or formula for solving a problem.
⚫ It was created mathematician, Mohammed ibn-Musa
al-Khwarizmi.
⚫ Often used for calculation, data processing and
programming.
⚫ Algorithms can be expressed in any language.
2
Introduction to Algorithms
3
Types of Algorithms
Flow chart
4
Pseudocode
5
Pseudocode
Example of Pseudocode:
6
Pseudocode
Advantages of Pseudocode
⚫ Reduced complexity.
⚫ Increased flexibility.
⚫ Ease of understanding.
7
Pseudocode
Why is Pseudocode Necessary?
8
Pseudocode
How to Write Pseudocode Statements?
9
Pseudocode
How to Write Pseudocode Statements?
3. A computer can perform arithmetic
Use actual mathematical symbols or the words for the symbols
Example:
Add number to total
Total = total + number
+, -, *, /
Calculate, Compute also used
Pseudocode
How to Write Pseudocode Statements?
IF condition THEN
some action
ELSE
alternative action
ENDIF
Pseudocode
Example 1:
Program Specification:
Write a program that obtains two integer numbers from the
user. It will print out the sum of those numbers.
Pseudocode:
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the sum
Display the result
Pseudocode
Example 2:
Finding average of any three numbers.
Step 1 Start
Step 2 Read values of X, Y, Z
Step 3 S=X+Y+Z
Step 4 A=S/3
Step 5 Write value of A
Step 6 Stop
Pseudocode
Example 3:
Finding square and cube.
Step 1 Start
Step 2 Read value of N
Step 3 S=N*N
Step 4 C=S*N
Step 5 Write values of S, C
Step 6 Stop
Pseudocode
Example 4:
Finding biggest of two numbers.
Step 1 Start
Step 2 Read A, B
Step 3 If A > B, then BIG = A, otherwise
BIG = B
Step 4 Write BIG
Step 5 Stop
Pseudocode
Example 5:
Calculate pay.
Step 1 Start
Step 2 Input hours
Step 3 Input rate
Step 4 pay = hours * rate
Step 5 Print pay
Step 6 End
Pseudocode
Exercise:
Write a Pseudocode for these problems.
1. S = (A + B + C) / Y
2. Convert from Celsius to Fahrenheit.
(Multiply by 9, then divide by 5, then add 32 )
3. Area of Circle (r2) 4
4. Volume of Sphere ( 3 r3)
Distance traveled
5. Average speed = Time taken
End of session Part 1