ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ ΤΜΗΜΑ ΗΛΕΚΤΡΟΛΟΓΩΝ ΜΗΧΑΝΙΚΩΝ ΚΑΙ ΜΗΧΑΝΙΚΩΝ ΥΠΟΛΟΓΙΣΤΩΝ ΗΜΥ 3: Διακριτή Ανάλυση και Δομές Χειμερινό Εξάμηνο 06 Σειρά Ασκήσεων : Συναρτήσεις, Σχέσεις, Σειρές και Αθροίσματα, Αλγόριθμοι και Πολυπλοκότητα Exercise Problem.3. Why is f ot a fuctio from R to R if a) f (x) = /x The expressio /x is meaigless for x = 0, which is oe of the elemets i the domai; thus the "rule" is o rule at all. I other words, f (0) is ot defied. b) f (x) = x Thigs like 3 udefied (or, at best, are complex umbers). c) f (x) = ± (x + The "rule" for f is ambiguous. We must have f (x) defied uiquely, but here there are two values associated with every x, the positive square root ad the egative square root of x +. Problem.3.5 (optioal) I each case we wat to fid the domai (the set o which the fuctio operates, which is implicitly stated i the problem) ad the rage (the set of possible output values). a) Clearly the domai is the set of all bit strigs. The rage is Z; the fuctio evaluated at a strig with l's ad o 0's is, ad the fuctio evaluated at a strig with 0's ad o l's is -. b) Agai the domai is clearly the set of all bit strigs. Sice there ca be ay atural umber of 0's i a bit strig, the value of the fuctio ca be 0,, 4,... Therefore the rage is the set of eve atural umbers. c) Agai the domai is the set of all bit strigs. Sice the umber of leftover bits ca be ay whole umber from 0 to 7 (if it were more, the we could form aother byte), the rage is {0,,, 3, 4, 5, 6, 7}.
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ d) As the problem states, the domai is the set of positive itegers. Oly perfect squares ca be fuctio values, ad clearly every positive perfect square is possible. Therefore, the rage is {l, 4, 9, 6,... }. Problem.3.3 a) Oe way to determie whether a fuctio is a bijectio is to try to costruct its iverse. This fuctio is a bijectio, sice its iverse (obtaied by solvig y = x + for x) is the fuctio g(y) = (y - ) /.Alteratively, we ca argue directly. To show that the fuctio is oe-to-oe, ote that if x + = x' +, the x = x'. To show that the fuctio is oto, ote that ( (y - ) /) + = y, so every umber is i the rage. b) This fuctio is ot a bijectio, sice its rage is the set of real umbers greater tha or equal to (which is sometimes writte [, )), ot all of R. (It is ot ijective either.) c) This fuctio is a bijectio, sice it has a iverse fuctio, amely the fuctio f(y) = y /3 (obtaied by solvig y = x 3 for x). d) This fuctio is ot a bijectio. It is easy to see that it is ot ijective, sice x ad -x have the same image, for all real umbers x. A little work shows that the rage is oly { y 0.5 y < } = [0.5, ). Problem.4.7 Oe patter is that each term is twice the precedig term. A formula for this would be that the th term is -l. Aother patter is that we obtai the ext term by addig icreasig values to the previous term. Thus to move from the first term to the secod we add ; to move from the secod to the third we add ; the add 3, ad so o. So the sequece would start out,, 4, 7,, 6,,... We could also have trivial aswers such as the rule that the first three terms are,, 4 ad all the rest are 7 (so the sequece is,, 4, 7, 7, 7,... ), or that the terms simply repeat,, 4,,, 4,,, 4,... Here is aother patter: Take poits o the uit circle, ad coect each of them to all the others by lie segmets. The iside of the circle will be divided ito a umber of regios. What is the largest this umber ca be? Call that value a. If there is oe poit, the there are o lies ad therefore just the oe origial regio iside the circle; thus a =. If =, the the oe chord divides the iterior ito two parts, so a =. Three poits give us a triagle, ad that makes four regios (the iside of the triagle ad the three pieces outside the triagle), so a3 = 4. Careful drawig shows that the sequece starts out,, 4, 8, 6, 3. That's right: 3, ot 3.
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Problem.4.9 (optioal) We eed to compute the terms of the sequece oe at a time, sice each term is depedet upo oe or more of the previous terms. a) We are give ao =. The, by the recurrece relatio a = 6a-, we see (by lettig = ) that a = 6ao = 6 =. Similarly a = 6a = 6 = 7, the a3 = 6a = 6 7 = 43, ad a4 = 6a3 = 6 43 = 59. b) a = (give), a = a = = 4, a3 =a = 4 = 6, a4 =a3 = 6 = 56, a5 =a4 = 56 = 65536. c) This time each term depeds o the two previous terms. We are give a0 = ad a =. To compute a we let = i the recurrece relatio, obtaiig a = a + 3a0 = + 3 = 5. The we have a3 = a + 3a = 5 + 3 = ad a4 = a3 + 3a = + 3 5 = 6. d) ao = (give), a = (give), a = a+ ao = +4 = 6, a3 = 3a + 3 a =3 6+9 = 7, a4 = 4a3 + 4 a = 4 7 + 6 6 = 04. e) We are give ao =, a =, ad a = 0. The a3 = a + a0 = 0 + = ad a4 = a3 + a = + = 3. Problem 3..3 a) Note that = 8 ad x = 9. Iitially, i is set equal to. The while loop is executed as log as i 8 ad the i th elemet of the list is ot equal to 9. Thus, o the first pass we check that 8 ad that 9 (sice a = ), ad therefore perform the statemet i := i +. At this poit i =. We check that 8 ad the i th elemet of the list is ot equal to 9. Thus o the first pass we check that 8 ad 9 3, ad therefore agai icremet i, this time to 3. This process cotiues util i = 7. At that poit the coditio "i 8 ad 9 a," is false, sice a = 9. Therefore the body of the loop is ot executed (so i is still equal to 7), ad cotrol passes beyod the loop. The ext statemet is the if... the statemet. The coditio is satisfied, sice 7 8, so the statemet locatio := i is executed, ad locatio receives the value 7. The else clause is ot executed. This completes the procedure, so locatio has the correct value, amely 7, which idicates the locatio of the elemet x (amely 9) i the list: 9 is the seveth elemet. b) Iitially, i is set equal to ad j is set equal to 8. Sice i < j at this poit, the steps of the while loop are executed. First m is set equal to [(l + 8)/] = 4. The sice x (which equals 9) is greater tha a4 (which equals 5), the statemet i := m + is executed, so i ow has the value 5. At this poit the first iteratio through the loop is fiished, ad the search has bee arrowed to the sequece a5,..., a8. I the ext pass through the loop (there is aother pass sice i < j is still true), m becomes [(5 + 8)/] = 6. Sice agai x > am, we reset i to be m +, which is 7. The loop is ow repeated with i = 7 ad j = 8. This time m becomes 7, so the test x > am (i.e., 9 > 9) fails; thus j := m is executed, so ow j = 7. At this poit i j, so there are o more iteratios of the loop. Istead cotrol passes to the statemet beyod the loop. Sice the coditio x = a, is true, locatio is set to 7, as it should be, ad the algorithm is fiished. 3
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Problem 3..35 There are four passes through the list. O the first pass, the 3 ad the are iterchaged first, the the ext two comparisos produce o iterchages, ad fially the last compariso results i the iterchage of the 7 ad the 4. Thus after oe pass the list reads, 3, 5, 4, 7. Durig the ext pass, the 5 ad the 4 are iterchaged, yieldig, 3, 4, 5, 7. There are two more passes, but o further iterchages are made, sice the list is ow i order. Problem 3..3 If f(x) is Θ (g(x)), the f(x) C g(x) ad g(x) (x)i for all x > k. Thus f(x) is O(g(x)) ad g(x) is O(f(x)). Coversely, suppose that f(x) is O(g(x)) ad g(x) is O(f(x)). The (with appropriate choice of variable ames) we may assume that f(x) Cg(x) ad g(x) Cf(x) for all x > k. (The k here will be the larger of the two k's ivolved i the hypotheses.) If C > 0 the we ca take C = C - to obtai the desired iequalities i "f(x) is Θ (g(x))." If C 0, the g(x) = 0 for all x > k, ad hece by the first iequality f(x) = 0 for all x > k; thus we have f(x) = g(x) for all x > k, ad we ca take C=C=. Problem 3.3. (optioal) a) We ca express the suggested algorithm i pseudocode as follows. Notice that the Boolea variable disjoit is set to true at the begiig of the compariso of sets S, ad S, ad becomes false if ad whe we fid a elemet commo to those two sets. If disjoit is ever set to false, the we have foud a disjoit pair, ad aswer is set to true. This process is repeated for each pair of sets (cotrolled by the outer two loops). procedure disjoitpair(s, S,..., S : subsets of {,,..., }) aswer:= false for i := to for j := i + to disjoit := true for k:= to if k ϵ Si ad k ϵ Sj the disjoit:= false if disjoit the aswer := true retur aswer b) The three ested loops imply that the elemethood test eeds to be applied O( 3 ) times. 4
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Problem 9..5 Recall the defiitios: R is reflexive if (a,a)ϵr for all a; R is symmetric if (a,b)ϵr always implies (b, a)ϵr; R is atisymmetric if (a, b)ϵr ad (b, a)ϵr always implies a = b; ad R is trasitive if (a, b)ϵr ad (b, c)ϵr always implies (a, c)ϵr. a) It is tautological that everyoe who has visited Web page a has also visited Web page a, so R is reflexive. It is ot symmetric, because there surely are Web pages a ad b such that the set of people who visited a is a proper subset of the set of people who visited b (for example, the oly lik to page a may be o page b). Whether R is atisymmetric i truth is hard to say, but it is certaily coceivable that there are two differet Web pages a ad b that have had exactly the same set of visitors. I this case, (a, b)ϵr ad (b, a)ϵr, so R is ot atisymmetric. Fially, R is trasitive: if everyoe who has visited a has also visited b, ad everyoe who has visited b has also visited c, the clearly everyoe who has visited a has also visited c. b) This relatio is ot reflexive, because for ay page a that has liks o it, (a, a) R. The defiitio of R is symmetric i its very statemet, so R is clearly symmetric. Also R is certaily ot atisymmetric, because there surely are two differet Web pages a ad b out there that have o commo liks foud o them. Fially, R is ot trasitive, because the two Web pages just metioed, assumig they have liks at all, give a example of the failure of the defiitio: (a, b)ϵr ad (b, a)ϵr, but (a, a) R. c) This relatio is ot reflexive, because for ay page a that has o liks o it, (a, a) R. The defiitio of R is symmetric i its very statemet, so R is clearly symmetric. Also R is certaily ot atisymmetric, because there surely are two differet Web pages a ad b out there that have a commo lik foud o them. Fially, R is surely ot trasitive. Page a might have oly oe lik (say to this textbook), page c might have oly oe lik differet from this (say to the Erdos Number Project), ad page b may have oly the two liks metioed i this setece. The (a, b)ϵr ad (b, c)ϵr, but (a, c) R. d) This relatio is probably ot reflexive, because there probably exist Web pages out there with o liks at all to them (for example, whe they are i the process of beig writte ad tested); for ay such page a we have (a, a) R. The defiitio of R is symmetric i its very statemet, so R is clearly symmetric. Also R is certaily ot atisymmetric, because there surely are two differet Web pages a ad b out there that are refereced by some third page. Fially, R is surely ot trasitive. Page a might have oly oe page that liks. 5
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Problem 9..5 We eed to show two thigs. First, we eed to show that if a relatio R is symmetric, the R=R -, which meas we must show that R R - ad R - R. To do this, let (a, b) R. Sice R is symmetric, this implies that (b,a) R. But sice R - cosists of all pairs (a,b) such that (b,a) R, this meas that (a, b) R -. Thus we have show that R R -. Next let (a, b) R -. By defiitio this meas that (b,a) R. Sice R is symmetric, this implies that (a,b) R as well. Thus we have show that R - R. Secod we eed to show that R = R - implies that R is symmetric. To this ed we let (a, b) R ad try to show that (b, a) is also ecessarily a elemet of R. Sice (a, b) R, the defiitio tells us that (b, a) R -. But sice we are uder the hypothesis that R = R -, this tells us that (b, a) R, exactly as desired. Problem 9.. We simply eed to fid solutios of the iequality, which we ca do by commo sese. The set is { (,, 3),(,,4),(,3,4), (,3,4)}. Exercise..: Όλα τα ζεύγη θετικών ακέραιων αριθμών a) ( (x,y) όπου x,yz με x>0 και y>0)..: Το σύνολο των θετικών ακέραιων αριθμών b) c) d)..: Z +..: Z= 0,,,...9..: Όλα τα πιθανά bit strigs..: Z= 0,,,.....: Όλα τα πιθανά bit strigs..: Z= 0,,,... k όπου k ο αριθμός του ψηφίου του strig 6
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 3 a) : και επί b) Όχι :, όχι επί c) : και επί Exercise 4 a) ΝΑΙ b) ΟΧΙ c) ΝΑΙ d) ΟΧΙ Exercise 5 a), ακέραιο υπάρχει άθροισμα ακεραίων που να δίνει τον ακέραιο για k Z, f ( k,0) = k b) OXI π.χ. δεν μπορούν να εκφραστούν οι αρνητικοί αριθμοί c) OXI π.χ. δεν μπορούν να εκφραστούν οι αρνητικοί αριθμοί d), f ( k,0) = k ίδια αιτιολογία με διαφορά ακεραίου 7
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 6 a) Cotrapositive Proof Αν η g δεν είναι :, τότε: x, x (.. της g), ώστε x x και g( x ) = g( x ) και f g( x ) = f ( g( x )) = f ( g( x )) οπότε θα είχαμε f g όχι : αρα αναγκαστικά η g πρέπει να είναι : b) g όχι επί f επί a a a a b b b b c c c f g =>f g a a a a a b b b b b c c c ΔΕΝ ΙΣΧΥΕΙ 8
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 7 Η f είναι αντιστρέψιμη είναι : για α=0 έχουμε f(x)=0 x R ot : για α 0 έχουμε f(x )-f(x )=α( x x ) f(x ) f(x ) για x x f είναι : για α 0 y y ax x y = + = με f ( ) = y Exercise 8 a) f ( x) = f ( x) f ( x) A B A B Περίπτωση: x A x B = x A B f ( x) = f ( x) f ( x) 0 = 00 TRUE A B A B Περίπτωση: x A x B = x A B f ( x) = f ( x) f ( x) 0 = 0 TRUE A B A B 3 Περίπτωση: x A x B = x A B f ( x) = f ( x) f ( x) 0 = 0 TRUE A B A B 4 Περίπτωση: x A x B = x A B f ( x) = f ( x) f ( x) = TRUE A B A B Ισχύει για όλες τις περιπτώσεις και άρα ΙΣΧΥΕΙ b) f ( x) = f ( x) + f ( x) f ( x) f ( x) A B A B A B Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) 0 = 0 + 0 00 TRUE A B A B A B 9
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = 0 + 0TRUE A B A B A B 3 Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = + 0 0 TRUE A B A B A B 4 Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = + TRUE A B A B A B Ισχύει για όλες τις περιπτώσεις και άρα ΙΣΧΥΕΙ c) f ( x) = f ( x) A A Περίπτωση: x A = x A f ( x) = f ( x) 0 = TRUE A A Περίπτωση: x A = x A f ( x) = f ( x) = 0 TRUE A A Ισχύει για όλες τις περιπτώσεις και άρα ΙΣΧΥΕΙ d) f ( x) = f ( x) + f ( x) f ( x) f ( x) A B A B A B Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) 0 = 0 + 0 00 TRUE AB A B A B Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = 0 + 0 TRUE AB A B A B 3 Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = + 0 0 TRUE AB A B A B 0
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ 4 Περίπτωση: x A x B = x A B f ( x) = f ( x) + f ( x) f ( x) f ( x) = + TRUE AB A B A B Ισχύει για όλες τις περιπτώσεις και άρα ΙΣΧΥΕΙ Exercise 9 a) x = x Θέτουμε m = x τότε m x m + m x ( m + ) m x m + m = x και m = x x = x b) Με τον ίδιο τρόπο λύνεται και το δεύτερο ερώτημα. Exercise 0 Αυτοπαθής Συμμετρική Αντισυμμετρική Μεταβατική a) b) c) d) e) f)
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise Αυτοπαθής Συμμετρική Αντισυμμετρική Μεταβατική a) b) c) d) S R =>R S 3 3 3 3 3 3 4 4 4 4 4 4 R S = {(,),(,3),(,4),(,),(,3),(,4),(3,),(3,3),(3,4)} R S S R (,) (,) (,) (,3) (,) (,) (,4) (,) (,3) (3,) (,) (,4) (3,3) (3,3) (3,) (3,4) (4,4) (3,) (3,3) (3,4)
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ R R R R (,) (,) (,) (,3) (,3) (,3) (,4) (,4) (,4) (3,) (3,) (3,) (3,3) (3,3) (3,3) (3,4) (3,4) (3,4) S T T S (,) (,4) (,4) (,) (4,) (,4) (,) (4,) (,) (3,3) (4,4) T S S T (,4) (,) (,4) (4,) (,) (4,) (,) (4,) (,) (3,3) (4,4) 3
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ S T R R (S T) (,4) (,) (4,) (4,) (,3) (4,3) (4,) (,4) (4,4) (3,) (3,3) (3,4) T R S (R S) T) (,4) (,) (4,) (4,) (,3) (4,3) (,4) (4,4) (,) (,3) (,4) (3,) (3,3) (3,4) R ( S T) = ( R S) T Exercise R = R R = R R Έστω R: αυτοπαθής R R ή, ό a,( a, a) R ( a, a) R R k Έστω R : αυτοπαθής a a a R R a a R R k k+ k+,(, ) και (, ) (, ), άρα αυτοπαθής Οπότε με επαγωγή R k αυτοπαθής 4
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 3 R = R R = R R R : ή, R R ή ό : k k k R : ή ( a, b) R ( b, a) R ( b a) k k R : ή ( c, d) R ( d, c) R ( c d) k+ k+ Θέλω νδο για τυχαίο ( x, y) R ( y, x) R ( x y) k+ k ( x, y) R c, ώστε ( x, c) R και ( c, y) k με ( x, c) R ( c, x) R ( c, y) R ( y, c) R k R με R = R R, έχουμε ( y, c) R ( c, x) R ( y, x) R k+ k k k+ Άρα ( x, y) R ( y, x) R k+ k+ ε επαγωγή R : ή 5
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 4 a) a a a3 a4 a5 a6 a7 a8 3 *3+5 *+5 *7+5 *59+5 5 507 09 b) a a a3 a4 a5 a6 a7 a8 3 3 Exercise 5 a) 5 5 5 ( k+ ) = k+ = ( + + 3+ 4 + 5) + 5 = 0 k= k= k= b) 4 j= 0 or j 0 3 4 ( ) = ( ) + ( ) + ( ) + ( ) + ( ) = 4 j= 0 4+ ( ) j ( ) = = c) js 76 (/ j) = + + + = 3 5 7 05 d) = ( + + + ) = 4 js Exercise 6 a) b) c) 8 j= 0 8 j= 8+ j 3 = 3 = 7533 j 3 = 9840 8 8 8+ j j 0 ( ) ( ) = ( ) ( ) + ( ) = ( ) = 7 j= j= 6
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ d) 8 j= 0 8+ ( 3) j ( 3) = = 984 3 Exercise 7 a) b) c) d) 3 3 3 3 (i + 3 j) = i + 3 j = 4 i + 9 j = 4( + + 3) + 9( + ) = 5 i= j= i= j= i= j= i= j= 3 3 3 (3i j) = 3i j = i 6 j = (0 + + ) + 6(0 + + + 3) = 0 i= 0 j= 0 i= 0 j= 0 i= 0 j= 0 i= 0 j= 0 3 3 ( j) = j = 3 j = 3(0 + + ) = 9 i= j= 0 j= 0 i= j= 0 3 3 3 3 3 3 3 3 3 3 i j = i j = i j = ( + + 3 ) (0 + + ) = 80 i= 0 j= i= 0 j= i= 0 j= Exercise 8 έ ak = = ak = = k + ( k ) + k = ( ) = ( ak ak ) = ( a a0) k( k + ) k k + k = k = k = = ( ) = = + + + Exercise 9 Bubble sort 5 5 5 5 5 5 5 3 3 3 3 6 6 3 3 3 3 3 5 3 3 3 6 5 3 3 3 6 5 4 4 4 4 4 6 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 7
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 0 a) b) c) d) e) f) f x x x x x O x C ( ) = 7 + 7 + = 8, ( ), = 8 f x x x x x O x C ( ) = + 000 + 000 = 00, ( ), = 00 f x x x x x x O x C ( ) = log =, ( ), = 4 x f ( x) = O( x ) l (l ) f x x x f ( x) = floor( x) ceil( x) = x x x( x + ) x x x x ( ) = (lim = lim = lim O( x ) x x x = x + x x + x = x O x C =, ( ), Exercise a) 3 x + 7 f ( x ) O ( x ) = f ( x) = ( x) f ( x) 3 x, ( x) b) f x x x ( ) = + 7 f ( x) x + x = 3 x O( x ) = f x f ( x) x ( for x 7) ( x ) ( ) ( x ) c) f ( x) = x + = x + x 3x f ( x) x + = x + = O( x) = x x f ( x) x = x = ( x) f ( x) ( x) 8
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ d) f x ( ) = log( x + ) f ( x) log ( x + x ) = log ( x ) = log( x) + log() 3log x, x 0 0 f x x x f x x ( ) log( ) = log ( ) (log ), Με κατάλληλη αλλαγή βάσης e) f ( x)log x (log x), f ( x) = log () log x 0 0 O(log x) (log x) (log x) Exercise Έστω f(x)=x, g(x)=x (f(x) O(g(x)) όμως x C x C x x, Άρα δεν ισχύει 9
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 3 j x j + j + x j x ( j, j + ), Therefore x j+ 3 dx ( ) = x dx (3 ) = x 3 3... dx (+) x dx x j j= H = dx + = l( ) + l( ), e H O(log ) x 0
ΗΜΥ 3: ΔΙΑΚΡΙΤΗ ΑΝΑΛΥΣΗ ΚΑΙ ΔΟΜΕΣ Exercise 4 M = max{ a, a,... a } f ( x) = a x +... + a a x + a x +... a 0 0 a x + a x +... a x M ( + ) x = Cx, O( x ) 0 k, k m, m : logest of ai, i a a a Τότε i i, x k x a a0 a f ( x) = ax +... + a0 = x a + +... + x x x f ( x) =( x ) Αποδείχτηκε Exercise 5 x k for example: k = 0 x = x k = x = x 0 k+ + = ( k ), x ( x ) θέλω τετραγωνίζοντας για k, k πολ/σμοί. k Με απλό αλγόριθμο θέλω συνολικά πολ/σμούς η Πιο αποδοτική η μέθοδος. k