|
1.Give the order-of-Magnitude time efficiency (in THETA) - Z: l, V8 ]. E. P
for the algorithm. @0 p ~" `3 J" B. ?/ ~
5 S+ k( h: ?; a: u! x( t
Step 1:get values for D1, D2,,,,,, Dn
8 l! q9 C3 I. ^8 @+ q Step 2:get sum=0
: F9 W/ d7 G# M9 H Step 3:set left=1
0 |: ^4 Z( V# B* r Step 4:repeat Step 5 to 7 until left>N ' t7 e* M }/ e5 f5 U0 h
Step 5: if Dleft is positive then
. ^& Q' u3 j: m" M, k" C% P Step 6: set sum=sum+Dleft
2 M5 z3 P' d9 u6 w, n4 z Step 7: set left=left+1
5 @2 y! r5 V, ~ Step 8: print out sum as the answer $ B: u( T" c8 |7 O: o
7 J% c& |9 d; m1 A: y
8 v: z1 I8 E5 q$ N3 M: y0 F6 r" A: P ?2 c
2.Give the order-of-magnitude time efficiency(in THETA) ' ?8 A( q& h- s
for the the algorithm. . s4 j7 o8 K+ Z/ n3 q/ W. U
6 X- y$ j( D2 g( I1 `$ `& Y Step 1:get values for L1, L2,….. Ln ) y$ Y# f% I6 ]0 M4 T
Step 2:set i=0 : R% S, m( l+ J3 q; }
Step 3:repeat Steps 4 to 8 until i>N 3 Z+ W9 [. _6 [$ F% j5 m
Step 4: set j=1
5 E. a: X1 b7 S- G% d2 X1 W Step 5: repeat Steps 6 and 7 until j>N + m' ?. \8 Z! u8 J
Step 6: print(LI,Lj) ' O* ^; U% N# |% _: J
Step 7: add 1 to the value of j - O1 k% g5 _0 l+ h0 `
Step 8: add 1 to the value of i
( m: F: f% o$ Z0 U; m
9 Z6 _2 X) c) _4 }$ G; E求以上二題的時間複雜度 |
|