Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm Complexity By: Ashish Patel and Alex Golebiewski.

Similar presentations


Presentation on theme: "Algorithm Complexity By: Ashish Patel and Alex Golebiewski."— Presentation transcript:

1 Algorithm Complexity By: Ashish Patel and Alex Golebiewski

2 Outline Complexity of Algorithms Complexity Classes Tractable and Intractable Traveling Salesman Problem Knapsack Problem

3 Complexity of Algorithms The complexity of an algorithms deals with the problem of how much time is required for completion and the amount of space it uses. Measurement is in terms of input size.

4 Why Complexity is Important 283264 log n1 sec3 sec5 sec6 sec n2 sec8 sec32 sec64 sec nlogn2 sec24 sec2.67 min6.4 min n2n2 4 sec64 sec17.07 min1.14 hrs n3n3 8 sec8.53 min9.1 hrs3.03 days 2n2n 4 sec4.27 min1.36 cent5x10 9 cent n!2 sec4.2 hrs8x10 25 cent 4x10 79 cent

5 Complexity Classes Set of computational problems with the same bounds on time and space. Tractable (solvable in polynomial time) –P Intractable (not solvable in polynomial time) –NP –NP-Complete –NP-Hard Unsolvable (cannot be solved by a computer)

6 Complexity Classes P Intractable Not solvable NP NP-CompleteNP-Hard

7 P The set of concrete decision problems that are solvable in polynomial time Problems that include those with reasonably efficient algorithms If a problem is not in P, it will be extremely expensive and probably impossible to solve in practice

8 NP NP stands for “non-deterministic polynomial” Class of decision problems solved by a non-deterministic polynomial algorithm Non-deterministic polynomial Algorithm –Guess potential solution –Verify solution in polynomial time

9 NP - Complete NP–complete is the term used to describe decision problems that are the hardest ones in NP in the sense that, if there were a polynomial algorithm for an NP- complete problem, then there would be a polynomial algorithm for every problem in NP. A problem is NP-complete if: –It is in NP and all other problems in NP can be reduced to it in polynomial time An examples of NP-complete problems are the Traveling Salesman, the Knapsack problem, Hamiltonian Circuit, CNF-Satisfiability, etc.

10 NP - Hard Class of decision problems harder than those that can be solved by a non- deterministic polynomial algorithm If decision version of optimization problem is in NP-Complete, then optimization is NP-Hard

11 Unsolvable Any problem that cannot be solved by any means through the use of a computer. Example: The Halting problem

12 Approximation Algorithms An algorithm that seems to work well for the inputs that usually occur. The strategies, or heuristics, used by many of the approximation algorithms are simple and straightforward, yet for some problems they provide surprisingly good results.

13 Hamiltonian Circuit A Hamiltonian Circuit, in a graph or digraph, is a path (cycle) that starts and ends ate the same vertex and passes through every vertex exactly once Hamiltonian Circuit Problem: Determine whether a given graph has a Hamiltonian Circuit.

14 Traveling Salesman Problem (TSP) Optimization Problem: Given a weighted graph, find a minimum weighted Hamiltonian Circuit. (NP- Hard) Decision Problem: Given a weighted graph and an integer k, is there a Hamiltonian Circuit with total weight at most k? (NP-complete) This problem is widely known as the Traveling Salesman problem; the salesman wants to minimize total traveling while visiting all the cities in a territory. Other applications include routing trucks for garbage pickup and package deliver. General Solution is of Factorial Complexity

15 12 34 3 65 4 9 8 12 34 3 65 4 9 8 12 34 3 65 4 9 8 12 34 3 65 4 9 8 1  2  4  3  1 = 3 + 5 + 4 + 6 = 18 1  4  3  2  1 = 9 + 4 + 8 + 3 = 24 1  3  2  4  1 = 6 + 8 +5 +9 = 28 Can also be reversed with same cost *** optimal ***

16 Knapsack Problem Let C = capacity of knapsack (positive) and S = set of objects with assigned “sizes/weights” and “values” (all positive) Optimization Problem: Find the largest valued subset of S that fits in the knapsack of capacity C Decision Problem: Given value K, is there a subset of S that fits in the knapsack of capacity C and has a total value at least K? This problem is mostly exemplified by a robber with a limited size bag stealing items from someone. He wants to get the most value he can inside the bag.

17 ItemValueWeight TV$250.00100lbs Jewelry$1000.0 0 30lbs Clothes$100.0050lbs Piano$2000.0 0 300lbs Couch$200.00150lbs ItemValueWeight Piano$2000.00300lbs Total=$2000.00300lbs T weight = 300lbs ItemValueWeight Couch$200.00150lbs TV$250.00100lbs Jewelry$1000.0030lbs Total=$1450.00270lbs ItemValueWeight Couch$200.00150lbs TV$250.00100lbs Clothes$100.0050 Total=$550.00300lbs *** OPTIMAL***

18 Applause!!! Clap Clap Clap Clap Clap


Download ppt "Algorithm Complexity By: Ashish Patel and Alex Golebiewski."

Similar presentations


Ads by Google