Tutorial 3: How to write an Algorithm and its Basic
- There are no well-defined standards for writing algorithms.
- It is problem or resource dependent.
- All programming languages share basic code constructs like loops (do, for and while), flow controls (if-else), etc. These common constructs can be used to write an algorithm.
- Algorithm writing is a process and is executed after the problem domain is well-defined.
Problem:- Design an algorithm to add two numbers and display the result
step 1: START
step 2: declare three integers a, b & c
step 3: define values of a & b
step 4: add values of a & b
step 5: store step 4 to c
step 6: print c
step 7: STOP
Other Way:-
step 1: START ADD
step 2: get values of a & b
step 3: c < — a & b
step 4: display c
step 5: STOP
Algorithm Complexity:-
Two main factor which decide the efficiency of X
Time Factor:- Time is measured by counting the number of key operation such as comparisons in the sorting algorithm.
Space Factor:- Space is measured by counting a maximum memory space required by the algorithm.