Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- A[1...n]
- int x
- int y
- int z
- int a=0
- for i=1 to z do
- if(x==0)
- if(A[i]<x)
- a=a+1
- else for j=y to z
- if(A[i]==j)
- break
- if(z!=0)
- if(A[i]<x)
- a=a+1
- T(n) = O(n^2) - worst case becouse loop isn't breaked by the condition so it must repeat n^2-times.
- 2. A[1...n]
- product(A, n)
- if(n==1)
- return A[1];
- else
- return(A, n-1)*A[n]
- T(4)=T(3)=T(2)=T(1)
- T(n)=O(n)
- 3.(wklej od szymka popraw fory)
- 4.a)
- b) a=8, b=2, f(n) = n
- n^logb (a) = n^log8 2 = n^3
- f(n)=n < n^3 - czyli dużo O bo epsilon > 0
- theta(n^log8 2) = theta(n^3)
- c)a=4 b=2 f(n)=n^4
- n^logb(a) = n^log2 4 = n^2
- f(n) = n^4 > n^2 czyli omega ale nie chce mi sie sprawdzac warunku
- theta(f(n))=theta(n^4)
- d)
- 5.
- BUBBLE-SORT(A,n)
- for i=n downto 2
- for j=1 to i-1
- if A[j] > A[j+1]
- A[j] ← → A[j+1]^3 ← swap
- T(n) = theta(n^2)
- INSERTION-SORT (A, n)
- for j = 2 to n
- r = A [j]
- i = j − 1
- while i >= 0 and A[i] > r do
- A[i + 1] = A[i]
- i = i − 1
- A[i + 1] = r ^3
- B(n) = theta(n)
- T(n) = O(n^2)
- W(n) = theta(n^2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement