|
1.Give the order-of-Magnitude time efficiency (in THETA) - R; j k* h; L6 W# X. p& T( D
for the algorithm. , L# n1 s, R3 c5 M! D( Y
1 l1 h7 g# I" G2 f& e5 T/ W: V6 _ Step 1:get values for D1, D2,,,,,, Dn
+ g) J; H( z# ^ Step 2:get sum=0 4 b- c+ B; k* a* H- C. B8 _
Step 3:set left=1 ) q( v* w' _, n. \
Step 4:repeat Step 5 to 7 until left>N # U. l: j. P' n; E* h @7 A3 A1 x
Step 5: if Dleft is positive then , g; O7 q* g) e5 H1 A
Step 6: set sum=sum+Dleft 2 |) @& f% R5 x# r k
Step 7: set left=left+1 * ]! G) S- h7 R. `% L
Step 8: print out sum as the answer 0 V* Z8 o. g9 N
# B: c3 t/ @! x2 J8 {: K. B2 Z4 s6 Z( {( V+ N
' E; W" A3 X3 j/ Z8 B2.Give the order-of-magnitude time efficiency(in THETA) & {; I" ?0 Y; }- j E8 M& r
for the the algorithm.
# i9 `, _- }5 q3 T# i5 I; R( b8 K' E / X) c$ r0 f9 b
Step 1:get values for L1, L2,….. Ln 8 e' F) W$ N1 c1 o7 ~% l, D
Step 2:set i=0 8 b5 o, c3 {& W' L" |+ D8 n7 z
Step 3:repeat Steps 4 to 8 until i>N
( y$ c% j& ?- } W Step 4: set j=1
; q5 ^& y7 N3 X8 L' z2 R. p Step 5: repeat Steps 6 and 7 until j>N - V. a3 X. L. n0 h+ E
Step 6: print(LI,Lj) * q6 F: m) R* l
Step 7: add 1 to the value of j
7 L9 a) n, F! s, I5 _! n; x5 r Step 8: add 1 to the value of i ' T$ |) Q1 B/ O# z- w* ?
* |. x# `( ~( w# @: L7 r4 l求以上二題的時間複雜度 |
|