Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Complexity. בעיה פשוטה במיוחד סדר שלושה מספרים לפי סדר מונוטוני עולה יש למישהו רעיון?

Similar presentations


Presentation on theme: "Introduction to Complexity. בעיה פשוטה במיוחד סדר שלושה מספרים לפי סדר מונוטוני עולה יש למישהו רעיון?"— Presentation transcript:

1 Introduction to Complexity

2 בעיה פשוטה במיוחד סדר שלושה מספרים לפי סדר מונוטוני עולה יש למישהו רעיון?

3 אלגוריתם א' אם A גדול מ-B, ו- B גדול מ-C, אז הדפס A,B,C אם A גדול מ-C, ו- C גדול מ-B, אז הדפס A,C,B אם B גדול מ-A, ו-A גדול מ-C, אז הדפס B,A,C אם B גדול מ-C, ו-C גדול מ-A, אז הדפס B,C,A אם C גדול מ-A, ו-A גדול מ-B, אז הדפס C,A,B אם C גדול מ-B, ו-B גדול מ-A, אז הדפס C,B,A

4 אלגוריתם ב' אם A גדול מ-B אם B גדול מ-C, הדפס A,B,C אחרת, אם A גדול מ-C הדפס A,C,B אחרת, הדפס C,A,B אחרת אם C גדול מ-B, הדפס C,B,A אחרת, אם A גדול מ-C הדפס B,A,C אחרת, הדפס B,C,A

5 איזה פתרון יותר טוב? נריץ בראש על כמה מספרים ונבדוק שעובד? נראה בכמה משתנים כל אלגוריתם משתמש? ננסה על מספר מחשבים? יוסי יבדוק את אלגוריתם א' על ה-Macintosh שלו יונית תבדוק את אלגוריתם ב' על ה-Pentium במעבדה

6 השוואת אלגוריתמים היחידה הבסיסית (במקרה זה): השוואה בין שני מספרים ככל שיש יותר השוואות, לוקח יותר זמן להגיע לתשובה

7 אלגוריתם א' אם A גדול מ-B, ו- B גדול מ-C, אז הדפס A,B,C אם A גדול מ-C, ו- C גדול מ-B, אז הדפס A,C,B אם B גדול מ-A, ו-A גדול מ-C, אז הדפס B,A,C אם B גדול מ-C, ו-C גדול מ-A, אז הדפס B,C,A אם C גדול מ-A, ו-A גדול מ-B, אז הדפס C,A,B אם C גדול מ-B, ו-B גדול מ-A, אז הדפס C,B,A

8 השוואת אלגוריתמים היחידה הבסיסית (במקרה זה): השוואה בין שני מספרים ככל שיש יותר השוואות, לוקח יותר זמן להגיע לתשובה אלגוריתם א': במקרה הטוב: 2 במקרה הרע: 10 בממוצע: 5 (לא 6!)

9 אלגוריתם ב' אם A גדול מ-B אם B גדול מ-C, הדפס A,B,C אחרת, אם A גדול מ-C הדפס A,C,B אחרת, הדפס C,A,B אחרת אם C גדול מ-B, הדפס C,B,A אחרת, אם A גדול מ-C הדפס B,A,C אחרת, הדפס B,C,A

10 השוואת אלגוריתמים היחידה הבסיסית (במקרה זה): השוואה בין שני מספרים ככל שיש יותר השוואות, לוקח יותר זמן להגיע לתשובה אלגוריתם א': במקרה הטוב: 2 במקרה הרע: 10 בממוצע: 5 (לא 6!) אלגוריתם ב': במקרה הטוב: 2 במקרה הרע: 3 בממוצע: 2.666

11 אלגוריתמים כבסיס לתוכנה מהו אלגוריתם? סידרה סופית של פעולות לביצוע הפותרות בעיה אלגוריתמית מהי בעיה אלגוריתמית? הגדרת אוסף קלטים חוקיים הגדרת פלטים רצויים (פונקציה של הקלטים) לא כל הבעיות האלגוריתמיות ניתנות לפיתרון אלגוריתם מתאר בבהירות תהליך: הופך קלט חוקי לפלט חוקי ומסיים.

