. Definition
An algorithm is a step-by-step procedure used to solve a specific problem or to perform a task.
It gives clear instructions in a logical order to reach the correct result.
__________________________________
. Example
Algorithm to make tea:
Take water in a pan
Boil the water
Add tea leaves and sugar
Add milk
Boil for 23 minutes
Pour tea into a cup
__________________________________
.Characteristics of an Algorithm
An algorithm must have:
1=INPUT Data given to the algorithm
2=OUTPUT Result produced. 3=Definiteness Clear and unambiguous steps
4=Finiteness Must end after limited steps
5=Effectiveness Steps must be simple and executable
__________________________________
.How Many Types of Algorithms Are There?
Algorithms are classified into different
types based on their working method.
1: Sequential algorithm
Steps are executed one after another in order.
Example:
Adding two numbers
Start
Input A and B
Sum = A + B
Display Sum
Stop
2: Selectional algorithm
Decision-making algorithms using conditions.
Example:
Check even or odd number
Start
Input number N
If N % 2 == 0, print Even
Else print Odd
Stop
3:Iteration (Looping) Algorithm
Repeat steps until a condition is satisfied.
Example:
Print numbers from 1 to 5
Start
Set i = 1
Print i
i = i + 1
Repeat steps 34 until i > 5
Stop
4:Recursive Algorithm
An algorithm that calls itself to solve a problem.
Example:
Factorial of a number
Factorial(5) = 5 4 3 2 1
5:Divide and Conquer Algorithm
Problem is divided into smaller sub-problems, solved separately, then combined.
Example:
Merge Sort
Binary Search
6: Greedy algorithm
Make the best choice at each step.
Example:
Coin change problem
Selection of activities
__________________________________
.How Does an Algorithm Work?
An algorithm works in three main stages:
1. Input
Data is given to the algorithm
Example: Numbers, values, user input
2. Processing
Logical operations are performed
Example: Calculations, comparisons
3. Output
Final result is displayed
Example: Sum, result, decision
Flow:
Input Process Output
.Example Showing How Algorithm Works
Problem: Find the greater of two numbers
.Algorithm:
.Start
.Input A and B
.If A > B, print A is greater
.Else print B is greater
.Stop
__________________________________
.Advantages of Algorithms
.Easy to understand
.Helps in program planning
.Reduces errors
.Language independent
__________________________________
. Disadvantages of algorithm
1=Time Consuming
Writing a detailed algorithm takes a lot of time, especially for big problems.
2=Difficult for Complex Problems
Large and complex problems make algorithms lengthy and hard to understand.
3=No Standard Format
There is no fixed rule or standard format for writing algorithms.
4=Not Visual
Algorithms do not show the flow of control visually like flowcharts.
5=Cannot Be Executed Directly
Algorithms must be converted into a program before execution.
6=Lengthy for Simple Tasks
Even small problems may require many steps, making the algorithm unnecessarily long.
__________________________________
. Conclusion
An algorithm is the basic foundation of programming that provides a clear, step-by-step method to solve a problem. It helps in understanding the logic of a program before actual coding. Algorithms are language independent, easy to plan, and reduce errors in program development. Different types of algorithms such as sequential, selection, iteration, and recursive are used according to the nature of the problem. Although algorithms may be time-consuming
and lengthy for complex problems, they play a very important role in problem solving and program design.
Requirements:
Get fast, custom help from our academic experts, any time of day.
Place your order now for a similar assignment and have exceptional work written by our team of experts.
Secure
100% Original
On Time Delivery