ã¯ããã«
ãã¢ã«ã´ãªãºã ã®è¨ç®éã表ç¾ãããã¼ã«ã¨ãã¦ï¼$O$-notation ã¨ããã®ã¯ç«¶æããã°ã©ãã³ã°ã®æèã§ãããåºã¦ãã¾ãï¼ãã®ä¸æ¹ã§ï¼$O$-notation ã®å°å
¥ãããµãã£ãã¨è¡ãããã±ã¼ã¹ã¯ããªãå¤ãï¼å³å¯ã«å®ç¾©ãã¦å°å
¥ããå ´é¢ã¨ããã®ãå®ã¯å°ãªãããã«ãè¦åãããã¾ãï¼ããã¯ããã§æ·å±
ãä½ããªã£ã¦ããã®ã§ããï¼å®ç¾©ã notion ã«èª¤è§£ãããã¨ã³ãã¥ãã±ã¼ã·ã§ã³ã§é½é½¬ãçããå¯è½æ§ããããã¨æãã¾ãï¼å®éï¼$O$-notation ã®å®ç¾©ããããã¨ãããã£ã¦ãããããªãï¼ãã¨æãããããªä½¿ç¨ä¾ããã°ãã°è¦åãããã¾ãï¼ä¾ãã°ã$O(1{,}000{,}000{,}000 )$ãã ã¨ãï¼ããã®å¦çã«ã¯å°ãªãã¨ã $O( f(n) )$ ãããããªã©ã§ãï¼
ã競æããã°ã©ãã³ã°ã«åãçµãå ´é¢ã«ããã¦ãã®æã®ä¸ç解ãè´å½çãªäºæ
ããããããã¨ã¯ãã¾ãããã¾ãããï¼ãã¯ãã«ã«ã¿ã¼ã ãç¨ããã³ãã¥ãã±ã¼ã·ã§ã³ã§é½é½¬ãçã¾ãªãããã«ã¯å®ç¾©ããã£ããæãã¦ããã¹ãã ã¨æãã¾ãã®ã§ï¼æ¬ç¨¿ã§ã¯ãã®ãããã«ã¤ãã¦æ¸ãã¦ã¿ããã¨æãã¾ãï¼ã§ãã®ã§ï¼å
ç¨ã®ä¾ã«å¯¾ãã¦ãããã£ã¦ $O( 1 )$ ããããã¨ãã$\Omega$ ã§æ¸ãã°ãããªãï¼ãã¨è¨ãã人ã¯ï¼ãã®è¨äºãèªãã§ãæ¢ç¥ã®äºæã°ããããããã¾ãã*1ï¼æ°å¼ãç»å ´ãã¾ããï¼èªã¿æ¹ããæ°æã¡ãä¸ç·ã«æ¸ãã¦ããã¾ãã®ã§ï¼è¦ãç®ã§ããã£ãã¨ãªããã«ããã ããã¨ãããããã§ãï¼
O-notation
ã$O$-notation ãéã«ä½¿ã£ã¦ãã人ã®å¤ãã¯ï¼ãå¦çæéã $O( * )$ ã®ã«ãã³å
ã«ãããã¤ã®å®æ°åã«æ¯ä¾ããããããã®æå³ã§ä½¿ã£ã¦ãããã¨æããã¾ãï¼ããããã㯠$O$-notation ã®å®ç¾©ããããã¨å¿
ãããæ£ããããã¾ããï¼å®éã«ã¯ï¼$O$-notation ã¯ï¼å¦çæéã«ã¤ãã¦ã®æèã§ä½¿ããªãï¼å¦çæéã®ä¸çã«ããè¨åãã¦ãã¾ãã*2ï¼$O( n^3 )$ æéã§åä½ããã¢ã«ã´ãªãºã ã $O( n^5 )$ æéã¢ã«ã´ãªãºã ã ã¨ä¸»å¼µãã¦ãï¼ããã¯æ£ãã主張ã§ã*3ï¼
ãã§ã¯ï¼$O$-notation ã®å®ç¾©ãè¦ã¦ã¿ã¾ãããï¼"Introduction to Algorithms" [1] ã§ã¯ï¼ä»¥ä¸ã®ãããªæãã§å®ç¾©ããã¦ãã¾ãï¼ããæ¸ãæ¹ãå¤ãã¦ãã¾ãï¼ï¼
$$
O( g( n ) ) \overset{ \mathrm{ def } }\Longleftrightarrow \{ f( n ) \mid \exists c, \exists n_0, \forall n \geq n_0, 0 \leq f( n ) \leq c g( n ) \}
$$
ããã§ï¼$f, g$ ã¯é¢æ°ã§ãï¼ã¾ãï¼$O( g( n ) )$ ã¯é¢æ° $g( n )$ ã«ãã£ã¦å®ã¾ãé¢æ°ã®éåã§ããã¨ããç¹ã«ã¯æ³¨æãã¦ãããæ¹ãããããããã¾ããï¼é¢æ° $f( n ) \in O( g( n ) )$ ã§ãããããªé¢æ° $f( n )$ ã¨ããã®ã¯ã©ãããé¢æ°ãã¨ããã¨ï¼å³è¾ºã®å
å
表è¨ãä¸å¯§ã«èªãã§ãããã°ï¼
- ããå®æ° $c$ 㨠$n_0$ ããã¾ãã¨ã£ã¦ãããã¨ãï¼
- $n_0$ 以ä¸ã®å ¨ã¦ã® $n$ ã«å¯¾ãã¦ï¼
- $f( n ) \leq cg( n )$ ã§ããâ¦â¦ã¤ã¾ãï¼$f( n )$ ã®å¤ã¯ $g( n )$ ã®å®æ°ï¼$c$ï¼å以ä¸ã§ãã
ãã㪠$f( n )$ ã§ãï¼ãæ°æã¡ã¨ãã¦ã¯ï¼ãå¼æ° $n$ ãå°ããã¨ããã§ã®æ¯ãèãã¯ç½®ãã¦ããã¦ï¼$n \geq n_0$ ã表ç¾ãã¦ããï¼ï¼ããç¨åº¦å¤§ã㪠$n$ ã«å¯¾ãã¦ã¯å¸¸ã« $f( n )$ 㯠$g( n )$ ã®å®æ°ï¼$c$ï¼å以ä¸ã§ãããã¨ããæãã§ãï¼ã¾ãï¼ããè¦ããã $f( n ) = O( g( n ) )$ ã¨ãã風ãªè¡¨è¨ã¯è¨å·ãå³å¯ã«ä½¿ãã° $f( n ) \in O( g( n ) )$ ã§ãã®ã§çå·ã®å·¦å³ã交æã§ãã¾ããï¼ãã®æå³ã§çå·ããã£ã¦ãã¦ã»ããæ§è³ªããã£ã¦ããªãï¼ã¨ãããæ¬æ¥çå·ã§ã¯ãªãï¼ã®ã§ããï¼ãã®ãè¨å·ã®æ¿«ç¨ã*4ã¯ããè¡ããã¦ãã¾ã*5ï¼
åé ã«æãã誤ç¨ï¼ï¼ï¼ã®è©±
ããã¦ï¼åé 㧠$O( 1{,}000{,}000{,}000 )$ ããå°ãªãã¨ã $O( n )$ æéå¿ è¦ãã¯å¤ã§ããã¨æ¸ãã¾ããï¼ãããã«ã¤ã㦠$O$-notation ã®å®ç¾©ãè¸ã¾ãã¦è¦³å¯ãã¦ã¿ããã¨æãã¾ãï¼
$O( 1{,}000{,}000{,}000 )$ ?
ã$O( 1 )$ ã¨ããéåãèãã¦ï¼$\exists c$ ã®ã¨ãã㧠$c = 1{,}000{,}000{,}000$ ã¨ãï¼$O( 1{,}000{,}000{,}000 )$ ã®å´ã§ã¯ $c = 1$ ã¨ã¨ã£ã¦ãããã¨ï¼$c g( n )$ ã®ã¨ãããä¸è´ã㦠$O( 1{,}000{,}000{,}000 )$ ã¨çãããªãã¾ãã®ã§ï¼éåã¨ãã¦åãã«ã§ãã¾ãï¼ããã«ã¤ãã¦ã¯ãééããã¨ãããã¨ã§ã¯ããã¾ãããï¼é常ï¼ã«ãã³ã®ä¸ã¯ç°¡åãªå½¢ã®å¼ã«ãªãããã«æ¸ããããã¨ãå¤ãï¼ã¾ãï¼å¤§ããªå®æ°ãæ¸ããã¨ã«ãã£ã¦ç¹æ®µä½ããä¼ãããã£ãã¨ãã¦ãï¼å®ç¾©çã«ã¯ä¼ãããªãã¨ãããã¨ã«ãªãã¾ãï¼
ãå°ãªãã¨ã $O( n )$ æéå¿ è¦ãï¼
ããã¡ãã«ã¤ãã¦ã¯ï¼ä¾ãã° $O( 1 ) \subseteq O( n )$ ã ã£ãããããã¨ã«æ³¨æããã¨ï¼ãå°ãªãã¨ãããã ãå¿ è¦ãã¿ãããªãæ°æã¡ãããã¾ãæ£ãã表ç¾ããã¦ãã¾ããï¼$O$-notation ã¯ããã以ä¸ãã表ãã¦ããã®ã«å¯¾ãã¦ï¼ãå°ãªãã¨ãï½ï½ããããã¯ããã以ä¸ãã¨ããæ°æã¡ã表ç¾ãã¦ããããã§ãï¼
ã¢ã«ã´ãªãºã åéã§ã® $O$-notation
ãã¢ã«ã´ãªãºã ã®æèã§ã¯å
¸åçã«ã¯åç¯ã®å®ç¾©å¼ã«ãããé¢æ° $f$ ã¯ãå
¥åãµã¤ãºãããå¿
è¦ãªã½ã¼ã¹ï¼æé or 空éï¼ãã¸åãé¢æ°ã§ãï¼æéã®æå³ã§ã®ãªã½ã¼ã¹ã¯ãã®ã¾ã¾å®è¡æéã®ãã¨ãè¨ã£ã¦ãã¦ï¼ç©ºéã¨ããã®ã¯å¿
è¦ãªã¡ã¢ãªã®éã®ãã¨ãè¨ãã¾ãï¼
ã競æããã°ã©ãã³ã°å«ãã¢ã«ã´ãªãºã åé㧠$O$-notation ã使ã£ã¦ããã®ã¢ã«ã´ãªãºã 㯠$O( g( n ) )$ æéã§ãããã¨ãã£ã主張ãããã¨ãï¼ãã®ä¸»å¼µãã¡ããã¨è¨ãã¨ï¼
- çç®ãã¦ããã¢ã«ã´ãªãºã ã®å®è¡æéã¯ï¼ã¢ã«ã´ãªãºã ã¸ã®å ¥åã®ãããé·ã $n$ ã¨ãã¦é¢æ° $f( n )$ ã§è¡¨ããï¼$f( n ) \in O( g( n ) )$ ã§ãã
ãªã©ã®æå³ã§ç¨ãããã¾ãï¼ã¾ãï¼ã°ã©ãã¢ã«ã´ãªãºã ã§ã¯ãã°ã©ãã®é ç¹æ°ããå®è¡æéã¸ã®é¢æ°ãã ã£ããï¼æ°è«ã¢ã«ã´ãªãºã ï¼ã£ã¦å¼ã³æ¹ã§ããã®ããªï¼ï¼*6ã§ã¯ãå
¥åã表ç¾ãã¦ããæ´æ° $n$ ããå®è¡æéã¸ã®é¢æ°ãã§ãã£ãããã¾ãï¼è©³ç´°ã¯çãã¾ããï¼æ¬æ¥ã¨ãããï¼å義çã«ã¯ããã¥ã¼ãªã³ã°ãã·ã³ã¸ã®å
¥åé·ããããå®è¡æéã¸ã®é¢æ°ãã§ãã®ã§*7ï¼ã¡ãã£ã¨æ³¨æãã¦ããå¿
è¦ãããã¾ã*8ï¼
ãã¾ãï¼åç¯æå¾ã®ãå¼æ° $n$ ãå°ããã¨ããã§ã®æ¯ãèãã¯ç½®ãã¦ããã¦ï¼ããç¨åº¦å¤§ã㪠$n$ ã«å¯¾ãã¦ã¯å¸¸ã« $f( n )$ 㯠$g( n )$ ã®å®æ°å以ä¸ã§ãããã¨ããã®ã¯ï¼ã¢ã«ã´ãªãºã ã¨çµ¡ãã¦ä¾ãæããã¨ï¼ä¾ãã° $O( n \log n ) \subseteq O( n^2 )$ ã¨ããäºå®ã¯ï¼ãé
åãã½ã¼ãããã¨ãï¼ããç¨åº¦å¤§ããé
åã«å¯¾ãã¦ã¯ $O( n \log n )$ ã®ãã¼ã¸ã½ã¼ããåªç§ã ãï¼å
¥åãå°ãã㨠$O( n^2 )$ ã®æ¿å
¥ã½ã¼ããéããããããªããã¨ãã£ãæãã§ã*9ï¼åºæ¬çã«ã¯ï¼
- å ¥åãµã¤ãº $n$ ãç¡éã«å¤§ãããã¦ãã£ãã¨ãã«ï¼å¿ è¦ãªã½ã¼ã¹é $f( n )$ ã¯å ¥åãµã¤ãºã®å¢å¤§ã«å¯¾å¿ãã¦ã©ã®ããã«å¢ãã¦ããã®ãï¼
ã¨ããç¹ã«çç®ãã¦ãã¾ãï¼ãªã®ã§ï¼ä¾ãã°ï¼ãå ¥åãµã¤ãºã«é¢ããã常㫠2 åéã§å¤ãæ¢ç´¢ããã¢ã«ã´ãªãºã ãããã£ãã¨ããã°ï¼ãã㯠$O( 1 )$ æéã¢ã«ã´ãªãºã ã§ãï¼$O( 1 )$ æéã¨ããã¨ãä¸ç¬ã§çµãããã¨ããã¤ã¡ã¼ã¸ãããã¾ããï¼æ£ããã¯ãå ¥åé·ã«ä¾åããªãããããã®æå³ãªã®ã§æ³¨æãå¿ è¦ã§ãï¼å ¥åé·ãç¡éã«å¤§ãããªã£ã¦ã常ã«ãå®æ°æéããªã®ã¯ããæå³ãä¸ç¬ãã§ã¯ããã®ã§ããâ¦â¦ï¼
$\Omega$-notation 㨠$\Theta$-notation
ãããã¾ã§è¦ã¦ããããã«ï¼$O$-notation ã¯ãä¸çãã表ãã¦ãã¾ãï¼å
ç¨ããããå°ãªãã¨ããããããã®æéããããããªã©ãè¨ãããã¨ãã«ã¯ãä¸çãã表ç¾ã§ããè¨å·ãããã¨ä¾¿å©ã§ãï¼ä¸çã¯è¨å· $\Omega$ ã使ã£ã¦ $\Omega( g( n ) )$ ãªã©ã¨æ¸ãã¾ãï¼å®ç¾©ã¨ãã¦ã¯ $O$-notation ã¨ã»ã¼åæ§ã§ï¼
$$
\Omega( g( n ) ) \overset{ \mathrm{ def } }\Longleftrightarrow \{ f( n ) \mid \exists c, \exists n_0, \forall n \geq n_0, 0 \leq c g( n ) \leq f( n ) \}
$$
ã§ãï¼$O$-notation ã¨ã®éãã¯ï¼å
å
表è¨ã®ä¸çªå³ã§ $f( n )$ 㨠$c g( n ) )$ ã®ä½ç½®ãå
¥ãæ¿ãã£ã¦ããã ãã§ãï¼$O$-notation ã¨åæ§ä¸å¯§ã«èªãã§ãããã°ï¼
- ããå®æ° $c$ 㨠$n_0$ ããã¾ãã¨ã£ã¦ãããã¨ãï¼
- $n_0$ 以ä¸ã®å ¨ã¦ã® $n$ ã«å¯¾ãã¦ï¼
- $c g( n ) \leq f( n )$ ã§ããâ¦â¦ã¤ã¾ãï¼$f( n )$ ã®å¤ã¯ $g( n )$ ã®å®æ°ï¼$c$ï¼å以ä¸ã§ãã
ã¨ãªãã¾ãï¼
ãã¾ãï¼$O( g( n ) )$ 㨠$\Omega( g( n ) )$ ã®å
±éé¨åãï¼è¨å· $\Theta$ ã使ã£ã¦ï¼
$$
\Theta( g( n ) ) \overset{ \mathrm{ def } }\Longleftrightarrow O( g( n ) ) \cap \Omega( g( n ) )
$$
ã¨æ¸ãã¾ãï¼$f( n ) \in \Theta( g( n ) )$ ã¨è¡¨æããã°ï¼ä¸çã¨ä¸çã®ä¸¡æ¹ããæãããã¨ãã§ãã¦ï¼ãå®æ°åã«æ¯ä¾ãããã«è¿ãæ°æã¡ã表ç¾ãããã¨ãã«ããé©åãªè¨æ³ã¨ãªãã¾ãï¼
å¹³åã¨ãææªã¨ã
ã$O$-notation ã¯é¢æ°ã®ï¼çºæ£é度ã®ï¼ä¸çã«è¨åããã¨æ¸ãã¾ããï¼ãä¸çãã¯ããã以ä¸ãã«è¿ããããªæ°æã¡ã®è¨èã§ããï¼ã ããã¨ãã£ã¦ï¼$O$-notation ã§è¡¨ãããè¨ç®éãï¼å¯¾è±¡ã®ã¢ã«ã´ãªãºã ãæ大ã§å©ç¨ããè¨ç®ãªã½ã¼ã¹ã¨ã¯éãã¾ããï¼ããã¯ï¼ã¢ã«ã´ãªãºã ã®å¹³åè¨ç®éã表ç¾ããã®ãææªè¨ç®éã表ç¾ããã®ãã«ãã£ã¦å¤ãã£ã¦ãã¾ãï¼ã¯ã¤ãã¯ã½ã¼ããä¾ã«ããã°ï¼
- ã¯ã¤ãã¯ã½ã¼ãã®å¹³åè¨ç®é㯠$O( n \log n )$ æé
- ã¯ã¤ãã¯ã½ã¼ãã®ææªè¨ç®é㯠$\Theta( n^2 )$ æé
ã¨ãã 2 ã¤ã®ä¸»å¼µã¯ããããæ£ããã§ãï¼ç«¶æããã°ã©ãã³ã°ã§ã¯ç«¶æã®æ§è³ªä¸å°ãææªè¨ç®éã«ã¤ãã¦ã®è©±ããã¾ããï¼æ¬æ¥ã¯ä½ã«ã¤ãã¦è©±ããã¦ããããæèããå¿ è¦ãããã¾ãï¼
ãããã«
ããããã漸è¿è¨æ³ã«ã¤ãã¦ï¼ç«¶æããã°ã©ãã³ã°ã§é »åºã® $O$-notation ããï¼ããã¨è°è«ï¼è¡¨ç¾ï¼ããããã $\Omega$-notation, $\Theta$-notation ã¾ã§çºãã¦ãã¾ãã*10ï¼æ¬ç¨¿ãç解ã®å©ãã¨ãªãã¾ããã幸ãã§ãï¼
åèæç®
[1] Cormen, Thomas H., et al. Introduction to algorithms. MIT press, 2009.
*1:ããã¯ããã¨ãã¦ï¼å 容ã®ä¸åçã¸ã®ææã¯æè¿ã§ã
*2:i.e. ã大ããã¦ãããããããã¨ãã話ã§ãã£ã¦ï¼å¿ ããããã®å¤§ããã«ãªãã¨ã¯éããªã
*3:ãã¡ããï¼ãããããä¸çããç¥ããã¦ãããªããã¡ãã§è¡¨è¨ããæ¹ã好ã¾ããã¯ããã¾ãï¼ã¨ã¯ããï¼è§£æãçãäºã«ãã£ã¦ææ°ã大ããã¢ã«ã´ãªãºã ãï¼è§£æã®æ¹åã ãã§è¨ç®éãæ¹åãããè«æãåºã¦ããããã§ãï¼æå°æå®æ°ããåå¨æ§ã ããèããã®ã§ refer ãã¾ããï¼ï¼
*4:ãè¨å·ã®æ¿«ç¨ãã§ãã¯ãã«ã«ã¿ã¼ã ããã Wikipedia 先輩に記事ãç«ã£ã¦ã¾ãã
*5:ãã¾ã好ãã§ã¯ããã¾ããã
*6:ç´ æ°å¤å®ã¨ããããããã¤
*7:ãã¥ã¼ãªã³ã°ãã·ã³ã ã¨è°è«ãç ©éãªã®ã§ä»ã®ãè¨ç®ã¢ãã«ãã使ããã¨ã®æ¹ãå¤ãæ°ããã¾ããï¼è²ã é¢åãªã®ã§ãã®è¾ºã¯å²æãã¾ã
*8:ãªã®ã§ï¼ãæ´æ°ããªã©ãå ¥åã«ãªã£ã¦ããã¨ãï¼æ´æ° $x$ ã®ãããé·ã¨ããã®ã¯ãã®æ´æ°ã® $\log x$ ç¨åº¦ãªã®ã§ï¼æ¬æ¥ã¯æ°ãã¤ãã¦è°è«ããå¿ è¦ãããã¾ãï¼ãæ¬å¤é å¼æéããªã©ã§èª¿ã¹ã¦ã¿ã¾ããã
*9:ãã®ä¾ã ã¨ã¯ã¤ãã¯ã½ã¼ãã¯åºãã«ãããã©ï¼ã¤ã³ããã½ã¼ãã¨ãè¨ããããªãâ¦â¦
*10:å®ã¯ $o$-notation ã¨$\omega$-notation ãããã®ã§ãã Wikipedia 先輩ã«ä»»ãã¾ã