12 אלגוריתמים? ברמזור הבא פני ימינה ואז תמשיך שלושה-ארבעה ק"מ ברמזור הבא פנה ימינה ואז אתה כבר באזור. תשאל שם. קח שלוש כפיות סוכר. ערבב בתוך כוס מים רותחים. מיין את רשימת המספרים. הדפס את האיבר הראשון. בצע: 1. בחר רנדומלית מספר בין 3 ל-5. 2. אם המספר גדול מ-4, הדפס "יש", אחרת חזור ל-1 3. חזור ל-1

13 למה צריך אלגוריתמים? אם אוסף הקלטים החוקי הוא אינסופי או גדול מאד כל הרשימות האפשריות של מספרים השלמים אם אוסף הפלטים החוקי הוא אינסופי או גדול מאד לדוגמא: 300 מליון הספרות הראשונות של פאי אחרת, אפשר פשוט להשתמש בטבלה!

14 מדידת איכות של תוכנה איכות של תוכנית נמדדת במדדים שונים: קלות התחזוקה של התוכנית מודולריות ואפשרות השימוש בתוכנית למטרות שונות יעילות התוכנית בזמן ריצה ובשימוש בזיכרון בקורס זה אנו מתמקדים במדדי יעילות המטרה: ניתוח יעילות של אלגוריתמים (סיבוכיות) לא להיות תלויים במדידות אמפיריות שלא מאפשרות השוואה כגון: "התוכנה סיימה בתוך 1.3 שניות על מחשב פנטיום עם MB256 זיכרון פנימי"

15 ניתוח סיבוכיות (Complexity) זיכרון וזמן ריצה Worst Case Average Case Best Case פונקציה של: גודל הקלט בביטים, במספר המרכיבים (לדוגמא במיון),... מודל המחשוב: מעבד מרכזי, זיכרון מרכזי מסוג RAM מחיר פעולה בסיסית: השוואה, חישוב אריתמטי,....

16 חישוב יעיל נסמן את זמן הריצה של אלגוריתם ב-T(n) ואת הזיכרון הנדרש ב-S(n) N הינו גודל הקלט לדוגמא: בעיית חיפוש מספר במערך קלט: מערך A בגודל n המכיל מספרים; מספר k לחיפוש פלט: אם k נמצא במקום ה-i, החזר i, אחרת החזר Nil.

17 חיפוש איבר במערך 1. For i  1 to n 2. If A[i] = k 3. return i 4. return Nil Best Case: When k = A[1], search is over as soon as begun T(n) = C (C is a constant) C = time to do i  1 + time to compare to n + time to compare to k + …

18 חיפוש איבר במערך 1. For i  1 to n 2. If A[i] = k 3. return i 4. return Nil Worst Case: When k not in A[], search goes through entire list T(n) = C+B+B+B+…. +D (C,B,D constants) n times = C+n*B+D

19 חיפוש איבר במערך 1. For i  1 to n 2. If A[i] = k 3. return i 4. return Nil Average Case: Let Ti be the time it takes to find k when in A[i] Suppose k can be in any place i, or outside of A[] With uniform distribution T(n) = (T1+T2+T3+ …. Tn) / n =

20 פונקציות אסימפטוטיות עכשיו יש לנו זמני ריצה נתונים בקבועים C,B,D הקבועים ישתנו בין מחשבים אז איך נוכל להשוות בין אלגוריתמים בעלי קבועים שונים או פונקציות T(n) שונות? לצורך כך אנו משתמשים בפונקציות אסימפטוטיות: O (או-גדול Big-O) (אומגה-גדול Big-Omega) (טתה- גדול Big-Theta) פונקציות אסימפטוטיות מאפיינות סדר גודל – התנהגות הפונקציה כשגודל הקלט עולה

21 Big – O: חסם עליון Definition : if there exists constants c>0 and n0 such that for all n>n0, In other words, g(n) bounds f(n) from above (for large n’s) up to a constant. Examples: בתודה למתרגל אלמוני באוניברסיטה העברית על השקופית

22 1000 3000 2000 משמעות סדרי גודל: דוגמא בתודה למרצה באוניברסיטת תל אביב על השקופית שימו לב

23 השוואת סדרי גודל מספר השניות מאז המפץ הגדול -- מספר בן 24 ספרות מספר הפרוטונים ביקום – מספר בן 80 ספרות בתודה לד"ר מירב חדד וראובן קאשי 101001000 1111 log 10 n123 n101001000 n2n2 1001000010 6 2n2n 1024מספר בן 31 ספרותמספר בן 302 ספרות n!36x10 6 מספר בן 161 ספרותמספר גדול באמת

