|
1.Give the order-of-Magnitude time efficiency (in THETA) - V8 _6 p6 ^: V4 i9 X# R
for the algorithm.
; c5 u: e, ^! ]0 L& p1 v: T6 N 8 s4 y6 V: U |3 A& Z8 x
Step 1:get values for D1, D2,,,,,, Dn
, w. M- E. e2 H8 r; ^ Step 2:get sum=0
" J3 v6 V; s" E _+ t Step 3:set left=1 * C/ o4 f8 k& w- Y' i" j
Step 4:repeat Step 5 to 7 until left>N
! g0 g% F" G( P; E# Y* X8 C+ w Step 5: if Dleft is positive then
( K! ?+ U3 J. T& u Step 6: set sum=sum+Dleft
2 S: I4 y; F: m) x5 Y5 t Step 7: set left=left+1
' Q3 `. i9 t% \* ?0 \ Step 8: print out sum as the answer 6 ^( P3 ~7 D6 I
$ K+ Q; s3 L5 j/ b0 S2 G4 h$ k! g# a A: L) x: [1 p
" N B! d8 r) K& h+ n; c5 R2.Give the order-of-magnitude time efficiency(in THETA)
( b6 S' s$ t% i6 _% s! @ for the the algorithm. 5 L- N6 A& O3 s+ ?, C b
4 X+ K( S9 p2 e) F Step 1:get values for L1, L2,….. Ln
" r' I& U+ ?! K. ?% F Step 2:set i=0 " {* W, L4 `; u# m0 E8 c
Step 3:repeat Steps 4 to 8 until i>N + ]6 r8 ]' O9 x
Step 4: set j=1 9 u; g4 N9 N( i) _. ?
Step 5: repeat Steps 6 and 7 until j>N z2 n5 G6 \, B$ a: p o y5 |
Step 6: print(LI,Lj) ; j! L! {9 B1 r& W" B
Step 7: add 1 to the value of j , u' P6 Z1 m& b# g1 J6 |
Step 8: add 1 to the value of i ! {. {. L- `. O7 K& q1 c2 A
' `8 w" b+ ^7 R. Y/ A/ I h求以上二題的時間複雜度 |
|