|
°£´ÜÇÑ ¼öÇà½Ã°£ °è»ê (»ç·Ê 1)
|
|
¡á ´ÙÀ½ ÇÁ·Î±×·¥Àº À» ±¸ÇÏ´Â ÇÁ·Î±×·¥
int sum( int n )
{ int partial_sum
= 0; ································· ¨ç
for(
int i = 1; i <= n; i++ ) ······················
¨è
partial_sum += i * i * i;
························
¨é
return
partial_sum; ································
¨ê
}
|
1´ÜÀ§
2n+2 ´ÜÀ§
3n ´ÜÀ§
1´ÜÀ§
|
ÀÌ ÇÁ·Î±×·¥Àº ¨çÇà, ¨êÇà¿¡¼ °¢°¢
1´ÜÀ§, ¨éÇà¿¡¼ 3n ´ÜÀ§, ¨èÇà¿¡¼ 2n+2 ´ÜÀ§ ½Ã°£ÀÌ ¼öÇàµÇ¸ç
µû¶ó¼ ÃÑ 5n+4´ÜÀ§½Ã°£ÀÌ °É¸°´Ù. Áï, ÀÌ ÇÁ·Î±×·¥ÀÇ ¼öÇà½Ã°£Àº O(n)
ÀÌ´Ù.
ÀÌ¿Í °°Àº °è»êÀ» ºü¸£°Ô ÃßÁ¤ÇÏ´Â ¹æ¹ýÀº Áß¿äÇÏÁö
¾ÊÀº °÷Àº »ý·«ÇÏ°í »ó¼öµµ »ý·«ÇÏ¸é¼ °è»êÇÏ´Â ¹æ¹ýÀÌ´Ù.
Áï, 3ÇàÀÇ ¼öÇà½Ã°£Àº O(1)À̸ç, for¹®ÀÌ n¹ø ¹Ýº¹µÇ¹Ç·Î O(n)À̶ó°í
»¡¸® °è»êÇÒ ¼ö ÀÖ´Ù.
|