24 למה משתמשים במדדים אסימפטוטיים? כיון שהם לא משתנים גם אם המחשבים נעשים מהירים יותר, או שפת התכנות משתפרת מסתירים את הקבועים המאפיינים מחשב מסויים מבליטים את אופן התנהגות האלגוריתם בקלט גדול זה גם חיסרון עבורנו כמהנדסים – למה?

25 Big – Omega חסם תחתון: Definition : if there exists constants c>0 and n0 such that for all n>n0, In other words, g(n) bounds f(n) from below (for large n’s) up to a constant. Examples: בתודה למתרגל אלמוני באוניברסיטה העברית על השקופית

26 Big – Theta: חסם עליון ותחתון Definition : if: and In other words, g(n) is a tight estimate of f(n) (in asymptotic terms). Examples: בתודה למתרגל אלמוני באוניברסיטה העברית על השקופית

27 cg(n) f(n) n0n0 cg(n) n0n0 f(n) c 2 g(n) c 1 g(n) n0n0 ציור מדדי סיבוכיות בתודה למרצה באוניברסיטת תל אביב על השקופית

28 חיפוש איבר במערך 1. For i  1 to n 2. If A[i] = k 3. return i 4. return Nil Best Case: T best (n) = C = O(1) Worst Case: T worst (n) = C+n*B+D = O(n) Average Case: T average (n) <= C(n+C)/2 = O(n)

29 Complexity and Performance Some algorithms are better than others for solving the same problem We can’t just measure run-time, because the number will vary depending on what language was used to implement the algorithm, how well the program was written how fast the computer is how good the compiler is how fast the hard disk was…

30 Basic idea: counting operations Each algorithm performs a sequence of basic operations: Arithmetic: (low + high)/2 Comparison: if ( x > 0 ) … Assignment: temp = x Looping: while ( true ) { … } … Idea: count the number of basic operations performed on the input

31 It Depends Difficulties: Which operations are basic? Not all operations take the same amount of time Operations take different times with different hardware or compilers

32 Sample running times of basic Java operations (ran them in a loop…) Loop Overhead ; 196 10 Double division d = 1.0 / d; 400 77 Method call o.m(); 372 93 Object Constructiono=new SimpleObject(); 1080 110 Sys1: PII, 333MHz, jdk1.1.8, -nojit Sys2: PIII, 500MHz, jdk1.3.1 Operation Loop Body nSec/iteration Sys1 Sys2

33 So instead… We use mathematical functions that estimate or bound: the growth rate of a problem’s difficulty, or the performance of an algorithm Our Motivation: analyze the running time of an algorithm as a function of only simple parameters of the input

34 Asymptotic Running Factors Operation counts are only problematic in terms of constant factors. The general form of the function describing the running time is invariant over hardware, languages or compilers! public static int myMethod(int n) { int sq = 0; for(int j=0; j < n ; j++) for(int k=0; k < n ; k++) sq++; return sq; } Running time is “about” n 2 We use “Big-O” notation, and say that the running time is O(n 2 )

35 The Problem’s Size The problem’s size is stated in terms of n, which might be: the number of components in an array the number of items in a file the number of pixels on a screen the amount of output the program is expected to produce

36 Example Linear growth in complexity (searching an array, one component after another, to find an element): n number of components time to perform the search

37 Another example Polynomial growth: the quadratic growth of the problem of visiting each pixel on the screen, where n is the length of a side of the screen: n length of the side of the screen time to visit all pixels n2n2 polynomial

38 Does this matter? Yes!!! Even though computers get faster at an alarming rate, the time complexity of an algorithm still has a great affect on what can be solved Consider 5 algorithms, with time complexity log 2 N N N log 2 N N 2 2 N

39 Asymptotic Behavior of (Some) Functions

40 Some Numbers Consider 5 algorithms, with time complexity n n log 2 n n 2 n 3 2 n

41 Limits on problem size as determined by growth rate AlgorithmTimeMaximum problem size Complexity1 sec 1 min1 hour A 1 n 1000 6 x 10 4 3.6 x 10 6 A 2 n log 2 n 140 48932.0 x 10 5 A 3 n 2 31 244 1897 A 4 n 3 10 39 153 A 5 2 n 9 15 21 Assuming one unit of time equals one millisecond.

