Algorithm-Definition-examples-Complexity-Divide and Conquer- Binary search
-Maximum
and Minimum-Merge sort.
1.Algorithm Definition:
Algorithm is step-by-step process or sequence of steps for solving a
problem.
2. Properties of an Algorithm
The properties of an algorithm is given by
✓ Input: The algorithm must have input values from a specified set
✓ Output: The algorithm must produce the output values from a specified
set of input values. The output values are the solution to a problem.
✓ Finiteness: For any input the algorithm must terminate after a finite
number of steps.
✓ Definiteness: All the steps of the algorithm must be precisely defined.
✓ Effectiveness: It must be possible to perform each step of the algorithm
correctly and in a finite amount of time
3.Types of Algorithms:
1.Sorting algorithms: Bubble Sort, insertion sort, and many more. These
algorithms are used to sort the data in a particular format.
2.Searching algorithms: Linear search, binary search, etc. These algorithms are
used in finding a value or record that the user demands.
3.Graph Algorithms: It is used to find solutions to problems like finding the
shortest path between cities, and real-life problems like traveling salesman
problems.
Example 1: Write an algorithm to find the maximum of all the elements
present in the array.
, Step 1: Start the Program
Step 2: Declare a variable max with the value of the first element of the array.
Step 3: Compare max with other elements using loop.
Step 4: If max < array element value, change max to new max.
Step 5: If no element is left, return or print max otherwise goto step 3.
Step 6: End of Solution
Example 2: Write an algorithm to find the average of 3 subjects.
Step 1: Start the Program
Step 2: Declare and Read 3 Subject, let’s say S1, S2, S3
Step 3: Calculate the sum of all the 3 Subject values and store result in Sum
variable (Sum = S1+S2+S3)
Step 4: Divide Sum by 3 and assign it to Average variable. (Average = Sum/3)
Step 5: Print the value of Average of 3 Subjects
Step 6: End of Solution
4.Advantages of Algorithms
• Easy to understand: Since it is a stepwise representation of a solution to
a given problem, it is easy to understand.
• Language Independent: It is not dependent on any programming
language, so it can easily be understood by anyone.
• Debug / Error Finding: Every step is independent / in a flow so it will be
easy to spot and fix the error.
• Sub-Problems: It is written in a flow so now the programmer can divide
the tasks which makes them easier to code.