|
1.Give the order-of-Magnitude time efficiency (in THETA) 4 G: k3 P8 x% K3 u
for the algorithm.
! G2 ]/ `5 z+ a P$ c
8 I' [/ V' A" V* S2 Q+ `. ?6 M9 C Step 1:get values for D1, D2,,,,,, Dn 3 l# H6 [4 c4 e3 C" M# \3 s
Step 2:get sum=0
{. j o. _; D3 g5 k& c9 _9 M6 ] Step 3:set left=1 2 j" D/ o2 D" e3 ~7 _/ ~" ?
Step 4:repeat Step 5 to 7 until left>N
! F; A2 R8 r& ~# c8 _0 [* m Step 5: if Dleft is positive then 2 A& ~, J U+ l2 K9 A9 P8 e
Step 6: set sum=sum+Dleft
' X, |8 R4 i8 K7 G Step 7: set left=left+1
# Z( w/ g0 ]( r6 t+ R Step 8: print out sum as the answer
# v# F7 [. a" V1 \
( u0 H; a! w7 Y6 `6 N) b2 Y' p6 i& C/ r w) a4 O% b! s" F
( r3 W2 N% u0 |* t. }8 n. @2.Give the order-of-magnitude time efficiency(in THETA)
2 x [* I" K! z: ~5 l# k) g for the the algorithm. 1 \" P3 b) I4 _! ?
; s$ r0 F6 o" w: F0 Q! ] Step 1:get values for L1, L2,….. Ln
1 D- D- I6 m+ Y6 ]; i R& e2 s- X Step 2:set i=0 ; q& X& m/ n2 _3 E
Step 3:repeat Steps 4 to 8 until i>N
" h V( U' w0 P C3 a Step 4: set j=1 . {. d6 O7 h& R/ U
Step 5: repeat Steps 6 and 7 until j>N
. V4 A$ J% ^! q3 K4 m% Q3 g Step 6: print(LI,Lj) 8 E* ^. v( u4 o, r
Step 7: add 1 to the value of j * g# q0 K+ M2 l+ r6 ^' ]
Step 8: add 1 to the value of i % @0 W* n r/ O# c
' h' c; x+ ^% W$ ^- @( _# ~. l# @, y求以上二題的時間複雜度 |
|