42 Effect of tenfold speed-up AlgorithmTimeMaximum problem size Complexity before speed-upafter speed-up A 1 n s 1 10s 1 A 2 n log 2 n s 2 Approx. 10s 2 (for large s 2 ) A 3 n 2 s 3 3.16s 3 A 4 n 3 s 4 2.15s 4 A 5 2 n s 5 s 5 + 3.3

43 Functions as Approximations formnamemeaning for very big n Task (n) =  (f(n))‘omega’f(n) is underestimate or lower bound Task (n) = ~(f(n))‘tilde’f(n) is almost exactly correct Task (n) = O(f(n))‘big O’f(n) is an overestimate or upper bound Task (n) = o(f(n))‘little o’f(n) increasingly overestimates

44 Big O Notation Big O notation is the most useful for us; it says that a function f(n) serves as an upper bound on real-life performance. For algorithm A of size n (informally): The complexity of A(n) is on the order of f(n) if A(n) is less than or equal to some constant times f(n) The constant can be anything as long as the relation holds once n reaches some threshold.

45 Big O Notation A( n ) is O(f( n )) as n increases without limit if there are constants C and k such that A( n )  C*f( n ) for every n > k This is useful because is focuses on growth rates. An algorithm with complexity n, one with complexity 10 n, and one with complexity 13 n + 73, all have the same growth rate. As n doubles, cost doubles. (We ignore the “73”, because we can increase 13 to 14, i.e., 14 n  13 n + 73 for all n  73.)

46 Big O Notation This is a mathematically formal way of ignoring constant factors, and looking only at the “shape” of the function A=O(f) should be considered as saying that “A is at most f, up to constant factors” We usually will have A be the running time of an algorithm and f a nicely written function. E.g. The running time of the algorithm on the right is O(n 2 ) public static int myMethod(int n) { int sq = 0; for(int j=0; j < n ; j++) for(int k=0; k < n ; k++) sq++; return sq; }

47 Properties of the O notation Constant factors may be ignored   k > 0  kf  is  O( f)

48 Properties of the O notation Constant factors may be ignored   k > 0  kf  is  O( f) Higher powers grow faster n r  is  O( n s ) if 0  r  s

49 Properties of the O notation Constant factors may be ignored   k > 0  kf  is  O( f) Higher powers grow faster n r  is  O( n s ) if 0  r  s ç Fastest growing term dominates a sum If f is O(g), then f + g is O(g) eg an 4 + bn 3 is O(n 4 )

50 Properties of the O notation Constant factors may be ignored   k > 0  kf  is  O( f) Higher powers grow faster n r  is  O( n s ) if 0  r  s ç Fastest growing term dominates a sum If f is O(g), then f + g is O(g) eg an 4 + bn 3 is O(n 4 ) ç Polynomial’s growth rate is determined by leading term If f is a polynomial of degree d, then f is O(n d )

51 Properties of the O notation f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h)

52 Properties of the O notation f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h) Product of upper bounds is upper bound for the product If f is O(g) and h is O(r)  then fh is O(gr)

53 Properties of the O notation f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h) Product of upper bounds is upper bound for the product If f is O(g) and h is O(r)  then fh is O(gr) Exponential functions grow faster than powers n k  is  O( b n )  b > 1 and k  0 eg n 20 is O( 1.05 n )

54 Properties of the O notation f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h) Product of upper bounds is upper bound for the product If f is O(g) and h is O(r)  then fh is O(gr) Exponential functions grow faster than powers n k  is  O( b n )  b > 1 and k  0 eg n 20 is O( 1.05 n ) Logarithms grow more slowly than powers log b n  is  O( n k )  b > 1 and k  0 eg log 2 n is O( n 0.5 )

55 Properties of the O notation f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h) Product of upper bounds is upper bound for the product If f is O(g) and h is O(r)  then fh is O(gr) Exponential functions grow faster than powers n k  is  O( b n )  b > 1 and k  0 eg n 20 is O( 1.05 n ) Logarithms grow more slowly than powers log b n  is  O( n k )  b > 1 and k  0 eg log 2 n is O( n 0.5 ) Important!

56 Properties of the O notation All logarithms grow at the same rate log b n is O(log d n)  b, d > 1

57 Properties of the O notation All logarithms grow at the same rate log b n is O(log d n)  b, d > 1 Sum of first n r th powers grows as the (r+1) th power   k r  is   ( n r+1 ) eg  i = is  ( n 2 ) k=1 n n n(n+1) 2

