What Is An Algorithm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

What is an Algorithm?

The word Algorithm means “A set of rules to be followed in calculations or other problem-solving operations” Or “A
procedure for solving a mathematical problem in a finite number of steps that frequently involves recursive
operations “.
Algorithms can be simple and complex depending on what you want to achieve.

An algorithm is a well-defined sequential computational technique that accepts a value or a


collection of values as input and produces the output(s) needed to solve a problem.
Or we can say that an algorithm is said to be accurate if and only if it stops with the proper output
for each input instance.
NEED OF THE ALGORITHMS :
Algorithms are used to solve problems or automate tasks in a systematic and efficient manner.
They are a set of instructions or rules that guide the computer or software in performing a
particular task or solving a problem.
There are several reasons why we use algorithms:
 Efficiency: Algorithms can perform tasks quickly and accurately, making them an essential tool
for tasks that require a lot of calculations or data processing.
 Consistency: Algorithms are repeatable and produce consistent results every time they are
executed. This is important when dealing with large amounts of data or complex processes.
 Scalability: Algorithms can be scaled up to handle large datasets or complex problems, which
makes them useful for applications that require processing large volumes of data.
 Automation: Algorithms can automate repetitive tasks, reducing the need for human
intervention and freeing up time for other tasks.
 Standardization: Algorithms can be standardized and shared among different teams or
organizations, making it easier for people to collaborate and share knowledge.
Know about Algorithm Complexity:
Complexity in algorithms refers to the amount of resources (such as time or memory) required to
solve a problem or perform a task. The most common measure of complexity is time complexity,
which refers to the amount of time an algorithm takes to produce a result as a function of the size
of the input. Memory complexity refers to the amount of memory used by an algorithm. Algorithm
designers strive to develop algorithms with the lowest possible time and memory complexities,
since this makes them more efficient and scalable.
The complexity of an algorithm is a function describing the efficiency of the algorithm in terms of
the amount of data the algorithm must process.
Usually there are natural units for the domain and range of this function.
An algorithm is analyzed using Time Complexity and Space Complexity. Writing an efficient
algorithm help to consume the minimum amount of time for processing the logic. For algorithm A, it
is judged on the basis of two parameters for an input of size n :
 Time Complexity: Time taken by the algorithm to solve the problem. It is measured by
calculating the iteration of loops, number of comparisons etc.
 Time complexity is a function describing the amount of time an algorithm takes in terms of the
amount of input to the algorithm.
 “Time” can mean the number of memory accesses performed, the number of comparisons
between integers, the number of times some inner loop is executed, or some other natural unit
related to the amount of real time the algorithm will take.
 Space Complexity: Space taken by the algorithm to solve the problem. It includes space used
by necessary input variables and any extra space (excluding the space taken by inputs) that is
used by the algorithm. For example, if we use a hash table (a kind of data structure), we need
an array to store values so
 this is an extra space occupied, hence will count towards the space complexity of the algorithm.
This extra space is known as Auxiliary Space.
 Space complexity is a function describing the amount of memory(space)an algorithm takes in
terms of the amount of input to the algorithm.
 Space complexity is sometimes ignored because the space used is minimal and/ or obvious,
but sometimes it becomes an issue as time.
.The time complexity of the operations:
 The choice of data structure should be based on the time complexity of the operations that will
be performed.
 Time complexity is defined in terms of how many times it takes to run a given algorithm, based
on the length of the input.
 The time complexity of an algorithm is the amount of time it takes for each statement to
complete. It is highly dependent on the size of the processed data.
 For example, if you need to perform searches frequently, you should use a binary search tree.
.The space complexity of the operations:
 The choice of data structure should be based on the space complexity of the operations that
will be performed.
 The amount of memory used by a program to execute it is represented by its space complexity.
 Because a program requires memory to store input data and temporal values while running ,
the space complexity is auxiliary and input space.
 For example, if you need to store a lot of data, you should use an array.

cases in complexities:
There are two commonly studied cases of complexity in algorithms:
1.Best case complexity: The best-case scenario for an algorithm is the scenario in which the
algorithm performs the minimum amount of work (e.g. takes the shortest amount of time, uses the
least amount of memory, etc.).
2.Worst case complexity: The worst-case scenario for an algorithm is the scenario in which the
algorithm performs the maximum amount of work (e.g. takes the longest amount of time, uses the
most amount of memory, etc.).
In analyzing the complexity of an algorithm, it is often more informative to study the worst-case
scenario, as this gives a guaranteed upper bound on the performance of the algorithm. Best-case
scenario analysis is sometimes performed, but is generally less important as it provides a lower
bound that is often trivial to achieve.

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.
Disadvantages of Algorithms
 Creating efficient algorithms is time-consuming and requires good logical skills.
 Nasty to show branching and looping in algorithms.

