Pre Lab DAA (Introduction)
Pre Lab DAA (Introduction)
Introduction
The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
A procedure for solving a mathematical problem in a finite number of steps that
frequently involves recursive operations”.
o Algorithm Definition:
An algorithm is a set of commands that must be followed for a computer to
perform calculations or other problem-solving operations.According to its formal
definition, an algorithm is a finite set of instructions carried out in a specific
order to perform a particular task. It is not the entire program or code; it is simple
logic to a problem represented as an informal description in the form of a
flowchart or pseudocode.
Characteristics of Algorithm:
Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs. It may or may not take input.
Well-Defined Outputs: The algorithm must clearly define what output will be
yielded and it should be well-defined as well. It should produce at least 1 output.
Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
Feasible: The algorithm must be simple, generic, and practical, such that it can be
executed with the available resources. It must not contain some future technology or
anything.
Language Independent: The Algorithm designed must be language-independent,
i.e. it must be just plain instructions that can be implemented in any language, and
yet the output will be the same, as expected.
Input: An algorithm has zero or more inputs. Each that contains a fundamental
operator must accept zero or more inputs.
Output: An algorithm produces at least one output. Every instruction that contains
a fundamental operator must accept zero or more inputs.
Algorithms Techniques:
There are several types of algorithms available. Some important algorithms are:
3. Backtracking Algorithm:
The backtracking algorithm 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 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.
8. Greedy Algorithm:
In this type of algorithm, the solution is built part by part. The solution for the next part
is built based on the immediate benefit of the next part. The one solution that gives the most
benefit will be chosen as the solution for the next part.
Complexity:
The complexity of an algorithm can be measured in three ways:
1. Time Complexity:
To estimate the time complexity, we need to consider the cost of each fundamental
instruction and the number of times the instruction is executed.
If we have statements with basic operations like comparisons, return
statements, assignments, and reading a variable. We can assume they
take constant time each O(1).
2. Space Complexity :
The space Complexity of an algorithm is the total space taken by the algorithm with
respect to the input size. Space complexity includes both Auxiliary space and space
used by input.
Example of an Algorithm:
Problem: Create an algorithm that multiplies two numbers and displays the output.
Algorithms instruct programmers on how to write code. In addition, the algorithm can be written as:
Simulation Links:
o Sort techniques: https://visualgo.net/en/sorting
o
o Searching Technique:
https://www.cs.usfca.edu/~galles/visualization/Search.html