58 Polynomial and Intractable Algorithms Polynomial Time complexity An algorithm is said to be polynomial if it is O( n d ) for some integer d Polynomial algorithms are said to be efficient They solve problems in reasonable times! Intractable algorithms Algorithms for which there is no known polynomial time algorithm We will come back to this important class later in the course

59 Analysing an Algorithm Simple statement sequence s 1 ; s 2 ; …. ; s k O(1) as long as k is constant Simple loops for(i=0;i<n;i++) { s; } where s is O(1) Time complexity is n O(1) or O(n) Nested loops for(i=0;i<n;i++) for(j=0;j<n;j++) { s; } Complexity is n O(n) or O(n 2 ) This part is O(n)

60 Analysing an Algorithm Loop index doesn’t vary linearly h = 1; while ( h <= n ) { s; h = 2 * h; } h takes values 1, 2, 4, … until it exceeds n There are 1 + log 2 n iterations Complexity O(log n)

61 Analysing an Algorithm Loop index depends on outer loop index for(j=0;j<n;j++) for(k=0;k<j;k++){ s; } Inner loop executed 1, 2, 3, …., n times  Complexity O(n 2 ) n  i = i=1i=1 n(n+1) 2 Distinguish this case - where the iteration count increases (decreases) by a constant ç O(n k ) from the previous one - where it changes by a factor ç O(log n)

62 Asymptotic Analysis of Algorithms We usually embark on an asymptotic worst case analysis of the running time of the algorithm. Asymptotic: Formal, exact, depends only on the algorithm Ignores constants Applicable mostly for large input sizes Worst Case: Bounds on running time must hold for all inputs Thus the analysis considers the worst-case input Sometimes the “average” performance can be much better Real-life inputs rarely “average” in any formal sense

63 Worst Case/Best Case Worst case performance measure of an algorithm states an upper bound Best case complexity measure of a problem states a lower bound; no algorithm can take less time

64 Multiplicative Factors Because of multiplicative factors, it’s not always clear that an algorithm with a slower growth rate is better If the real time complexities were A 1 = 1000n, A 2 = 100nlog 2 n, A 3 = 10n 2, A 4 = n 3, and A 5 = 2 n, then A 5 is best for problems with n between 2 and 9, A 3 is best for problems with n between 10 and 58, A 2 is best for n between 59 and 1024, and A 1 is best for bigger n.

65 An Example: Binary Search Binary search splits the unknown portion of the array in half; the worst- case search will be O(log 2 n) Doubling n only increases the logarithm by 1; growth is very slow

66 Example: Insertion Sort (reminder) 182235978455611047 starting order: 18 22 35 97 84 55611047 move through the array, keeping the left side ordered; when we find the 35, we have to slide the 18 over to make room: 182235978455 611047 continue moving through the array, always keeping the left side ordered, and sliding values over as necessary to do so: 18 slid over

67 Example: Insertion Sort Sum from 1 to N would be: (N*(N+1))/2 So sum from 1 to N-1 is ((N-1)*N)/2 Worst case for insertion sort is thus N 2 /2 – N/2 In other words, O(N 2 )

68 Asymptotic Behavior of (Some) Functions N grows much slower than N 2, so we ignore the N term

69 Selection Sort and Bubble Sort Similar analyses tell us that both Selection Sort and Bubble Sort have time complexity of O(N 2 ) Selection Sort Bubble Sort

70 Some Complexity Examples For each of the following examples: 1. What task does the function perform? 2. What is the time complexity of the function? 3. Write a function which performs the same task but which is an order-of-magnitude (not a constant factor) improvement in time complexity

71 Example 1 public int someMethod1 (int[] a) { int temp = 0; for (int i=0; i temp) temp = Math.abs(a[j]-a[i]); return temp; }

72 Example 1 1.Finds maximum difference between two values in the array public int someMethod1 (int[] a) { int temp = 0; for (int i=0; i temp) temp = Math.abs(a[j]-a[i]); return temp; }

73 Example 1 1.Finds maximum difference between two values in the array 2.O(n 2 ) public int someMethod1 (int[] a) { int temp = 0; for (int i=0; i temp) temp = Math.abs(a[j]-a[i]); return temp; }

74 Example 1 public int someMethod1 (int[] a) { int temp = 0; for (int i=0; i temp) temp = Math.abs(a[j]-a[i]); return temp; } 1.Finds maximum difference between two values in the array 2.O(n 2 ) 3.Find the max and min values in the array, then subtract one from the other – the problem will be solved in O(n)

