0% found this document useful (0 votes)
26 views9 pages

Pre Lab DAA (Introduction)

Uploaded by

nupurk.aids22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views9 pages

Pre Lab DAA (Introduction)

Uploaded by

nupurk.aids22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Pre-Lab (AD22026)

Aim: Introduction to algorithm, Basic Concepts and Simulation

 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.

 Steps to design an algorithm:

 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:

1. Brute Force Algorithm:


It is the simplest approach to 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 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.

7. Divide and Conquer Algorithm:


This algorithm breaks a problem into sub-problems, solves a single sub-problem, and
merges the solutions 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 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.

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 Notations, graph and equations:

o The main idea of asymptotic analysis is to have a measure of the


efficiency of algorithms that don’t depend on machine-specific
constants and don’t require algorithms to be implemented and time
taken by programs to be compared.
o Asymptotic notations are mathematical tools to represent the time
complexity of algorithms for asymptotic analysis.
There are mainly three asymptotic notations:

1. Big-O Notation (O-notation)


2. Omega Notation (Ω-notation)
3. Theta Notation (Θ-notation)

1. Theta Notation (Θ-Notation):


Theta notation encloses the function from above and below. Since it
represents the upper and the lower bound of the running time of an algorithm, it is
used for analyzing the average-case complexity of an algorithm.
.Theta (Average Case) You add the running times for each possible input
combination and take the average in the average case.
2. Big-O Notation (O-notation) :
Big-O notation represents the upper bound of the running time of an
algorithm. Therefore, it gives the worst-case complexity of an algorithm.
.It is the most widely used notation for Asymptotic analysis.
.It specifies the upper bound of a function.
.The maximum time required by an algorithm or the worst-case time complexity.
.It returns the highest possible output value(big-O) for a given input.
.Big-Oh(Worst Case) It is defined as the condition that allows an algorithm to
complete statement execution in the longest amount of time possible.

4. Omega Notation (Ω-Notation):

Omega notation represents the lower bound of the running time of an


algorithm. Thus, it provides the best case complexity of an algorithm.
The execution time serves as a lower bound on the algorithm’s time complexity.
It is defined as the condition that allows an algorithm to complete statement execution in
the shortest amount of time.

 Complexity:
The complexity of an algorithm can be measured in three ways:

1. Time Complexity:

The time complexity of an algorithm is defined as the amount of time taken


by an algorithm to run as a function of the length of the input. Note that the time to
run is a function of the length of the input and not the actual execution time of the
machine on which the algorithm is running on

How is Time complexity computed?

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 amount of memory required by the algorithm to solve a given problem is


called the space complexity of the algorithm. Problem-solving using a computer
requires memory to hold temporary data or final result while the program is in
execution.

How is space complexity computed?

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.

Space complexity is a parallel concept to time complexity. If we need to create an


array of size n, this will require O(n) space. If we create a two-dimensional array of
size n*n, this will require O(n2) space.

 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

You might also like