0% found this document useful (0 votes)
22 views

DSA Algorithm

The document discusses different types of algorithms including deterministic, non-deterministic, series, parallel, heuristic, and approximate algorithms. It also covers asymptotic analysis and common notations used like Big O, Big Omega, and Big Theta to analyze the time complexity of algorithms.

Uploaded by

Riyaz Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

DSA Algorithm

The document discusses different types of algorithms including deterministic, non-deterministic, series, parallel, heuristic, and approximate algorithms. It also covers asymptotic analysis and common notations used like Big O, Big Omega, and Big Theta to analyze the time complexity of algorithms.

Uploaded by

Riyaz Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Algorithm:

Deterministic algorithm:
• In a deterministic algorithm, for a given particular input, the computer will
always produce the same output going through the same states and follow a
predictable sequence of steps to arrive at that output
• Can solve the problem in polynomial time.
• Can determine the next step of execution.
• The algorithms in which the result of every algorithm is uniquely defined
are known as the Deterministic Algorithm. In other words, we can say that
the deterministic algorithm is the algorithm that performs fixed number of
steps and always get finished with an accept or reject state with the same
result.
• In Deterministic Algorithms execution, the target machine executes the
same instruction and results same outcome which is not dependent on the
way or process in which instruction get executed
• In deterministic algorithm the path of execution for algorithm is same in
every execution.
• As outcome is known and is consistent on different executions so
Deterministic algorithm takes polynomial time for their execution.
• On the basis of execution and outcome in case of Deterministic algorithm,
they are also classified as reliable algorithms as for a particular input
instructions the machine will give always the same output.
• Example bubble sort
• Predictable processing
• No randomness.
• Consistance result.
non-deterministic algorithm
• non-deterministic algorithm, for the same input, the compiler may
produce different output in different runs.
• In fact, non-deterministic algorithms can’t solve the problem in
polynomial time and can’t determine what is the next step.
• The non-deterministic algorithms can show different behaviors for
the same input on different execution and there is a degree of
randomness to it.
• the algorithms in which the result of every algorithm is not uniquely defined
and result could be random are known as the Non-Deterministic Algorithm
• the machine executing each operation is allowed to choose any one of these
outcomes subjects to a determination condition to be defined later.
• On other hand Non deterministic algorithm are classified as non-reliable
algorithms for a particular input the machine will give different output on
different executions.
• outcome is not known and is non-consistent on different executions so Non-
Deterministic algorithm could not get executed in polynomial time.
• the path of execution is not same for algorithm in every execution and could
take any random path for its execution.
Deterministic Algorithms Non-deterministic Algorithms
It has a single outcome. It has multiple outcomes.

Algorithm is non-deterministic if the algorithm


In a deterministic algorithm, given input will
takes more than one path. Due to this, one cannot
always produce the same output.
determine the next state of the machine.

It has a unique value. It has different values.


Can solve the problem in polynomial time. Can’t solve the problem in polynomial time.

The algorithm which terminates unsuccessfully if


The algorithm where the result is uniquely is and only if there exists no set of choices leading to
termed the deterministic algorithm a success signal is known as a non-deterministic
algorithm.

Example : Mathematical function is deterministic. Example: Random function is non-deterministic.


