1 / 23

Algorithms

Algorithms. Algorithm: what is it ?. Algorithms. Algorithm: what is it ? Some representative problems : Interval Scheduling. Algorithms. Algorithm: what is it ? Some representative problems : Interval Scheduling Bipartite Matching. Algorithms. Algorithm: what is it ?

robertray
Download Presentation

Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms Algorithm: what is it ?

  2. Algorithms • Algorithm: what is it ? • Some representative problems : • Interval Scheduling

  3. Algorithms • Algorithm: what is it ? • Some representative problems : • Interval Scheduling • Bipartite Matching

  4. Algorithms • Algorithm: what is it ? • Some representative problems : • Interval Scheduling • Bipartite Matching • Independent Set

  5. Algorithms • Algorithm: what is it ? • Some representative problems : • Interval Scheduling • Bipartite Matching • Independent Set • Area of a Polygon

  6. Algorithms How to decide which algorithm is better ? Search problem Input : a sequence of n numbers (in an array A) and a number x Output : YES, if A contains x, NO otherwise

  7. Algorithms How to decide which algorithm is better ? Search problem Input : a sequence of n numbers (in an array A) and a number x Output : YES, if A contains x, NO otherwise What if A is already sorted ?

  8. Running Time O(n) – running time of the linear search O(log n) – running time of the binary search Def : Big-Oh (asymptotic upper bound) f(n) = O(g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) · c g(n) Examples : n, n3, log n, 2n, 7n2 + n3/3, 1, 1 + log n, n log n, n + log n

  9. Running Time Def : Big-Oh (asymptotic upper bound) f(n) = O(g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) · c g(n) Example: Prove that n = O(n3)

  10. Running Time Def : Big-Oh (asymptotic upper bound) f(n) = O(g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) · c g(n) Example: Prove that n3 = O(7n2+n3/3)

  11. Running Time Def : Big-Oh (asymptotic upper bound) f(n) = O(g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) · c g(n) Example: Prove that log10 n = O(log n)

  12. Running Time Def : Big-Oh (asymptotic upper bound) f(n) = O(g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) · c g(n) Example: what about 3n and 2n

  13. Running Time O(n) – running time of the linear search O(log n) – running time of the binary search Def : Big-Omega (asymptotic lower bound) f(n) = (g(n)) if there exists a constant c > 0 and a constant n0 such that for every n ¸ n0 we have f(n) ¸ c g(n) Examples : n, n3, log n, 2n, 7n2 + n3/3, 1, 1 + log n, n log n, n + log n

  14. Running Time O(n) – running time of the linear search O(log n) – running time of the binary search Def : Theta (asymptotically tight bound) f(n) = (g(n)) if there exists constants c1, c2 > 0 and a constant n0 such that for every n ¸ n0 we have c1 g(n) · f(n) · c2 g(n) Examples : n, n3, log n, 2n, 7n2 + n3/3, 1, 1 + log n, n log n, n + log n

  15. A survey of common running times Linear • for i=1 to n do • something Also linear : • for i=1 to n do • something • for i=1 to n do • something else

  16. A survey of common running times Example (linear time): Given is a point A=(ax, ay) and n points (x1,y1), (x2,y2), …, (xn,yn) specifying a polygon. Decide if A lies inside or outside the polygon.

  17. A survey of common running times Example (linear time): Given are n points (x1,y1), (x2,y2), …, (xn,yn) specifying a polygon. Compute the area of the polygon.

  18. A survey of common running times Example (linear time): Given are n points (x1,y1), (x2,y2), …, (xn,yn) specifying a polygon. Compute the area of the polygon.

  19. A survey of common running times O(n log n) Or: • for i=1 to n do • for j=1 to log(n) do • something • for i=1 to n do • j=n • while j>1 do • something • j = j/2

  20. A survey of common running times Quadratic • for i=1 to n do • for j=1 to n do • something

  21. A survey of common running times Cubic

  22. A survey of common running times O(nk) – polynomial (if k is a constant)

  23. A survey of common running times Exponential, e.g., O(2k)

More Related