np_complete

# np_complete - Np-complete Introduction There are two types...

This preview shows pages 1–4. Sign up to view the full content.

Software Engineering Abdelghani Bellaachia Page 1 Np-complete Np-complete ˜ Introduction: There are two types of problems: ü Problems whose time complexity is polynomial: O(logn), O(n), O(nlogn), O(n 2 ), O(n 3 ) Examples: searching, sorting, merging, MST, etc. ü Problems with exponential time complexity: O(2 n ), O(n!), O(n n ), etc. Examples: TSP, n-queen, 0/1knapsack, etc. Two classes of algorithms: ü P: The set of all problems, which can be solved by deterministic algorithms in polynomial time. ü NP: The set of all problems which can be solved by nondeterministic algorithms in polynomial time (NP: Nondeterministic Polynomial)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Software Engineering Abdelghani Bellaachia Page 2 ˜ Non-deterministic algorithms: Unlike deterministic algorithms, each operation has several outcomes Example: ü x = choice(1. .n); ü x may have any value between 1 and n ü The time of this type of instruction is O(1). ü If there is a solution, the algorithm will terminate successfully; otherwise, it will terminate unsuccessfully. ˜ Example1: Searching problem: input: A(1. .n) and x Output: index j such that A(j)=x if x is in A or j=0 if x does not belong to A. Ndsearch(A(1. .n), x) Integer j; Begin J=choice(1. .n); If A(j) =x Then Print(j); Else Print(0); Endif; End; ü The complexity is O(1);
Software Engineering Abdelghani Bellaachia Page 3 ˜

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

np_complete - Np-complete Introduction There are two types...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online