Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

11 Algorithm

Deterministic algorithms always produce the same output for a given input, while non-deterministic algorithms may produce different outputs for the same input each time they are run. Non-deterministic algorithms cannot solve problems in polynomial time or determine the next step of execution. Prolog is one language that can implement non-deterministic algorithms, but these operators are not part of standard programming languages.

Uploaded by

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

11 Algorithm

Deterministic algorithms always produce the same output for a given input, while non-deterministic algorithms may produce different outputs for the same input each time they are run. Non-deterministic algorithms cannot solve problems in polynomial time or determine the next step of execution. Prolog is one language that can implement non-deterministic algorithms, but these operators are not part of standard programming languages.

Uploaded by

Ujjwal Adhikari
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CHAPTER-11

Algorithms
Deterministic and Non-Deterministic algorithm
In a deterministic algorithm, for a given particular input, the computer will
always produce the same output going through the same states but in the case
of the 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.
To implement a non-deterministic algorithm, we have a couple of languages
like Prolog but these don’t have standard programming language operators
and these operators are not a part of any standard programming languages.
Some of the terms related to the non-deterministic algorithm are defined
below:
choice(X): chooses any value randomly from the set X.
failure(): denotes the unsuccessful solution.
success(): The solution is successful and the current thread terminates.
Deterministic and Non-Deterministic algorithm
Deterministic Algorithm Non-deterministic Algorithm

For a particular input the computer will


For a particular input, the computer will
give different outputs on different
give always the same output.
execution.

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

Cannot determine the next step of


Can determine the next step of execution. execution due to more than one path the
algorithm can take.

Operation are uniquely defined. Operation are not uniquely defined.

Like linear search and binary search like 0/1 knapsack problem.
Divide and Conquer Algorithm
A divide and conquer algorithm is a strategy of solving a large problem by breaking the
problem into smaller sub-problems solving the sub-problems, and combining them to
get the desired output.
How Divide and Conquer Algorithms Work?
Here are the steps involved:
Divide: Divide the given problem into sub-problems using recursion.
Conquer: Solve the smaller sub-problems recursively. If the sub problem is small
enough, then solve it directly.
Combine: Combine the solutions of the sub-problems that are part of the recursive
process to solve the actual problem.
Let the given array be:
Divide and Conquer Algorithm
Divide the array into two halves.

Again, divide each subpart recursively into two halves until you get individual
elements.
Divide and Conquer Algorithm
Now, combine the individual elements in a sorted manner. Here, conquer and combine
steps go side by side.
Divide and Conquer Algorithm
Divide and Conquer Algorithm
Serial and parallel Algorithm
In computer science, a parallel algorithm, as opposed to a traditional serial algorithm, is an
algorithm which can do multiple operations in a given time. It has been a tradition of computer
science to describe serial algorithms in abstract machine models, often the one known as random-
access machine.
For example, take a look at Merge Sort, its normal recursive implementation is already a parallel
algorithm (therefore merge sort is embarrassingly parallel). Note that with n threads, the time
complexity of merge sort will be O(log n) instead of O(n log n).
Serial algorithms are algorithms that are not parallel algorithms (i.e. it doesn't allow parallel
processing)
For example if you want to find maximum element of an array, you can do it as follow:
a = [2, 4, 3, 2]
ans = k
For i From 0 To Len(a) - 1
ans = Max(ans, a[i])
Return ans
There is no way for the compiler/interpreter to run this as parallel because it is iterative. It's
nature is to run sequentially
Heuristic and approximation algorithm
A heuristic is a technique designed for solving a problem more quickly when classic methods are
too slow. The objective of a heuristic is to produce quickly enough a solution that is good enough
for solving the problem at hand. ".
Heuristic could derive from theory or experimental experience, but approximation algorithms
have solid theory foundation (provable solution).
A heuristic is essentially a hunch is a heuristic. As is solving the traveling salesman problem by
starting at a random vertex and going to the nearest not yet visited each step. It is a plausible
idea, that should not give a too bad solution. In this case, it can be shown that it won't always
give a good solution.
An approximation algorithm is usually understood to give an approximate solution, with some
kind of guarantee of performance.
An approximation algorithm is a way of dealing with NP-completeness for an optimization
problem. This technique does not guarantee the best solution. The goal of the approximation
algorithm is to come as close as possible to the optimal solution in polynomial time.
 An approximation algorithm guarantees to run in polynomial time though it does not
guarantee the most effective solution.
 An approximation algorithm guarantees to seek out high accuracy and top quality
solution(say within 1% of optimum)
 Approximation algorithms are used to get an answer near the (optimal) solution of an
optimization problem in polynomial time

You might also like