0% found this document useful (0 votes)
4 views6 pages

Disjoint Set and Next

The document discusses various algorithms and concepts in the design and analysis of algorithms, including the Disjoint Set (Union-Find) operations, String Matching algorithms, NP-Complete and NP-Hard problems, and Approximation algorithms. It highlights the applications of string matching in plagiarism detection and bioinformatics, while also explaining the differences between NP-Hard and NP-Complete problems. Additionally, it covers the basics of polynomials and their properties.

Uploaded by

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

Disjoint Set and Next

The document discusses various algorithms and concepts in the design and analysis of algorithms, including the Disjoint Set (Union-Find) operations, String Matching algorithms, NP-Complete and NP-Hard problems, and Approximation algorithms. It highlights the applications of string matching in plagiarism detection and bioinformatics, while also explaining the differences between NP-Hard and NP-Complete problems. Additionally, it covers the basics of polynomials and their properties.

Uploaded by

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

Design and Analysis of Algorithm

Disjoint Set (Union-Find Algorithm)

Two sets are called disjoint sets if they don’t have any element in common, the
intersection of sets is a null set.

A data structure that stores non overlapping or disjoint subset of elements is


called disjoint set data structure. The disjoint set data structure supports
following operations:

• Adding new sets to the disjoint set.

• Merging disjoint sets to a single disjoint set using Union operation.

• Finding representative of a disjoint set using Find operation.

• Check if two sets are disjoint or not.

Operations on Disjoint Set Data Structures:

1. Find

2. Union

1. Find:

Can be implemented by recursively traversing the parent array until we hit a node
that is the parent of itself.

Time complexity: This approach is inefficient and can take O(n) time in worst
case.

2. Union:

It takes two elements as input and finds the representatives of their sets using
the Find operation, and finally puts either one of the trees (representing the set)
under the root node of the other tree.

Time complexity: This approach is inefficient and could lead to tree of length O(n)
in worst case.
Design and Analysis of Algorithm

String Matching Introduction

String Matching Algorithm is also called "String Searching Algorithm." This is a


vital class of string algorithm is declared as "this is the method to find a place
where one is several strings are found within the larger string."

Applications of String Matching Algorithms:

Plagiarism Detection: The documents to be compared are decomposed into


string tokens and compared using string matching algorithms. Thus, these
algorithms are used to detect similarities between them and declare if the work is
plagiarized or original.

Bioinformatics and DNA Sequencing: Bioinformatics involves applying


information technology and computer science to problems involving genetic
sequences to find DNA patterns. String matching algorithms and DNA analysis are
both collectively used for finding the occurrence of the pattern set.

Algorithms of string Matching

• Naive Algorithm: It slides the pattern over text one by one and check
for a match. If a match is found, then slides by 1 again to check for
subsequent matches.

• KMP (Knuth Morris Pratt) Algorithm: The idea is whenever a


mismatch is detected, we already know some of the characters in the
text of the next window. So, we take advantage of this information to
avoid matching the characters that we know will anyway match.

• Rabin Karp Algorithm: It matches the hash value of the pattern with
the hash value of current substring of text, and if the hash values
match then only it starts matching individual characters.

NP Complete Problem

NP Problem:
Design and Analysis of Algorithm

The NP problems set of problems whose solutions are hard to find but easy to
verify and are solved by Non-Deterministic Machine in polynomial time.

NP-Hard Problem:

A Problem X is NP-Hard if there is an NP-Complete problem Y, such that Y is


reducible to X in polynomial time. NP-Hard problems are as hard as NP-Complete
problems. NP-Hard Problem need not be in NP class.

If every problem of NP can be polynomial time reduced to it called as NP Hard.

A lot of times takes the particular problem solve and reducing different
problems.

example :

1. Hamiltonian cycle .

2. optimization problem .

3. Shortest path
NP-Complete Problem:

A problem X is NP-Complete if there is an NP problem Y, such that Y is reducible


to X in polynomial time. NP-Complete problems are as hard as NP problems. A
problem is NP-Complete if it is a part of both NP and NP-Hard Problem. A non-
deterministic Turing machine can solve NP-Complete problem in polynomial
time.

A problem is np-complete when it is both np and np hard combines together.

this means np complete problems can be verified in polynomial time.


Design and Analysis of Algorithm

Difference between NP-Hard and NP-Complete:

NP-hard NP-Complete

NP-Hard problems(say X) can be solved if NP-Complete problems can be


and only if there is a NP-Complete solved by a non-deterministic
problem(say Y) that can be reducible into Algorithm/Turing Machine in
X in polynomial time. polynomial time.

To solve this problem, it do not have to To solve this problem, it must be


be in NP . both NP and NP-hard problems.

Time is known as it is fixed in NP-


Time is unknown in NP-Hard.
Hard.

NP-Complete is exclusively a decision


NP-hard is not a decision problem.
problem.

Not all NP-hard problems are NP- All NP-complete problems are NP-
complete. hard

Do not have to be a Decision problem. It is exclusively a Decision problem.

It is optimization problem used. It is Decision problem used.

Approximation Algorithm
Design and Analysis of Algorithm

An Approximate Algorithm is a way of approach NP-COMPLETENESS for the


optimization problem. This technique does not guarantee the best solution. The
goal of an approximation algorithm is to come as close as possible to the
optimum value in a reasonable amount of time which is at the most polynomial
time. Such algorithms are called approximation algorithm or heuristic algorithm.

Performance Ratios

The main idea behind calculating the performance ratio of an approximation


algorithm, which is also called as an approximation ratio, is to find how close the
approximate solution is to the optimal solution.

The approximate ratio is represented using ρ(n) where n is the input size of the
algorithm, C is the near-optimal solution obtained by the algorithm, C* is the
optimal solution for the problem. The algorithm has an approximate ratio of ρ(n)
if and only if −

max{CC∗,C∗C}≤ρ(n)

Few popular examples of the approximation algorithms are −

• Vertex Cover Algorithm

• Set Cover Problem

• Travelling Salesman Problem (Approximation Approach)

• The Subset Sum Problem

Polynomials and Matrix Calculation


Polynomials are expressions that must contain at least one term. Each term of
a polynomial must contain at least one constant or at least variable and can
contain any number of constants or variables. In each term that has multiple
constants, each value is multiplied together. Exponents on variables must be
positive integers. Terms can only be divided by a constant. Terms of a
polynomial will be added or subtracted together.
Design and Analysis of Algorithm

Example:

X2-3x+2I

You might also like