Data Structures Algorithms and its Analysis

Estudies4you
Algorithm and its Analysis
Definition
An algorithm is a step by step procedure consisting of a set of rules
Characteristics of an algorithm:
·         Input: Zero or more inputs are extremely supplied.
·         Output: At least on output is produced.
·         Definitions: Each instruction is clear and unambiguous.
·         Finiteness: If we trace out the instructions of an algorithm, in all cases the algorithm terminates after a finite number of steps.
·         Effectiveness: Every instruction must be very basic so that it can be essentially carried out, say using a pencil and paper.

Example: To make tea, the following steps are to be followed:-
Step 1: Fill the kettle with 2 cups of water
Step 2: Switch on the power
Step 3: When water has boiled then
Step 4: Add 1 tea spoon of tea powder
Step 5: Add 2 tea spoons of sugar
Step 6: add half a cup of milk
Step 7: Switch off the power
Step 8: Pour the tea into a cup and serve
Example: if a person wants to travel from Hyderabad to Vishakapatnam by a bus, the following steps to be followed
Step 1: Decide the data and time
Step 2: Buy a ticket for that particular date and time
Step 3: Go to the Hyderabad bus station on that day and in time
Step 4: Board the bus to Vishakapatnam
Step 5: Get down in Vishakapatnam.


First one is not an algorithm because it is not satisfying the characteristics of an algorithm (step 3 is not definite).
Now, give another procedure which is not an algorithm
An algorithm to display the sum of three given numbers
Step 1: Begin
Step 2: Read three numbers a, b, c
Step 3: Store a + b + c in the sum
Step 4: Display the sum
Step 5: End

An instance
·         Begin
·         Given numbers 12, 25, 33
·         Sum = 12 + 25 + 33
·         Display “70”
·         End
An algorithm to display the greatest number from the three given numbers
Step 1: Begin
Step 2: read three numbers a, b, c
Step 3: if(a>b) and (a>c)
Step 4: display ‘a’ as the greatest number
Step 5: else if(b>c)
Step 6: display ‘b’ as the greatest number
Step 7: else
Step 8: display ‘c’ as the greatest number
Step 9: End

An algorithm to display the greatest number from the three given numbers
Step 1: Begin
Step 2: read three numbers a, b, c
Step 3: if(a>b) and (a>c)
Step 4: display ‘a’ as the greatest number
Step 5: else if(b>c)
Step 6: display ‘b’ as the greatest number
Step 7: else
Step 8: display ‘c’ as the greatest number
Step 9: End
An Instance
Begin
Given numbers 7, 8, 9
If(7>8) and (7>9) (false)
else if(8>9) (false)
7. else (true)
8. display “9” as the greatest number
9. End

To Top