翻蚳è
ããïŒãã®ããã¹ãã¯ãææãé床ã«ãåããå Žæã®ããã«ãå°ããªç¥èªã§ç€ºãããŠããŸãã èè
ã¯ãèªè
ã«ã¯ç¹å®ã®ãããã¯ãåçŽãããããŸãã¯æåãããããã«èŠãããããããªããšæ£ããèŠåããŠããŸãã ããã«ãããããããå人çã«ã¯ããã®ããã¹ãã¯ãã¢ã«ãŽãªãºã ã®è€éãã®åæã«é¢ããæ¢åã®ç¥èãåçåããã®ã«åœ¹ç«ã¡ãŸããã ä»ã®èª°ãã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
å
ã®èšäºã®éãå€ããããç§ã¯ãããéšåã«åå²ããŸãããããã®ãã¡åèš4ã€ã«ãªããŸãã
ç§ã¯ïŒãã€ãã®ããã«ïŒç¿»èš³ã®å質ã®æ¹åã«é¢ããPMã®ã³ã¡ã³ãã«éåžžã«æè¬ããŸãã以åã«å
¬éãããïŒ
ããŒã1é£æ床
åã®éšåããããããã®è£
食å®æ°ããã¹ãŠç Žæ£ã§ããå Žåãããã°ã©ã åœä»€ãã«ãŠã³ãããããã®é¢æ°ã®æŒžè¿çãªåäœã«ã€ããŠè©±ãããšã¯éåžžã«ç°¡åã«ãªããšçµè«ä»ããããšãã§ããŸãã å®éãã«ãŒããå«ãŸãªãããã°ã©ã ã«ã¯
f( n ) = 1
ããããŸãããã®å Žåãäžå®æ°ã®åœä»€ãå¿
èŠãªããã§ãïŒãã¡ãããååž°ããªãå Žå-以äžãåç
§ïŒã
1
ãã
n
ãŸã§ã®åäžãµã€ã¯ã«ã¯ããµã€ã¯ã«ã®ååŸã§äžå€ã®æ°ã®ã³ãã³ããå®è¡ãããµã€ã¯ã«å
ã®äžå®æ°ã®åœä»€ã
n
åå®è¡ãããããã挞è¿
f( n ) = n
n
ãäžããŸãã
ãã®ãããªèæ
®äºé
ã«å°ãããã®ã¯ãæ¯åæ瀺ãèªããããé¢åã§ã¯ãªãã®ã§ããã®è³æãçµ±åããããã®ããã€ãã®äŸãèŠãŠã¿ãŸãããã 次ã®
PHPããã°ã©ã ã¯
A
ãµã€ãº
n
é
å
A
ç¹å®ã®å€ãå«ãŸããŠãããã©ããã確èªããŸãã
<?php $exists = false; for ( $i = 0; $i < n; ++$i ) { if ( $A[ $i ] == $value ) { $exists = true; break; } } ?>
é
åå
ã®å€ãèŠã€ãããã®æ¹æ³ã¯ã
ç·åœ¢æ€çŽ¢ãšåŒã°ã
ãŸã ã ããã°ã©ã ã«ã¯
f( n ) = n
ããããããããã¯æå¹ãªååã§ãïŒããæ£ç¢ºã«ã¯ãç·åœ¢ããæå³ããŸãã次ã®ã»ã¯ã·ã§ã³ã§æ€èšããŸãïŒã
break
䜿çšãããšã1åã®å埩ã®åŸã§ããããã°ã©ã ãããæ©ãçµäºã§ããŸãã ãã ããé
å
A
ç¹å®ã®å€ããŸã£ããå«ãŸããŠããªãæãäžå©ãªã·ããªãªã«é¢å¿ãããããšãæãåºããŠãã ããã ãããã£ãŠã
f( n ) = n
ã¯ä»¥åãšåãã§ãã
æŒç¿2æãæ害ãªå Žåã«äžèšã®PHPããã°ã©ã ã«å¿
èŠãªåœä»€æ°ãäœç³»çã«åæãããã®æŒžè¿æ§ãå°ãåºããŸãïŒæåã®éšåã§Javascriptã§ããã°ã©ã ãåæããæ¹æ³ãšåæ§ïŒã f( n ) = n
ã«ãªãã¯ãã§ãã
é
åãã2ã€ã®å€ãè¿œå ãããã®çµæãæ°ããå€æ°ã«æžã蟌ãPythonããã°ã©ã ãèŠãŠã¿ãŸãããã
v = a[ 0 ] + a[ 1 ]
ããã«ã¯äžå®æ°ã®åœä»€ãããããã
f( n ) = 1
ã§ãã
次ã®C ++ããã°ã©ã ã¯
A
ãµã€ãº
n
ãã¯ãã«ïŒå
ã®é
åïŒ
A
2ã€ã®åäžã®å€ãå«ãŸããŠãããã©ããã確èªããŸãã
bool duplicate = false; for ( int i = 0; i < n; ++i ) { for ( int j = 0; j < n; ++j ) { if ( i != j && A[ i ] == A[ j ] ) { duplicate = true; break; } } if ( duplicate ) { break; } }
ãã¹ãããã2ã€ã®ãµã€ã¯ã«ã¯ã
f( n ) = n
2ã®åœ¢ã®æŒžè¿ãäžããŸãã
å®çšçãªæšå¥šäºé
ïŒåçŽãªããã°ã©ã ã¯ããã¹ãããããµã€ã¯ã«ã®æ°ãã«ãŠã³ãããããšã§åæã§ããŸãã
n
åã®ç¹°ãè¿ãã§ã®åäžãµã€ã¯ã«ã«ããã
f( n ) = n
ãŸãã ã«ãŒãå
ã®ã«ãŒãã¯
f( n ) = n
2ã§ãã ãµã€ã¯ã«å
ã®ãµã€ã¯ã«å
ã®ãµã€ã¯ã«ã¯
f( n ) = n
3ã§ãã ãªã©ãªã©ã
ã«ãŒãæ¬äœã®ããã°ã©ã ã§é¢æ°ãåŒã³åºããããã®äžã§å®è¡ãããåœä»€ã®æ°ãããã£ãŠããå Žåãããã°ã©ã å
šäœã®ã³ãã³ãã®ç·æ°ãç°¡åã«å€æã§ããŸãã äŸãšããŠæ¬¡ã®Cã³ãŒããæ€èšããŠãã ããã
int i; for ( i = 0; i < n; ++i ) { f( n ); }
f( n )
ãæ£ç¢ºã«
n
åœä»€ãå®è¡ããããšãããã£ãŠããå Žåã
f( n )
ã¯
n
ååŒã³åºããããããããã°ã©ã å
šäœã®åœä»€æ°ã¯æŒžè¿çã«
n
2ã«è¿ã¥ããšèšããŸãã
å®çšçãªæšå¥šäºé
ïŒäžé£ã®forã«ãŒããé£ç¶ããŠããå Žåãããã°ã©ã ã®æŒžè¿çãªåäœããããã®äžã§æãé
ãã«ãŒãã決å®ããŸãã 1ã€ã«ç¶ã2ã€ã®ãã¹ããããã«ãŒãã¯ããã¹ããããã«ãŒãèªäœãšæŒžè¿çã«åãã§ãã ãã¹ããããã«ãŒãã¯ãåäžã«ãŒãã
æ¯é
ãããšèšãããŠ
ããŸãã
次ã«ãçè«å®¶ã䜿çšããèå³æ·±ãè¡šèšæ³ã«åãæ¿ããŸãããã
f
ã®æ£ç¢ºãªæŒžè¿æ§ãèŠã€ãããšãããã°ã©ã ã¯
Î( f( n ) )
ãšèšããŸãã ããšãã°ãäžèšã®äŸã§ã¯ãããã°ã©ã
Î( 1 )
ã
Î( n
2 )
ããã³
Î( n
2 )
ãããããããã°ã©ã ã§ãã
Î( n )
ãtheta from nã
Î( n )
çºé³ãããŸãã
f( n )
ïŒå®æ°ãå«ãåœä»€ãã«ãŠã³ãããå
ã®é¢æ°ïŒã¯
Î( - )
ãšèšãããšããããŸãã ããšãã°ã
f( n ) = 2n
ã¯
Î( n )
é¢æ°ã§ãããšèšããŸãã äžè¬çã«ãæ°ãããã®ã¯äœããããŸããã ãŸãã
2n â Î( n )
ãšçºé³ããããšãã§ããŸããããã¯ãtwo nã¯then from the nãã«å±ããŸãã ãã®ãããªè¡šèšæ³ãšæ··åããªãã§ãã ãããããã°ã©ã ã«å¿
èŠãªã³ãã³ãã®æ°ãæ°ããŠ
2n
ã«ãããšããã®ã¢ã«ãŽãªãºã ã®æŒžè¿çãªåäœã¯
n
ïŒå®æ°ãç Žæ£ããããšã§ããããŸãïŒãšããŠèšè¿°ãããŠããã ãã§ãã ãã®è¡šèšæ³ã䜿çšããŠãããã€ãã®çã®æ°åŠçã¹ããŒãã¡ã³ãã瀺ããŸãã
- n 6 + 3nâÎïŒn 6 ïŒ
- 2 n + 12âÎïŒ2 n ïŒ
- 3 n + 2 nâÎïŒ3 n ïŒ
- n n + nâÎïŒn n ïŒ
ãšããã§ãæåã®ããŒãã®1ã€ãå®è¡ããããšã«ããå Žåãããã¯åœŒã®æ£è§£ã§ãã
ãã®é¢æ°ïŒã€ãŸãÎ( )
ãèšè¿°ãããã®ïŒãæéã®è€éã ããŸãã¯åã«ã¢ã«ãŽãªãºã ã®è€éããšåŒã³ãŸãã ãããã£ãŠã
Î( n )
ã¢ã«ãŽãªãºã ã®è€éãã¯
n
ã§ãã
Î( 1 )
ã
Î( n )
ã
Î( n
2 )
ããã³
Î( log( n ) )
ã«ãç¹å¥ãªååããã
Î( log( n ) )
ããããã¯éåžžã«äžè¬çã§ãã 圌ãã¯ã
Î( 1 )
ã¯
äžå®æéã¢ã«ãŽãªãºã ã
Î( n )
ã¯
ç·åœ¢ ã
Î( n
2 )
ã¯
2次 ã
Î( log( n ) )
ã¯
察æ°ã§ãããšèšããŸãïŒäœãããããªããŠãå¿é
ããªãã§ãã ãã
Î( log( n ) )
察æ°-ããã«ã€ããŠã¯ããã«èª¬æããŸãïŒã
å®çšçãªæšå¥šäºé
ïŒ
Î
ã倧ããããã°ã©ã ã¯ã
Î
ãå°ããããã°ã©ã ãããå®è¡ãé
ããªããŸãã
ãbig Oããšããè¡šèš
å®éã«ã¯ãäžèšã§æ€èšããæ¹æ³ã§ã¢ã«ãŽãªãºã ã®æ£ç¢ºãªåäœãèŠã€ããã®ã¯é£ããå ŽåããããŸãã ç¹ã«è€éãªäŸã®å Žåã ããããç§ãã¡ã®ã¢ã«ãŽãªãºã ã®æ¯ãèãã¯æ±ºããŠå¢çãè¶ããããšã¯ãããŸããã ããã«ãããå®æ°ãç¡èŠããŠãïŒä»¥åã®ããã«ïŒã¢ã«ãŽãªãºã ã®é床ãæ確ã«ç€ºãããªãå Žåããããããäœæ¥ã楜ã«ãªããŸãã å¿
èŠãªã®ã¯ãã®å¢çãèŠã€ããããšã§ããããã®æ¹æ³ã¯äŸã§èª¬æããæ¹ãç°¡åã§ãã
åŠç¿ã¢ã«ãŽãªãºã ã§äœ¿çšãããæãããç¥ãããŠããã¿ã¹ã¯ã¯ãœãŒãã§ãã ãµã€ãº
n
ã®é
å
A
n
ïŒããªãã¿ã®ããã«èãããŸããïŒïŒããããŠãããããœãŒãããããã°ã©ã ãæžãããã«æ±ããããŸãã ããã§ã®é¢å¿ã¯ããã®ãããªå¿
èŠæ§ãå®éã®ã·ã¹ãã ã§ãã°ãã°çããããšã§ãã ããšãã°ããã¡ã€ã«ãã©ãŠã¶ãŒã¯ããŠãŒã¶ãŒããã¡ã€ã«ãç°¡åã«ããã²ãŒãã§ããããã«ããã¡ã€ã«ãååã§äžŠã¹æ¿ããå¿
èŠããããŸãã ãŸãã¯å¥ã®äŸïŒãããªã²ãŒã ã§ã¯ãä»®æ³äžçã§ã®ãã¬ã€ã€ãŒã®èŠç¹ããã®è·é¢ã«å¿ããŠãç»é¢ã«è¡šç€ºãããŠãã3Dãªããžã§ã¯ãã䞊ã¹æ¿ããã¿ã¹ã¯ãçºçããå ŽåããããŸãã ç®çïŒãããã®ãã¡ã®ã©ãã圌ã«èŠããã©ããèŠããªããã決å®ããŸãïŒããã¯
å¯èŠæ§åé¡ãšåŒã°ããŸãïŒã ãœãŒããèå³æ·±ããã®ã§ãããªããªãããœãŒãã«ã¯å€ãã®ã¢ã«ãŽãªãºã ãããããã®ããã€ãã¯ä»ã®ãã®ãããæªãããã§ãã ãã®ã¿ã¹ã¯ã¯ãå®çŸ©ãšèª¬æãç°¡åã§ãã ããã§ã¯ãé
åããœãŒãããã³ãŒããæžããŸãããã
b = [] n.times do m = a[ 0 ] mi = 0 a.each_with_index do |element, i| if element < m m = element mi = i end end a.delete_at( mi ) b << m end
Rubyã§é
åã®äžŠã¹æ¿ããå®è£
ããå®å
šã«éå¹ççãªæ¹æ³ã次ã«ç€ºããŸãã ïŒãã¡ãããRubyã¯ã䜿çšãã¹ãçµã¿èŸŒã¿é¢æ°ã䜿çšããé
åã®ãœãŒãããµããŒãããŠããŸãããããã¯ã説æã®ããã ãã«ç€ºããäžèšã®ã³ãŒããããééããªãé«éã§ããïŒ
ãã®ã¡ãœããã¯
ãéžæã«ãããœãŒããšåŒã°ã
ãŸã ã ãŸããé
åã®æå°èŠçŽ ãæ€åºããïŒäžèšã®ã³ãŒãã§ã¯
a
ãæå°å€ã¯
m
ããã®ã€ã³ããã¯ã¹ã¯
mi
ãšããŠç€ºãããŸãïŒãæ°ããé
åã®æåŸã«é
眮ããïŒãã®å Žåã¯
b
ïŒãå
ã®é
åããåé€ãããŸãã 次ã«ãæ®ãã®å€ã®äžã§ãæå°å€ãåã³æ€åºãããæ°ããé
åïŒçŸåš2ã€ã®å€ãå«ãïŒã«è¿œå ãããå€ãé
åããåé€ãããŸãã ãã¹ãŠã®èŠçŽ ãå
ã®é
åããæ°ããé
åã«è»¢éããããŸã§ããã®ããã»ã¹ãç¹°ãè¿ãããŸããããã¯ããœãŒãã®çµäºãæå³ããŸãã ãã®äŸã§ã¯ã2ã€ã®ãã¹ããããã«ãŒãããããŸãã å€åŽã®ã«ãŒãã¯
n
åãå®è¡ããããå
åŽã®ã«ãŒãã¯é
å
a
åèŠçŽ ã«å¯ŸããŠ1åå®è¡ãããŸãã æåã«
a
ã¯
n
èŠçŽ ããããåå埩ã§ãããã®1ã€ãåé€ããŠãããæåã«å
éšã«ãŒãã
n
åã¹ã¯ããŒã«ãã次ã«
n - 1
ã
n - 2
ãªã©ãæåŸã®å埩ãŸã§å
éšã«ãŒãã1åã ãééããŸãã
åèš
1 + 2 + ... + (n - 1) + n
ãèæ
®ãããšããã®ã³ãŒãã®è€éããèŠã€ããã®ã¯ããåé¡ã«ãªããŸãã ããããããã«å¯ŸãããäžéããèŠã€ããããšãã§ããŸãã ãããè¡ãã«ã¯ãããã°ã©ã ãå€æŽããŠïŒã³ãŒãã«è§Šããããšãªã粟ç¥çã«ã§ããŸãïŒãããã
æªåãããŠãããäœãèµ·ãã£ããã®è€éããå°ãåºããŸãã ããããã°ãå
ã®ããã°ã©ã ã®åäœãã²ã©ãããŸãã¯ïŒã»ãšãã©ã®å ŽåïŒè¯ããªã£ãŠãããšèªä¿¡ãæã£ãŠèšãããšãã§ããŸãã
次ã«ãããã°ã©ã ã®è€éãã®çµè«ãåçŽåããããã«ãããã°ã©ã ãå€æŽããæ¹æ³ã«ã€ããŠèããŠã¿ãŸãããã å¿ããªãã§ãã ããïŒãããæªåãããïŒããšãã°ãã³ãŒãã«æ°ããåœä»€ãè¿œå ããïŒã ãã§ãå
ã®ããã°ã©ã ã«å¯ŸããŠè©äŸ¡ãæå³ãæã€ããã«ããããšãã§ããŸãã æããã«ãããã°ã©ã ã®å
éšã«ãŒããå€æŽããŠãåå埩ã§
n
åè©äŸ¡ã匷å¶ããããšãã§ããŸãã ãããã®ç¹°ãè¿ãã®ããã€ãã¯åœ¹ã«ç«ããªãã§ãããããçµæã®ã¢ã«ãŽãªãºã ã®è€éããåæããã®ã«åœ¹ç«ã¡ãŸãã ãã®å°ããªå€æŽãè¡ããšãæ°ããã¢ã«ãŽãªãºã ã«ã¯
Î( n
2 )
ãå«ãŸããŸããããã¯ããããããæ£ç¢ºã«
n
åå®è¡ããã2ã€ã®ãã¹ããããã«ãŒããååŸããããã§ãã ãããããªããå
ã®ã¢ã«ãŽãªãºã ã«ã¯
O( n
2 )
ãŸãã
O( n
2 )
ã
n
ããã®å€§ããªOã®2ä¹ã
)
çºé³ãããŸãã ããã¯ãããã°ã©ã ã挞è¿çã«
n
2ããæªããªãããšã瀺åããŠããŸãã 圌女ã¯è¯ããè¯ããåãã§ãããã ãšããã§ãã³ãŒãã«å®éã«
Î( n
2 )
å Žåãããã¯ãŸã
O( n
2 )
ã§ãããšèšããŸãã ãããããããç解ããããã«ãå
ã®ããã°ã©ã ãå€æŽããŠãããã»ã©å€ããããã»ãã®å°ãã ãæªããªããšæ³åããŠãã ããã ç¡é§ãªåœä»€ãããã°ã©ã ã®å
é ã«è¿œå ãããããªãã®ã ããã¯ãåœä»€ã«ãŠã³ãé¢æ°ã®å®æ°ã®ã¿ãå€æŽããŸããã挞è¿ã§ã¯ç¡èŠããŸãã ãããã£ãŠãããã°ã©ã ã®
Î( n
2 )
ã
O( n
2 )
ã§ãã
ãããããã®éã¯å¿
ãããçå®ã§ã¯ãããŸããã ããšãã°ã
Î( n )
æã€ã³ãŒã
Î( n )
ã
O( n
)
ã«å ããŠ
O( n )
ãŸãã
Î( n )
ããã°ã©ã ã
n
åå®è¡ã
for
åãªã
for
ã«ãŒãã§ãããšæ³åãããªããå¥ã®
for
insideãè¿œå ãã
n
åç¹°ãè¿ãããšã§æªåãããããšãã§ããŸãã ããã«ããã
f( n ) = n
2ã®ããã°ã©ã ãåŸãããŸãã èŠçŽïŒ
Î( a )
æã€ããã°ã©ã ã¯ã
b
ããã
b
O( b )
ã»ã©æªã
O( b )
ã§ãã ãŸããå€æŽã¯æå³ããªããªãããå
ã®ã³ãŒãã«äŒŒãã³ãŒããäœæããå¿
èŠããªãããšã«æ³šæããŠãã ããã 圌ã«å¿
èŠãªã®ã¯ãäžãããã
n
ã«é¢ããŠåœä»€ã®æ°ãå¢ããããšã ãã§ãã çµæã䜿çšããŠãåé¡ã解決ããã®ã§ã¯ãªããæ瀺ãã«ãŠã³ãããŸãã
ãããã£ãŠãããã°ã©ã ã«
O( n
2 )
ããããšèšã£ãŠããå®å
šã§ããã¢ã«ãŽãªãºã ã®åæã«ããã
n
2ãããæªããªãããšã¯ãããŸããã§ããã ããã«ãããããã°ã©ã ã®é床ãé©åã«èŠç©ããããšãã§ããŸãã æ°ããè¡šèšã§ããè¯ããªãããã«ãããã€ãã®äŸã解ããŠã¿ãŸãããã
æŒç¿3次ã®ãã¡ãæ£ãããã®ã¯ã©ãã§ããïŒ
Î( n )
ã®ã¢ã«ãŽãªãºã ã«ã¯O( n )
Î( n )
ã®ã¢ã«ãŽãªãºã ã«ã¯O( n
2 )
Î( n
2 )
ã®ã¢ã«ãŽãªãºã ã«ã¯O( n
3 )
Î( n )
ã®ã¢ã«ãŽãªãºã ã«ã¯O( 1 )
O( 1 )
ã®ã¢ã«ãŽãªãºã ã«ã¯Î( 1 )
O( n )
ã®ã¢ã«ãŽãªãºã ã«ã¯Î( 1 )
解決ç- å
ã®ããã°ã©ã ã«ã¯
Î( n )
ããããããçã§ãã ãããã£ãŠãããã°ã©ã ãå€æŽããã«O( n )
ãå®çŸã§ããŸãã n
2㯠n
ãããæªãã®ã§ãããã¯æ¬åœã§ãn
3㯠n
2ããæªãã®ã§ãããã¯æ¬åœã§ã1
n
ããæªããªãã®ã§ãããã¯åã§ãã ããã°ã©ã ãn
åœä»€ïŒç·åœ¢æ°ïŒã挞è¿çã«äœ¿çšããå Žåã 1
ïŒå®æ°ïŒã®åœä»€ã®ã¿ã挞è¿çã«å¿
èŠãšããããã«æªåãããããšã¯ã§ããŸããã- äž¡æ¹ã®å°é£ã¯åãã§ãããããæ¬åœã§ãã
- ããã¯æ¬åœãããããªãããããã§ãªããããããŸãããããã¯ã¢ã«ãŽãªãºã ã«äŸåããŸãã äžè¬çãªå Žåãããã¯åã§ãã ã¢ã«ãŽãªãºã ã
Î( 1 )
å Žåãããã¯ç¢ºãã«O( n )
ã§ãã ãã ãã O( n )
å Žåã Î( 1 )
ã§ã¯ãªãå¯èœæ§ããããŸãã ããšãã°ã Î( n )
ã¯O( n )
ã§ããã Î( 1 )
ã¯ããã§ã¯ãããŸããã
æŒç¿4ç®è¡çŽæ°ã®ã¡ã³ããŒã®åèšã䜿çšããŠãäžèšã®ããã°ã©ã ã
O( n
2 )
ã ãã§ãªã
Î( n
2 )
ã§ãããããšã蚌æããŸãã çå·®æ°åãããããªãå Žåã¯ã
ãŠã£ãããã£ã¢ãã芧ãã ãã -é£ãããããŸããã
ã¢ã«ãŽãªãºã ã®
è€é床ã¯ããã®çã®è€é床ã®
äžéã§ãããããé çªã«
Î
ã§è¡šãããããã
Î
ã
æ£ç¢ºãªæšå®å€ãäžãããšèšãããšããããŸãã èŠã€ããå¢çãæ£ç¢ºã§ãªãããšãããã£ãŠããå Žåã¯ãå°æåã®
ã䜿çšããŠããã瀺ãããšãã§ããŸãã ããšãã°ãã¢ã«ãŽãªãºã ã
Î( n )
å Žåããã®æ£ç¢ºãªè€é床ã¯
n
ã§ãã ãããã£ãŠããã®ã¢ã«ãŽãªãºã ã¯åæã«
O( n )
ãš
O( n
2 )
ã§ãã ã¢ã«ãŽãªãºã ã¯
Î( n )
ã
O( n )
ã¯å¢çãããæ£ç¢ºã«å®çŸ©ããŸãã ãããŠã
O( n
2 )
ã
( n
2 )
ïŒçºé³ïŒãnã®å°ããªoããšèªã¿ãŸã
)
æžããšãå¢çã®éåçŽæ§ãç¥ã£ãŠããããšã瀺ãããšãã§ããŸãã ãã¡ãããã¢ã«ãŽãªãºã ã®åäœã«é¢ãã詳现ãªæ
å ±ãåŸãããã«ãã¢ã«ãŽãªãºã ã®æ£ç¢ºãªå¢çãèŠã€ããããšãã§ããæ¹ãè¯ãã§ãããæ®å¿µãªãããããã¯å¿
ãããç°¡åã§ã¯ãããŸããã
æŒç¿5次ã®å¢çã®ã©ããå³å¯ã§ãã©ããå³å¯ã§ã¯ãªãããå€æããŸãã
O( n )
ãäžéãšããÎ( n )
ã¢ã«ãŽãªãºã Î( n
2 )
O( n
3 )
ãäžéãšããŠèŠã€ãã£)
ã¢ã«ãŽãªãºã Î( 1 )
O( n )
ãäžéãšããŠèŠã€ãÎ( 1 )
ã¢ã«ãŽãªãºã O( 1 )
ãäžéãšããŠèŠã€ããÎ( n )
ã¢ã«ãŽãªãºã O( 2n )
ãäžéãšããÎ( n )
ã¢ã«ãŽãªãºã
解決ç- ãã®å Žåã
Î
è€é床ãšO
è€é床ã¯åãã§ãããããå¢çã¯å³å¯ã§ã - ããã§ã
O
Î
ããã倧ããã¹ã±ãŒã«ã®è€éãã§ããããããã®å¢çã¯å³å¯ã§ã¯ãããŸããã å®éãããã§ã®å³å¯ãªå¢çã¯O( n
2 )
ã§ãã ã¢ã«ãŽãªãºã ão( n
3 )
ãšæžãããšãã§ããããã« - ç¹°ãè¿ããŸããã
O
ã¯Î
ããã倧ããªã¹ã±ãŒã«ã®è€éãã§ãããå¢çã¯å³å¯ã§ã¯ãªããšçµè«ä»ããŸãã O( 1 )
å³å¯ã§ããã O( n )
ã¯o( n )
æžãæããããšãã§ããŸã - ãã®å¢çã¯ééã£ãŠããããããã®å¢çã®å°åºã«ééãããããŸããã
Î( n )
n
ã¯1
ãããè€éãªã®ã§Î( n )
ã¢ã«ãŽãªãºã ã¯äžéO( 1 )
æã€ããšãã§ããŸããã å¿ããªãã§ãã ããã O
ã¯äžéã瀺ããŸã - éå³å¯ãªå¢çç·ãããããã«èŠãããããããŸããããå®éã«ã¯ããã§ã¯ãããŸããã å®éãå¢çç·ã¯å³å¯ã§ãã 挞è¿
2n
ãšn
ã¯åãã§ããã O
ãšÎ
ã¯æŒžè¿ã®ã¿ã«é¢é£ä»ããããŠããããšãæãåºããŠãã ããã O( 2n ) = O( n )
ã§ãããããè€éãã¯Î
ã§ãããããå¢çã¯å³å¯ã§ãã
å®çšçãªæšå¥šäºé
ïŒã¢ã«ãŽãªãºã ã®
O
è€é床ãèŠã€ããããšã¯ããã®
Î
è€é床ãããç°¡åã§ãã
ä»ã§ã¯ãããããã¹ãŠã®æ°ããè¡šèšæ³ãšæ··åãããŠãããããããŸãããã次ã®äŸã«é²ãåã«ãããã«2ã€ã®æåãç解ããŸãããã äžèšã§ãããã°ã©ã ãå€æŽããŠãOè¡šèšãäœæãããããæªåãããŸããïŒåœä»€æ°ãå¢ãããå®è¡æéãå¢ãããŸããïŒã
ã¯ãã³ãŒããç¹å®ã®å¶éããé
ããªãããšã¯æ±ºããŠãªãããšãæããŠãããŸãã ãããããè©äŸ¡ã®åºç€ãåŸãããŸããããã°ã©ã ã¯ååã§ããïŒ å察ã®ããšãè¡ããæ¢åã®ã³ãŒãã
æ¹åã ãäœãèµ·ãããã®è€éããèŠã€ããå ŽåãΩ衚èšã䜿çšããŸãã ãããã£ãŠã
Ω
ã¯è€éãããããããŸãããããã¯ããã°ã©ã ãæ¹åããããšã¯ã§ããŸããã ããã°ã©ã ãé
ãããã¢ã«ãŽãªãºã ãæªãããšã蚌æãããå Žåã«äŸ¿å©ã§ãã ãŸãããã®ç¹å®ã®å Žåã«äœ¿çšããã«ã¯ã¢ã«ãŽãªãºã ãé
ããããšèšãå Žåã«ã䜿çšã§ããŸãã ããšãã°ãã¢ã«ãŽãªãºã ã
Ω( n
3 )
ãšããããšã¯ãã¢ã«ãŽãªãºã ã
n
3ããè¯ããªãããšãæå³ããŸãã
Î( n
3 )
ããŸãã¯
Î( n
4 )
ããŸãã¯ããããæªãå ŽåããããŸããããã®ãè¯ããã®éçã¯ããããŸãã ãããã£ãŠã
Ω
ã¯ãã¢ã«ãŽãªãºã ã®è€éãã®
äžéã瀺ããŸãã
ο
ãšåæ§ã«ããã®å¶éãå³å¯ã§ãªãããšãããã£ãŠããå Žåã¯ã
Ï
æžãããšãã§ããŸãã ããšãã°ã
Î( n
3 )
ã¢ã«ãŽãªãºã ã¯
ο( n
4 )
ããã³
Ï( n
2 )
ã§ãã
Ω( n )
ãnãã倧ãããªã¡ã¬ã
Ω( n )
çºé³ããã
Ï( n )
ãnããå°ãããªã¡ã¬ã
Ï( n )
çºé³ãããŸãã
æŒç¿6次ã®Îé£æ床ã«ã€ããŠã¯ãå³å¯ãªOå¶éãšå³å¯ã§ãªãOå¶éãããã³å¿
èŠã«å¿ããŠå³å¯ãªå¶éãšå³å¯ã§ãªãΩå¶éïŒååšããå ŽåïŒãèšè¿°ããŸãã
- ÎïŒ1ïŒ
- ÎïŒânïŒ
- ÎïŒnïŒ
- ÎïŒn 2 ïŒ
- ÎïŒn 3 ïŒ
解決çããã¯ãäžèšã®å®çŸ©ãçŽæ¥äœ¿çšããæŒç¿ã§ãã
- å³å¯ãªå¢çã¯
O( 1 )
ããã³Î©( 1 )
ãŸãã éå³å¯ãªOå¢çã¯O( n )
ã§ãã Oã«ã¯äžéãããããšãæãåºããŠãã ããã n
ã¯1
ãã倧ããã¹ã±ãŒã«ã«ãããããããã¯å³å¯ãªå¶éã§ã¯ãªãã o( n )
æžãããšãã§ããŸãã ãã ãã 1
æªæºã®é¢æ°ã¯ãªãããã Ω
å³å¯ã§ãªãå¶éãèŠã€ããããšã¯ã§ããŸããã ã ãããããªãã¯å³æ Œãªåœå¢ã«å¯ŸåŠããå¿
èŠããããŸã - å³å¯ãªå¶éã¯Îè€é床ãšåãã§ãã OïŒânïŒããã³Î©ïŒânïŒãããããã éå³å¯ãªå¶éã®å Žåã
n
ânãã倧ããããO( n )
n
ãŸãã ãããŠããã®å¢çã¯å³å¯ã§ã¯ãªãã®ã§ã o( n )
æžãããšãã§ããŸãã äžã®éå³å¯ãªå¢çãšããŠãåã«Î©( 1 )
ïŒãŸãã¯Ï( 1 )
ïŒã䜿çšããŸã - å³å¯ãªå¶éã¯
O( n )
ããã³Î©( n )
ã§ãã éå³å¯ã«ã¯ã Ï( 1 )
ããã³o( n
3 )
ãŸãã ã©ã¡ããå
ã®è€éãããã¯ã»ã©é ãã®ã§ãæé«ã®å¢çç·ã§ã¯ãããŸããããç§ãã¡ã®å®çŸ©ã«åã£ãŠããŸã - å³å¯ãªå¢çã¯
O( n
2 )
ãšÎ©( n
2 )
ã§ãã éå³å¯ãªå¢çãšããŠãåã®äŸã®ããã«Ï( 1 )
ãšo( n
3 )
ã䜿çšããŸã - å³å¯ãªå¢çã¯ããããã
O( n
3 )
ããã³Î©( n
3 )
ã§ãã 2ã€ã®éå³å¯ãªå¢çã¯ãÏïŒânn2ïŒãšoïŒânn3ïŒã§ãã ãããã®å¶éã¯ãŸã å³å¯ã§ã¯ãããŸããããäžèšã§æšæž¬ããå¶éãããåªããŠããŸãã
Î
代ããã«
O
ãš
Ω
ã䜿çšããçç±ã¯ãèŠã€ãã£ãå¢çã®ç²ŸåºŠãäžæãªå Žåããã¢ã«ãŽãªãºã ãæ·±ãæãäžããããªãå Žåãããããã§ãã
ããŸããŸãªè¡šèšæ³ããã¹ãŠèŠããŠããªããŠãå¿é
ããå¿
èŠã¯ãããŸããã ãã€ã§ãæ»ã£ãŠæ
å ±ãæŽæ°ã§ããŸãã æãéèŠãªæåã¯
O
ãš
Î
ã§ãã
ãŸãã
Ω
ã¯é¢æ°ã®åäœã«äžéãäžããŸãïŒã€ãŸããããã°ã©ã ãæ¹åããŠåœä»€ã®èšç®ãå°ãªãããïŒããææªã®å Žåã®åæãåç
§ããŠããããšã«æ³šæããŠãã ããã ããã¯ãææªã®ããŒã¿ã»ãããããã°ã©ã ã«ãã£ãŒããããã®åäœãåæããããã§ãã
次ã®è¡šã¯ãäžèšã§ç€ºããèšå·ãšãæ°å€ãæ¯èŒããããã®éåžžã®æ°åŠã¢ã€ã³ã³ãšã®é¢ä¿ããŸãšãããã®ã§ãã éåžžã®æ°åŠè¡šèšã®ä»£ããã«ã®ãªã·ã£æåã䜿çšããçç±ã¯ãéåžžã§ã¯ãªã挞è¿æšå®å€ã®æ¯èŒãæ±ã£ãŠããããšã瀺ãå¿
èŠãããããã§ãã
挞è¿æšå®ã®æ¯èŒæŒç®å | æ°å€æ¯èŒæŒç®å |
---|
ã¢ã«ãŽãªãºã ã¯o ïŒäœãïŒã§ã | æ°< |
O ( - ) | †- |
Î ( - ) | = - |
Ω ( - ) | ⥠- |
Ï ( - ) | > - |
: ,
O
,
o
,
Ω
,
Ï
Î
,
O
, ,
Î
, ,
Ω
.