Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. 1.
  2. A[1...n]
  3. int x
  4. int y
  5. int z
  6. int a=0
  7. for i=1 to n do
  8. if(z==null)
  9. if(A[i]<x)
  10. a=a+1
  11. else for j=y to z
  12. if(A[i]==j)
  13. break
  14. if(A[i]<x)
  15. a=a+1
  16.  
  17. T(n) = O(n^2) - worst case becouse loop isn't breaked by the condition so it must repeat n^2-times.
  18. 2. A[1...n]
  19. product(A, n)
  20. if(n==1)
  21. return A[1];
  22. else
  23. return(A, n-1)*A[n-1]
  24. T(4)=T(3)=T(2)=T(1)
  25. T(n)=O(n)
  26. 3.(wklej od szymka popraw fory)
  27. 4.a)
  28. b) a=8, b=2, f(n) = n
  29. n^logb (a) = n^log8 2 = n^3
  30. f(n)=n < n^3 - czyli dużo O bo epsilon > 0
  31. theta(n^log8 2) = theta(n^3)
  32. c)a=4 b=2 f(n)=n^4
  33. n^logb(a) = n^log2 4 = n^2
  34. f(n) = n^4 > n^2 czyli omega ale nie chce mi sie sprawdzac warunku
  35. theta(f(n))=theta(n^4)
  36. d)
  37. 5.
  38. BUBBLE-SORT(A,n)
  39. for i=n downto 2
  40. for j=1 to i-1
  41. if A[j] > A[j+1]
  42. A[j] ← → A[j+1]^3 ← swap
  43.  
  44. T(n) = theta(n^2)
  45. INSERTION-SORT (A, n)
  46. for j = 2 to n
  47. r = A [j]
  48. i = j − 1
  49. while i >= 0 and A[i] > r do
  50. A[i + 1] = A[i]
  51. i = i − 1
  52. A[i + 1] = r ^3
  53.  
  54. B(n) = theta(n)
  55. T(n) = O(n^2)
  56. W(n) = theta(n^2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement