Lecture-16_student
Lecture-16_student
Algorithms
x y( x y )
x( | x )
1 Chapter 3
x 1
x
?
x 1
x ?
RIZOAN TOUFIQ
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY
Complexity of Algorithms
Section 3.3
Section Summary
Time Complexity
Worst-Case Complexity
Algorithmic Paradigms
Understanding the Complexity of Algorithms
The Complexity of Algorithms
Note: There is no need to compute the square root, since the square of the distance
between two points is smallest when the distance is smallest.
Continued →
Computing the Closest Pair of
Points by Brute-Force
Algorithm for finding the closest pair in a set of n points.
procedure closest pair((x1, y1), (x2, y2), … ,(xn, yn): xi, yi real numbers)
min = ∞
for i := 1 to n
for j := 1 to i
if (xj − xi)2 + (yj − yi)2 < min
then min := (xj − xi)2 + (yj − yi)2
closest pair := (xi, yi), (xj, yj)
return closest pair
The algorithm loops through n(n −1)/2 pairs of points, computes the
value (xj − xi)2 + (yj − yi)2 and compares it with the minimum, etc.
So, the algorithm uses Θ(n2) arithmetic and comparison operations.
We will develop an algorithm with O(log n) worst-case complexity in
Section 8.3.
Understanding the Complexity
of Algorithms
Understanding the Complexity
of Algorithms
The P versus NP problem asks whether the class P = NP? Are there
problems whose solutions can be checked in polynomial time, but can
not be solved in polynomial time?
– Note that just because no one has found a polynomial time algorithm is different
from showing that the problem can not be solved by a polynomial time
algorithm.
If a polynomial time algorithm for any of the problems in the NP
complete class were found, then that algorithm could be used to obtain
a polynomial time algorithm for every problem in the NP complete
class.
– Satisfiability (in Section 1.3) is an NP complete problem.
It is generally believed that P≠NP since no one has been able to find a
polynomial time algorithm for any of the problems in the NP complete class.
The problem of P versus NP remains one of the most famous unsolved
problems in mathematics (including theoretical computer science). The Clay
Mathematics Institute has offered a prize of $1,000,000 for a solution.
Stephen Cook
(Born 1939)
Query???
x 1 x ? 1
x 1
x
?
1
1 2 3 4.... ?
1 1 1 1 1......... ?
x 1
x
?