Computational Complexity
Abhishek De Chennai Mathematical Institute What is complexity?
Before that, we need to know what is the difference between:
Problem
Problem Instances
Algorithm PROBLEM: A problem is an unsolved question proposed to us. It contains an abstract description, probably a real-life situation.
Examples:
. Gi e toda s hu idit , ill it ai toda ? . What is the minimum time required to reach from my house to ISI during rush-hour? . Is 2004 a leap year? . What is the average score of Gambhir in IPL-7 given the list of his scores?
Types of problems • Returns a Boolean value. Decision (True or False) Problems •
• Returns a single output which could be of any Functional type. Problems • More tougher to study than decision problems. Class of all Problems • Searches for a structure 'y' in an object 'x'. Search • Also p odu es a it ess Problems if search is successful. (Sometimes this is a separate problem.)
• Given a set of parameters Optimization p o ides the est Problems possi le solutio hopefully without exhausting all cases. PROBLEM INSTANCE: The instance is a particular input to the problem, and the solution is the output corresponding to the given input. For example, consider the problem of primality testing. The instance is a number (say, 15) and the solution is "no". Thus the input string for a problem is referred to as a problem instance, and should not be confused with the problem itself because a particular instance cannot in general shed light on the ge eral approach to solve the problem.
Note that a problem can be viewed as an infinite collection of instances together with a solution for every instance i.e. the problem is solved if every (instance, solution) pair is known. ALGORITHM: An algorithm is an effective step-by-step method expressed as a finite list of well-defined instructions to solve a problem. Loosely speaking, it is the ge e al app oa h to sol e the p o le hi h works for any instance of the problem.
For example: Euclid’s Algorith to calculate the g.c.d of two numbers is one of the most algorithms. Types of Algorithms
• Same set of inputs render Deterministic same sets of outputs. • Probability of success is 1.
Algorithms
• Uses randomness to guide its behaviour. Same set of inputs may give Randomized • different set of outputs • Probability of success is not trivially 1. Finally, what is complexity?
Suppose you have two algorithms A and B to solve a problem. You a t to use the ette o e. What is the ea i g of a ette algorithm?
We sa , A is ette tha B if o ple it of A is less tha o ple it of B .
Definition. (Complexity) : Computational Complexity of an algorithm is the number of steps required to complete the task given the size of the input parameter, quantifying the amount of resources needed to solve them, such as time and storage.
Input parameter
Input parameter is the parameter which quantifies the complexity. The complexity is only the function of the input parameter.
“uppose ou e so ti g a a a . The u e of steps e ui ed will solely depend on the number of elements in the array. So input parameter is the size of the array.
Again, for number-theoretic algorithms, the input parameter is the measure of how big the number is. So it is number of bits occupied by the number.
Complexity Models
Temporal Spatial
• Temporal – Time required to complete the task • Space – Space/ Memory required to complete the task • Other complexity measures are also used, such as the amount of communication, the number of gates in a circuit and the number of processors . Thus one of the roles of complexity theory is to determine the practical limits on what computers can and cannot do. For example it is easy to estimate using complexity that even with the latest technology it is impossible to calculate 280.
(Here we will only discuss time complexity) Program running time – Why?
When is the running time (waiting time for user) noticeable/important?
• web search • database search • real-time systems with time constraints • Gene matching (DNA searches)
Performance is NOT Complexity
• Since we have now come into the realm of time complexity, there is an a priori notion that the faster a program is, the lesser complexity it has. Well, not always. • Running time depends on a lot of things like memory, disk space, which depend on machine, compiler, etc. This is the pe fo a e of the algorithm. • Complexity should be independent of CPU time and implementation. • Thus complexity affects performance but not the other way around.
The Big-Oh notation • Look at the picture along- side. Similarly we need to compare the theoretic running time of two algorithms. • Let f(x) and g(x) be the running time of two algorithms, where x is the input parameter. • f(x) = O(g(x)) if there exists constant c and k such that f(x) cg(x) for all x k.