?????(Analyzing Algorithms)

- ??
- ???????? ??Java??, ??? ?, ??????, 2005.
- Introduction to the Design and Analysis of

Algorithms -- A strategic approach, 2E, R.C.T.

Lee et. al., NcGraw Hill, 2005. - Introduction to Algorithms, Cormen et. al., MIT

Press.

?????

- ?????????????????????(resources)?????
- ??(Resources)???(memory),??(communication),??(ban

dwidth),??? (logic gate),??(time)

?????

- ???????(running time)???????????????????????
- ????????????(machine-independent) ???

???(Complexity)

- ??????
- ?????(time complexity)
- ?????(space complexity)
- ????????????????????,
- ???????,?????????
- ??????time complexity!

????

- ?????????????????
- ????(best case)?????????????????????????
- ????(worst case)?????????????????????????
- ????(average case)??????????????????????????

????????????

- ??,????????????????(worst-case running time)
- ??
- ????????(upper bound)?
- ??????????
- ?????????????????????(insertion sort)

??????(quadratic function)?

????????????

Algorithm Prime1(n)Input????2????nOutputtrue?false(??n????????)for i?2 to n-1 do if (ni)0 then return falsereturn true

- ??????,????2??????n,?n???,????Prime1???????????(n

i)???????((ni)0)??n-2???,?????n??????,?n????,???

?Prime1??????????????????1?,?????n??????

?????????????

- ??????,????2??????n,?n???,????Prime2???????????(n

i)???????((ni)0)?? -2???,?????n??????,?n????,?

???Prime2??????????????????1?,?????n??????

?????Prime1

- ??,????????,?????(worst case)?,???Prime1??????????

????n???????????(best case)?,???Prime1???????????

????n????????????,???Prime1?????(linear)

?????????(??????????)????(constant) ??????????

?????Prime2

- ?????????,?????(worst case)?,???Prime2????????????

????n???????????(best case)?,???Prime2???????????

????n????????????,???Prime2??????(square root)

?????????????(constant) ??????????

????(Asymptotic Notation)

- ????,???????????(asymptotic notation)??????????,??

??????????????????????,???????(problem

size)??????????? - ???????????(??????)???,???????(???????)???????(???

????)???????????????,??????,???????????????????? - ??????????(??????)????,??????????????????????????

??????????????????????????????,???????????????(???

???)??????,??????????????????????????

??(Order)

- ????????????????????,?????????????????(order)?????

,???????????????,?????????????????,???????????????

?????,??????????????,?????????????????? - ??,?????????????n-2,??n???(??????)?,?????????????n

,?????????(???)??(??????????????????????????????)

?????????????35n212n11,??n???(??????)?,?????????

????n2,????????????????????28n31245n2162n321,?

?n????(???????),?????????????n3(??????)?

?O??(Big-O Notation)

- ???????O??(Big-O notation)??????????,?O???????????

???????????(order)???,??????????O?????????

????,?????????????????????,????????????????????????(order),????????O????(O ??order??)?

???O??

- ?????????O??
- ?? ?O?? (Big-O notation)
- ?f(n)?g(n)????????????????,????????cgt0??????n0???

???n?n0??,f(n)?cg(n)??,????f(n)O(g(n))?(??

?f(n)???Big-O of g(n)?,???????????f of n is of

Big-O of g of n?)? - ??,??35n212n11??,??c58?n01(58?351211??),???n

?n01?,35n212n11?cn2(58n2)??,??,???35n212n11

O(n2)?

?????(Asymptotic Upper Bound)

- Def f(n) O(g(n)) ??(upper bound)"
- iff ? c, n0 ? f(n) ? cg(n) ? n ? n0
- e.g. f(n) 3n2 2
- g(n) n2
- ? n02, c4
- ? f(n) O(n2)
- e.g. f(n) n3 n O(n3)
- e. g. f(n) 3n2 2 O(n3) or O(n100 )

?????(Asymptotic Upper Bound)

?????(Asymptotic Lower Bound )

- Def f(n) ?(g(n)) ??(lower bound)
- iff ? c, and n0, ? f(n) ? cg(n) ? n ?

n0 - e. g. f(n) 3n2 2 ?(n2) or ? (n)

?????(Asymptotic Lower Bound )

Theta??

- Def f(n) ?(g(n))
- iff ? c1, c2, and n0, ? c1g(n) ? f(n) ?

c2g(n) ? n ? n0 - e. g. f(n) 3n2 2 ? (n2)

Theta??

- f(n) ?(g(n))

Theorem

- ??????f(n) ? g(n),
- ?

????????

- ?????????????????????????(?????,problem

size)??????????,??????????????????(?????,execution

time)??????????,?????????????????,???????????????

??,?????????????????????????????????????

?????

- ????????????????????,??????????????,??????????????

?? - O(1) lt O(log n) lt O( ) lt O(n) lt O(n log n) lt

O(n2) lt O(n3) lt O(2n)O(n!) ? O(nn)

??????????O????????

????? ??O???? ??

162 O(1) ?????(constant)??

63log n4 O(log n) ???(??)(sub-linear, logarithmic)??

37 52 O( ) ???(square root)??

n-2 O(n) ??(linear)??

156n81 O(n) ??(linear)??

35n212n11 O(n2) ??(quadratic)??

28n31245n2162n321 O(n3) ??(cubic)??

14?2n457n3248n2-45n81 O(2n) ??(exponential)??

???????????????????

log n n n logn n2 n3 2n

0 1.00 1 0 1 1 2

1 1.41 2 2 4 8 4

2 2.00 4 8 16 64 16

3 2.83 8 24 64 512 256

4 4.00 16 64 256 4,096 65,536

5 5.66 32 160 1,024 32,768 4,294,967,296

???????????????

???????????????(???)

???????? vs. ???????

- ??????????O(p(n))????,???p(n) ????????,???????????

???(polynomial time algorithm)?????,?p(n)???????,?

?????????????(exponential time algorithm)

(No Transcript)

(No Transcript)

????? (ceiling) ?????? (floor)

????(modular operation)

- ?????a ? ?????n, ??a mod n ? a/n ???
- a mod n a -?a/n?n.
- ?(a mod n) (b mod n), ?????? a ? b (mod n)???a

?b ?mod n (modulo n)????(equivalent)?? - ????a ? b (mod n) ?a ?b ?mod n?????????