Types of Algorithms:
There are several types of algorithms available. Some important algorithms are:
1. Brute Force Algorithm: It is the simplest approach for a problem. A brute force algorithm is the first approach that
comes to finding when we see a problem.
2. Recursive Algorithm: A recursive algorithm is based on recursion. In this case, a problem is broken into several
sub-parts and called the same function again and again.
3. Backtracking Algorithm: The backtracking algorithm basically builds the solution by searching among all possible
solutions. Using this algorithm, we keep on building the solution following criteria. Whenever a solution fails we trace
back to the failure point and build on the next solution and continue this process till we find the solution or all possible
solutions are looked after.
4. Searching Algorithm: Searching algorithms are the ones that are used for searching elements or groups of elements
from a particular data structure. They can be of different types based on their approach or the data structure in which
the element should be found.
5. Sorting Algorithm: Sorting is arranging a group of data in a particular manner according to the requirement. The
algorithms which help in performing this function are called sorting algorithms. Generally sorting algorithms are used
to sort groups of data in an increasing or decreasing manner.
6. Hashing Algorithm: Hashing algorithms work similarly to the searching algorithm. But they contain an index with
a key ID. In hashing, a key is assigned to specific data.
7. Divide and Conquer Algorithm: This algorithm breaks a problem into sub-problems, solves a single sub-problem
and merges the solutions together to get the final solution. It consists of the following three steps:
 Divide
 Solve
 Combine
8. Greedy Algorithm: In this type of algorithm the solution is built part by part. The solution of the next part is built
based on the immediate benefit of the next part. The one solution giving the most benefit will be chosen as the solution
for the next part.
9. Dynamic Programming Algorithm: This algorithm uses the concept of using the already found solution to avoid
repetitive calculation of the same part of the problem. It divides the problem into smaller overlapping subproblems and
solves them.
10. Randomized Algorithm: In the randomized algorithm we use a random number so it gives immediate benefit. The
random number helps in deciding the expected outcome.
Asymptotic Notation and Analysis (Based on input size) in Complexity Analysis of Algorithms
Asymptotic notation is a way to describe the running time or space complexity of an algorithm based on the input
size. It is commonly used in complexity analysis to describe how an algorithm performs as the size of the input
grows. The three most commonly used notations are Big O, Omega, and Theta.
1. Big O notation (O): This notation provides an upper bound on the growth rate of an algorithm’s running time
or space usage. It represents the worst-case scenario, i.e., the maximum amount of time or space an algorithm
may need to solve a problem. For example, if an algorithm’s running time is O(n), then it means that the
running time of the algorithm increases linearly with the input size n or less.
2. Omega notation (Ω): This notation provides a lower bound on the growth rate of an algorithm’s running time
or space usage. It represents the best-case scenario, i.e., the minimum amount of time or space an algorithm
may need to solve a problem. For example, if an algorithm’s running time is Ω(n), then it means that the
running time of the algorithm increases linearly with the input size n or more.
3. Theta notation (Θ): This notation provides both an upper and lower bound on the growth rate of an
algorithm’s running time or space usage. It represents the average-case scenario, i.e., the amount of time or
space an algorithm typically needs to solve a problem. For example, if an algorithm’s running time is Θ(n),
then it means that the running time of the algorithm increases linearly with the input size n.
In general, the choice of asymptotic notation depends on the problem and the specific algorithm used to solve it.
It is important to note that asymptotic notation does not provide an exact running time or space usage for an
algorithm, but rather a description of how the algorithm scales with respect to input size. It is a useful tool for
comparing the efficiency of different algorithms and for predicting how they will perform on large input sizes.
Why performance analysis?
There are many important things that should be taken care of, like user-friendliness, modularity, security,
maintainability, etc. Why worry about performance? The answer to this is simple, we can have all the above
things only if we have performance. So performance is like currency through which we can buy a ll the above
things. Another reason for studying performance is – speed is fun! To summarize, performance == scale. Imagine
a text editor that can load 1000 pages, but can spell check 1 page per minute OR an image editor that takes 1 hour
to rotate your image 90 degrees left OR … you get it. If a software feature can not cope with the scale of tasks
users need to perform – it is as good as dead.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy