Introduction To Algorithms l1
Introduction To Algorithms l1
Ms Samb
ML engineer
What are algorithms?
An algorithm is any-well defined computational procedure that takes some values, or set of values, as input and
produces some value, or set of values as output in a finite amount of time. An algorithm is thus a sequence of
computational steps that transform inputs into outputs.
You can also view an algorithm as a tool for solving a well-specified computational problem. The statement of the
problem specifies in general terms the desired: input/output relationship for problem instances, typically of arbitrarily
large size.
The algorithm describes a specific computational procedure for achieving that input/output relationship for all
problem instances.
As an example, suppose that you need to sort a sequence of numbers into monotonically increasing order. This
problem arises frequently in practice and provides fertile ground for introducing many standard design techniques
and analysis tools. Here is how we formally define the sorting problem:
2
What are algorithms?
Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem
consists of the input (satisfying whatever constraints are imposed in the problem statement) needed to compute a
solution to the problem.
Because many programs use it as an intermediate step, sorting is a fundamental operation in computer science. As
a result, we have a large number of good sorting algorithms at our disposal. Which algorithm is best for a given
application depends on among other factors: the number of items to be sorted, the extent to which the items are
already somewhat sorted, possible restrictions on the item values, the architecture of the computer, and the kind of
storage devices to be used: main memory, disks, or even tapes.
An algorithm is said to be correct if, for every input instance, it halts with the correct output. We say that a correct
algorithm solves the given computational problem. An incorrect algorithm might not halt at all on some input
instances, or it might halt with an incorrect answer. Contrary to what you might expect, incorrect algorithms can
sometimes be useful, if we can control their error rate. Ordinarily, however, we shall be concerned only with correct
algorithms.
An algorithm can be specified in English, as a computer program, or even as a hardware design. The only
requirement is that the specification must provide a precise description of the computational procedure to be 3
followed.
What are algorithms?
4
5
Use of algorithm
Algorithms play a crucial role in various fields and have many applications. Some of the key areas where algorithms are
used include:
1. Computer Science: Algorithms form the basis of computer programming and are used to solve problems ranging
from simple sorting and searching to complex tasks such as artificial intelligence and machine learning.
2. Mathematics: Algorithms are used to solve mathematical problems, such as finding the optimal solution to a
system of linear equations or finding the shortest path in a graph.
3. Operations Research: Algorithms are used to optimize and make decisions in fields such as transportation,
logistics, and resource allocation.
4. Artificial Intelligence: Algorithms are the foundation of artificial intelligence and machine learning, and are used
to develop intelligent systems that can perform tasks such as image recognition, natural language processing, and
decision-making.
5. Data Science: Algorithms are used to analyze, process, and extract insights from large amounts of data in fields
such as marketing, finance, and healthcare.
6
Use of algorithm
These are just a few examples of the many applications of algorithms. The use of algorithms is continually
expanding as new technologies and fields emerge, making it a vital component of modern society.
It can be understood by taking the example of cooking a new recipe. To cook a new recipe, one reads the
instructions and steps and executes them one by one, in the given sequence. The result thus obtained is the new
dish is cooked perfectly. Every time you use your phone, computer, laptop, or calculator you are using Algorithms.
Similarly, algorithms help to do a task in programming to get the expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that can be implemented in
any language, and yet the output will be the same, as expected.
7
Use of algorithm
1. Algorithms are necessary for solving complex problems efficiently and effectively.
2. They help to automate processes and make them more reliable, faster, and easier to perform.
3. Algorithms also enable computers to perform tasks that would be difficult or impossible for humans to do
manually.
4. They are used in various fields such as mathematics, computer science, engineering, finance, and many
others to optimize processes, analyze data, make predictions, and provide solutions to problems.
8
9
source: https://www.geeksforgeeks.org/introduction-to-algorithms/
Issues for Algorithm
There are various issues in the study of algorithms;
1. How to devise algorithms: The creation of an algorithm is a logical activity which may never be fully automated.
2. How to express algorithms: We shall express all of our algorithms using the best principles of structuring.
3. How to validate algorithms: After creation of algorithms is to validate algorithms. The process of checking an
algorithm computes the correct answer for all possible legal inputs is called algorithm validation. The purpose
of validation of algorithm is to find whether algorithm works properly without being dependent upon
programming languages.
4. How to analyze algorithms: Analysis of algorithm is a task of determining how much computing time and
storage is required by an algorithm. Analysis of algorithms is also called performance analysis. The behavior of
algorithm in best case, worst case and average case needs to be obtained.
5. How to test a program: Testing a program really consists of two phases:
a. Debugging: While debugging a program, it is checked whether program produces faulty results for valid
set of input and if it is found then the program has to be corrected.
b. Profiling or performance measuring: Profiling is a process of measuring time and space required by a
corrected program for valid set of inputs.
10
How to devise algorithms?
Creating an algorithm is an art which may never be fully automated. In this research we
want to study more design techniques and select appropriate design techniques to devise
the new useful algorithm. The most important design techniques are
(a) Brute-force or exhaustive search
(b) Divide and Conquer
(c) Greedy Algorithms
(d) Dynamic Programming
(e) Branch and Bound Algorithm
(f) Randomized Algorithm
(g) Backtracking
11
How to validate algorithms?
* Once an algorithm is devised, it is necessary to show that it computes the correct answer for all
possible legal inputs.
*It helps to the next process for writing program code in a particular programming language.
* This phase is also called program proving or program verification.
*The proof of correctness requires that the solution be stated in two forms.
* First form, In this form a program which is annotated by a set of assertations about the input and
output variables of the program. Then these assertations are often expresses in the predicate
calculus.
* Second form is called specification, and this expressed in the predicate calculus.
12
How to analysis algorithms?
> Efficiency of an algorithm can be analyzed at two different stages, before and after
implementation.
Before implementation(priori analysis), analysis of algorithms refers to the task of
determining how much computing time and storage space an algorithm require.
After implementation(Posterior Analysis), “Posterior” means “after”. Hence Posterior analysis means
checking the algorithm after its implementation. In this, the algorithm is checked by implementing it in any
programming language and executing it. This analysis helps to get the actual and real analysis report
about correctness(for every possible input/s if it shows/returns correct output or not), space required, time
consumed, etc. That is, it is dependent on the language of the compiler and the type of hardware used.
> This is the challenging area which require great mathematical skill. (Quantitative
judgement about the algorithms)
> An algorithm perform in the best case, the worst case or on the average case are typical.
13
14
TITLE
THANKS!
9/12/2021 15