75 Example 2: a[ ] is sorted in increasing order, b[ ] is not sorted public boolean someMethod2(int[] a, int[] b) { for (int j=0; j < b.length; j++) for (int i=0; i < a.length-1; i++) if (b[j] == a[i] + a[i+1]) return true; return false; }

76 Example 2: a[ ] is sorted in increasing order, b[ ] is not sorted 1.Checks whether a value in b[ ] equals the sum of two consecutive values in a[ ] public boolean someMethod2(int[] a, int[] b) { for (int j=0; j < b.length; j++) for (int i=0; i < a.length-1; i++) if (b[j] == a[i] + a[i+1]) return true; return false; }

77 Example 2: a[ ] is sorted in increasing order, b[ ] is not sorted 1.Checks whether a value in b[ ] equals the sum of two consecutive values in a[ ] 2.O(n 2 ) public boolean someMethod2(int[] a, int[] b) { for (int j=0; j < b.length; j++) for (int i=0; i < a.length-1; i++) if (b[j] == a[i] + a[i+1]) return true; return false; }

78 Example 2: a[ ] is sorted in increasing order, b[ ] is not sorted 1.Checks whether a value in b[ ] equals the sum of two consecutive values in a[ ] 2.O(n 2 ) 3.For each value in b[ ], carry out a variation of a binary search in a[ ] – the problem will be solved in O(n log n) public boolean someMethod2(int[] a, int[] b) { for (int j=0; j < b.length; j++) for (int i=0; i < a.length-1; i++) if (b[j] == a[i] + a[i+1]) return true; return false; }

79 Example 3: each element of a[ ] is a unique int between 1 and n; a.length is n-1 public int someMethod3 (int[] a) { boolean flag; for (int j=1; j<=a.length+1; j++) { flag = false; for (int i=0; i<a.length; i++) { if (a[i]==j) { flag = true; break; } } if (!flag) return j; } return -1; }

80 Example 3: each element of a[ ] is a unique int between 1 and n; a.length is n-1 public int someMethod3 (int[] a) { boolean flag; for (int j=1; j<=a.length+1; j++) { flag = false; for (int i=0; i<a.length; i++) { if (a[i]==j) { flag = true; break; } } if (!flag) return j; } return -1; } 1. Returns the missing value (the integer between 1 and n missing in a[ ])

81 Example 3: each element of a[ ] is a unique int between 1 and n; a.length is n-1 public int someMethod3 (int[] a) { boolean flag; for (int j=1; j<=a.length+1; j++) { flag = false; for (int i=0; i<a.length; i++) { if (a[i]==j) { flag = true; break; } } if (!flag) return j; } return -1; } 1. Returns the missing value (the integer between 1 and n missing in a[ ]) 2. O(n 2 )

82 A better solution to Example 3 public int betterMethod3 (int[] a) { int result = 0, sum, n; n = a.length+1; sum = (n*(n+1))/2; for (int i=0; i < a.length; i++) result += a[i]; return (sum-result); }

83 A better solution to Example 3 Time complexity O(n) public int betterMethod3 (int[] a) { int result = 0, sum, n; n = a.length+1; sum = (n*(n+1))/2; for (int i=0; i < a.length; i++) result += a[i]; return (sum-result); }

84 Theoretical Computer Science Studies the complexity of problems: increasing the theoretical lower bound on the complexity of a problem determining the worst-case and average-case complexity of a problem (along with best-case) showing that a problem falls into a given complexity class (e.g., requires at least, or no more than, polynomial time)

85 Easy and Hard problems “Easy” problems, by convention, are those that can be solved in polynomial time or less “Hard” problems have only non-polynomial solutions: exponential or worse Showing that a problem is easy is easy (come up with an “easy” algorithm); proving a problem is hard is hard

86 Theory and algorithms Theoretical computer scientists also devise algorithms that take advantage of different kinds of computer hardware, like parallel processors devise probabilistic algorithms that have very good average-case performance (though worst-case performance might be very bad) narrow the gap between the inherent complexity of a problem and the best currently known algorithm for solving it


Download ppt "Introduction to Complexity. בעיה פשוטה במיוחד סדר שלושה מספרים לפי סדר מונוטוני עולה יש למישהו רעיון?"

Similar presentations


Ads by Google