Algorithm
Algorithm
carried out in a specific order to produce the desired result. Algorithms are generally
developed independently of underlying languages, which means that an algorithm can
be implemented in more than one programming language. Unambiguity, fineness,
effectiveness, and language independence are some of the characteristics of an
algorithm. The scalability and performance of an algorithm are the primary factors that
contribute to its importance.
What is an Algorithm?
After defining what an algorithm is, you will now look at algorithm characteristics.
Characteristics of an Algorithm
Moving on in this What is an Algorithm tutorial, you will look at why you need an
algorithm.
Scalability
Performance
The real world is challenging to break down into smaller steps. If a problem can be
easily divided into smaller steps, it indicates that the problem is feasible.
After understanding what is an algorithm, why you need an algorithm, you will look at
how to write one using an example.
Example
Problem: Create an algorithm that multiplies two numbers and displays the output.
Step 1 − Start
Step 6 − print z
Step 7 − Stop
Algorithms instruct programmers on how to write code. In addition, the algorithm can
be written as:
Step 3 − z ← x * y
Step 4 − display z
Step 5 − Stop
In algorithm design and analysis, the second method is typically used to describe an
algorithm. It allows the analyst to analyze the algorithm while ignoring all unwanted
definitions easily. They can see which operations are being used and how the process is
progressing. It is optional to write step numbers. To solve a given problem, you create
an algorithm. A problem can be solved in a variety of ways.
As you progress through this "what is an Algorithm" tutorial, you will learn about some
of the components of an algorithm.
Factors of an Algorithm
Modularity: This feature was perfectly designed for the algorithm if you are given
a problem and break it down into small-small modules or small-small steps,
which is a basic definition of an algorithm.
Correctness: An algorithm's correctness is defined as when the given inputs
produce the desired output, indicating that the algorithm was designed correctly.
An algorithm's analysis has been completed correctly.
Maintainability: It means that the algorithm should be designed in a
straightforward, structured way so that when you redefine the algorithm, no
significant changes are made to the algorithm.
Functionality: It takes into account various logical steps to solve a real-world
problem.
Robustness: Robustness refers to an algorithm's ability to define your problem
clearly.
User-friendly: If the algorithm is difficult to understand, the designer will not
explain it to the programmer.
Simplicity: If an algorithm is simple, it is simple to understand.
Extensibility: Your algorithm should be extensible if another algorithm designer
or programmer wants to use it.
You will now see why an algorithm is so essential after understanding some of its
components.
Importance of an Algorithm
Compiled By: Jyotiranjan Sahoo , Asst.Prof. BPUT, Odisha 4
There are two factors in which the algorithm is fundamental:
Theoretical Significance
When you are given a real-world problem, you must break it down into smaller
modules. To deconstruct the problem, you must first understand all of its theoretical
aspects.
Practical Significance
As you all know, theory cannot be completed without practical application. As a result,
the significance of algorithms can be considered both theoretically and practically.
As you progress through this "what is an algorthim" tutorial, you will see algorithmic
approaches.
Approaches of an Algorithm
This algorithm uses the general logic structure to design an algorithm. It is also called
an exhaustive search algorithm because it exhausts all possibilities to provide the
required solution. There are two kinds of such algorithms:
1. Optimizing: Finding all possible solutions to a problem and then selecting the
best one, will terminate if the best solution is known.
2. Sacrificing: It will stop as soon as the best solution is found.
Greedy Algorithm
This is an algorithm paradigm that makes the best choice possible on each iteration in
the hopes of choosing the best solution. It is simple to set up and has a shorter
execution time. However, there are very few cases where it is the best solution.
Dynamic Programming
Only integer programming problems can be solved using the branch and bound
algorithm. This method divides all feasible solution sets into smaller subsets. These
subsets are then evaluated further to find the best solution.
Randomized Algorithm
As with a standard algorithm, you have predefined input and output. Deterministic
algorithms have a defined set of information and required results and follow some
described steps. They are more efficient than non-deterministic algorithms.
Backtracking
It is an algorithmic procedure that recursively and discards the solution if it does not
satisfy the constraints of the problem.
Following your understanding of what is an algorith, and its approaches, you will now
look at algorithm analysis.
Analysis of an Algorithm
The algorithm can be examined at two levels: before and after it is created. The two
algorithm analyses are as follows:
Priori Analysis
Posterior Analysis
Moving on in this "what is an algorithm" tutorial, you will now look at the complexity of
an algorithm.
Time Complexity
for i=1 to n
mul = mul *1;// when the loop ends, then mul holds the multiplication of the n
numbers
return mul;
The time complexity of the loop statement in the preceding code is at least n, and as
the value of n escalates, so does the time complexity. While the code's complexity, i.e.,
returns mul, will be constant because its value is not dependent on the importance of n
and will provide the result in a single step. The worst-time complexity is generally
considered because it is the maximum time required for any given input size.
Space Complexity
The amount of space an algorithm requires to solve a problem and produce an output
is called its space complexity. Space complexity, like time complexity, is expressed in
big O notation.
Finally after understanding what is an algorithm, its analysis and approches, you will
look at different types of algorithms.
Types of Algorithms
Search Algori
Sort Algorithm
Search Algorithm
Every day, you look for something in your daily life. Similarly, in the case of a
computer, a large amount of data is stored in the computer, and whenever a user
requests data, the computer searches for that data in the memory and returns it to the
user. There are primarily two methods for searching data in an array:
Linear Search
Compiled By: Jyotiranjan Sahoo , Asst.Prof. BPUT, Odisha 7
Linear search is a simple algorithm that begins searching for an element or a value at
the beginning of an array and continues until the required element is not found. It
compares the element to be searched with all the elements in an array; if a match is
found, the element index is returned; otherwise, -1 is returned. This algorithm can be
applied to an unsorted list.
Binary Search
A binary algorithm is the most basic algorithm, and it searches for elements very
quickly. It is used to find an element in a sorted list. To implement the binary
algorithm, the elements must be stored in sequential order or sorted. If the elements
are stored randomly, binary search cannot be implemented.
Sort Algorithm
Now that you have completed the tutorial on "what is an algorithm," you will
summarise what you have learned so far.