Series and parallel algorithm:
• In a "series" algorithm, tasks are completed one after the other, in a linear fashion. For
example, if you had a series of tasks to complete, you would do them in the order they were
given to you, completing one task before moving on to the next.
• Series algorithms are a type of algorithm that processes tasks in a linear, sequential fashion.
• They execute tasks one after the other, in the order they are given.
• Series algorithms are straightforward and easy to understand.
• They are suitable for simple problems or tasks with a fixed number of steps.
• Series algorithms may be less efficient than parallel algorithms, which can process tasks
simultaneously.
• They do not require the use of multiple processors or cores.
• Series algorithms can be run on any computer, regardless of its hardware configuration.
• They may be less affected by hardware or software failures, since they do not rely on multiple
components working together.
• Series algorithms can be used to solve a wide range of problems, including sorting, searching,
and data processing tasks.
• They may be less sensitive to input data or initial conditions than parallel algorithms.
Parallel Algorithm:
• In a "parallel" algorithm, tasks are divided into smaller units that can
be processed simultaneously, or in parallel.
• This can be done using multiple processors or cores, or by using
distributed computing techniques.
• Parallel algorithms can often be more efficient, because they can take
advantage of the increased processing power available on modern
computers. However, they can also be more complex to design and
implement
Parallel algorithm:
• Parallel algorithms are designed to take advantage of the increased processing power
available on modern computers by dividing tasks into smaller units that can be processed
simultaneously.
• They can be implemented using multiple processors or cores, or by using distributed
computing techniques.
• Parallel algorithms can be more efficient than series algorithms, especially for tasks that can
be divided into many independent units of work.
• They may be more complex to design and implement than series algorithms, due to the need
to coordinate the processing of multiple units of work.
• Parallel algorithms may be sensitive to factors such as the number and type of processors or
cores available, the size of the input data, and the communication overhead between
processing units.
• They may require more sophisticated programming techniques and tools, such as parallel
libraries or frameworks.
• Testing and debugging parallel algorithms can be more challenging, due to the need to
consider the interactions between multiple processing units.
Heuristic algorithm
• Heuristic algorithms are a type of algorithm that uses "rules of thumb" or
practical experience to find approximate solutions to problems, rather than
guaranteed optimal solutions.
• They are often used when it is difficult or impractical to find an exact
solution to a problem, or when the search space is too large to explore
completely.
• Heuristic algorithms can be very efficient, since they may not need to
explore every possible solution.
• They are commonly used in optimization problems, where the goal is to
find the best solution among a set of feasible alternatives.
• Heuristic algorithms may not always find the best possible solution, but
they can often find solutions that are "good enough" for practical
purposes.
Approximate algorithm:
• Approximate algorithms are a type of algorithm that trade accuracy for
efficiency, by providing solutions that are close to the optimal solution,
but not necessarily identical to it.
• They are often used when the cost of finding an exact solution is too high,
or when the input data is noisy or uncertain.
• Approximate algorithms may be faster than exact algorithms, since they
may not need to explore the entire search space.
• They can be used to solve a wide range of problems, including
optimization, machine learning, and data mining.
• The quality of the approximation may depend on factors such as the input
data, the complexity of the problem, and the design of the algorithm.
Asymptotic analysis
• Asymptotic analysis of an algorithm, refers to defining the mathematical
boundation/framing of its run-time performance. Using asymptotic
analysis, we can very well conclude the best case, average case and worst
case scenario of an algorithm.
• Asymptotic analysis refers to computing the running time of any
operation in mathematical units of computation
• Usually, time required by an algorithm falls under three types −
• Best Case − Minimum time required for program execution.
• Average Case − Average time required for program execution.
• Worst Case − Maximum time required for program execution.
Asymptotic Notations
• Following are commonly used asymptotic notations used in
calculating running time complexity of
• an algorithm.
• Ο Notation
• Ω Notation
• θ Notation
Big Oh Notation, Ο

• The Οn is the formal way to express the upper bound of


an algorithm's running time. It measures the worst case
time complexity or longest amount of time an algorithm
can possibly take to complete.
• If f(n) describes the running time of an algorithm, f(n) is
O(g(n)) if there exist a positive constant C and n0 such
that, 0 ≤ f(n) ≤ cg(n) for all n ≥ n0
• Mathematical Representation of Big-O Notation:
• O(g(n)) = { f(n): there exist positive constants c and n0
such that 0 ≤ f(n) ≤ cg(n) for all n ≥ n0 }
1. Theta Notation (Θ-Notation):

• The θn is the formal way to express both the lower bound and upper
bound of an algorithm's running time. It is represented as following.
• 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.
• Let g and f be the function from the set of natural numbers to itself.
The function f is said to be Θ(g), if there are constants c1, c2 > 0 and a
natural number n0 such that c1* g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0.
• Θ (g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0
≤ c1 * g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0}
3. 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.
• 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 both 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.
• Let g and f be the function from the set of natural numbers to itself.
The function f is said to be Ω(g), if there is a constant c > 0 and a
natural number n0 such that c*g(n) ≤ f(n) for all n ≥ n0
Thank You..

You might also like