Cormen, Leiserson, Rivest, Introduction to Algorithms . PowerPoint PPT Presentation

presentation player overlay
1 / 26
About This Presentation
Transcript and Presenter's Notes

Title: Cormen, Leiserson, Rivest, Introduction to Algorithms .


1
???? ??????
Lecture1 of Geiger Itais slide
brochure www.cs.technion.ac.il/dang/courseDS
???? ??????
CS-234218
??? ?????? ?????? (???? ?? ?????) Cormen,
Leiserson, Rivest, Introduction to Algorithms .
?GeigerItai,2001
2
???? ??????
Lecture1 of Geiger Itais slide
brochure www.cs.technion.ac.il/dang/courseDS
????? ?????
  • ????? ?? ???? ?????? ????????? ???????
  • ????? ???? ?????? ??????
  • ????? ???? ?????? ?????? ?????

??????? ????? ?????? ??????, ???, ?????, ???
????????, ???? ?????...
??????? ???????? ????, ????? ???? ?????, ?????
?????, ????? ???? ????, ????
?GeigerItai,2001
3
?????? ?????
  1. ???? ?????? ??????? ???????? ???????????
  2. ?????? ??????? ???????
  3. ???? ???? ?????
  4. ??? AVL
  5. ??? 3-2
  6. ?????? ???????
  7. ?????? ?????
  8. ????? ?????? ????
  9. ????
  10. ????? ????????
  11. ?????
  12. ????? ????

4
?????? ???????
????? ?????? ???????? (Abstract Data Type ADT)
??? ???? ?? ?????? ?? ????? ??????. ????? ??
???? ?????? ??? ???? ?????????, ??? ??? ?????,
?????? ?? ??????? ?? ???? ???????.
????? ??? ???????
??? ??? ???? ?? ????? ?-? top
8
7
?????
top -1 ????? ????top top 1 Atop x
??? ???????if top gt-1 returnAtop
????? ???? top top 1

6
top
5
4
3
2
1
0
?? ! ??? ????? ?? ?????? ??????? ???? ??????.
5
?????? ?????? ?????? ????????
Last In -- First Out LIFO ????? ????
????? ????
?????? (Stack) ?????? ?"? ??????? ?????
create(S) ????? ?????? S ???? ????. push(S,x)
????? ???? ??? ??? x ???? ??????? S. top(S)
????? ?? ????? ????? ??????? S (??????? ????
?????). pop(S) ????? ?? ????? ????? ???????
S. is-empty(S) ????? true ?? ??????? S ????
?-false ????.
6
?????? ?????? ?????? ???????? (????)
?????? ??????? ??????? ?? ?????? ????? ???? ????
pop, top ?? ?? ?????? ?? ????. ??? ????
create(S), is-empty(S) ????? ??? true. ???? ?????
push, ?????? pop, ??????? ?? ?????.
?? ????? ???? ????? ?? ??????? ?????? ??
??????. ?? ????? ??????? ?? ???????, ??? ????
??????. ??????
7
?????? ??????
  1. ????? ????? ???? (??? ??????).
  2. ????? ????? ????? ??????.

define NULL 0 typedef struct node DATA_TYPE
info struct node next NODE typedef NODE
STACK
????? ????
????? ?????? ????
void create (STACK s) (s) NULL
8
????? ????
????? push(s,x)
void push ( STACK s, DATA_TYPE x) NODE
P P malloc (sizeof (NODE)) P -gt info x P
-gt next (s) (s) p
void push ( STACK s, DATA_TYPE x) NODE
P P malloc (sizeof (NODE)) P -gt info x P
-gt next (s) (s) p
void push ( STACK s, DATA_TYPE x) NODE
P P malloc (sizeof (NODE)) P -gt info x P
-gt next (s) (s) p
void push ( STACK s, DATA_TYPE x) NODE
P P malloc (sizeof (NODE)) P -gt info x P
-gt next (s) (s) p
void push ( STACK s, DATA_TYPE x) NODE
P P malloc (sizeof (NODE)) P -gt info x P
-gt next (s) (s) p
9
????? ?????? ????
????? pop(s)
void pop ( STACK s) STACK t t (s) ?
next free (s) (s) t
????? top(s)
DATA_TYPE top ( STACK s) return (s) ? info

10
??? ????? ??????
First In -- First Out FIFO ????? ????
????? ????
??? (Queue) ????? ?"? ??????? ????? create(Q)
????? ??? ???. head(Q) ????? ?? ??? ????? ?????
???? Q (???? ???? ?????). enqueue(Q,x) ?????
???? ?? ??? x ???? ???? Q. dequeue(Q) ????? ??
????? ????? ???? Q. is-empty(Q) ????? true ??
???? Q ??? ?-false ????.
11
????? ?? ??? ????? ????
head(Q) Qf enqueue(Q,x) Qr
x r (r1)
n dequeue(Q) f (f1) n is_empty(Q)
f r create(Q) f r 0
???? Q ?? n ?????? ?? ??? ???????
r ????? ?? ???? ????? ????? ??? ???? (rear) f
????? ?? ???? ????? ????? ???? (front)
?????? ?????? ??????? ?????????? ????? mod n(
n). ???? ??? ??. f (r 1) n ?? ????? "??
???" ????enqueue ?"?? ???" ???? .dequeue
???????
???
n9
12
????? ??? ?"? ????? ??????
????? ???? ???? (last)
last
????? ???? ???? (first) . ???? ?? ??? ???? ??????
???? ??????? ?????? last.
13
????? ???? ADT ????????
?????? ?-ADT ???? ?? ??????? ??????? ??
???????. ???? ???? ????? ?? ???? ??????.
???? ?????? ???? ?????? ?? ????? ???? ???????
???? ????? ????????. ????? ????? ??????? ??????
???? ?? ???????.
  • ????? ?????? ??????? ?"?
  • ??????
  • ??? ???? ???? ?????? ???????, ??? ?????.
  • ???? ???? ??????? ??????.
  • ????? ??????? (????? ????? ???? ?????? ????? ).

14
??? ???? ?? ????????
??? ???? ?? ???????? A ???? ??? x ????? ?-tA(x) .
??? ????? ???? ?"? ???? ?????? ????? ??????????
???? ?? ??? ????. ??? ?? ????? ?????? ??????? ???
???????. (????, ???? ????? ???). ????? ?? ??? x
????? ?- x. ??????, ??????? ?????? ????? ????
x, ???? ???? ??? ???? ????? ?????. ??? ?????
????? ?????(worst case) ?? ???????? A ???? ???
?????? n ????? ?"? tA(n) maxx tA(x) xn .
15
??? ???? ?? ????????
sum 0 for (i 0 i lt n i) if sum lt
ai1 sum sum ai else terminate
????? 2
??? ??? ????? ?? ?????????? ??? ????? ????? ?????
?? ???????? ?? ????? tA(n) c1?n c2
16
???????? ??????? O
????? ???? f(n), g(n) ???????? ???????. ????
????????? f(n) ????? ?????? ????????? O(g(n)) ??
?????? ?????? n0,c ?? ???? n0 ? n ?????? f(n)
? c?g(n)
??? ?? ???? ?- g(n) ????? ??? ????? ?????????
???????? f(n) ????? ??? ?"? f(n) O(g(n)) ?????
?????? ????? f(n) ? O(g(n)).
f(n)
????? ?????? ?? ???? ???????? f(n) ??? ???????
???? ???? ??????, ???? ??? ????? ?? ????????,
???? g(n) ????? ???? ??????.
17
??????? ?????????????
???? ???? k ???? ??????
????? ???? ?????? c, n0, ?? ?? ???? n0 ? n
?????? f(n) ? c?nk. ??? amax max0,a0,..,ak .
????? ???? n0 2 ???c 2amax .
18
??????? ??????
19
???????
?????? ?????? ?????? ??????. ??????!
20
???????? ???
????? ?????? ???? ????? ????. ????? ???????
T(n) lt c?n 1 ??????T(n) O(n) .
21
???????? ??? (????)
  • ????? ?????? ????? ????? ?? x ????? ????? ?? n
    ??????.
  • ??? ??? ?????? ?? x ????? ?????? ????? ???????.
  • ?? ????? ?????? ???? ?- x ?????? ????.
  • ?? ????? ?????? ???? ?- x ??????? ?? ??? ?????
    ????? ?? ??????? ??????.
  • ?? ????? ?????? ??? ?- x ??????? ?? ??? ?????
    ????? ?? ??????? ???????.

????? ????? ?? ??? ????? ?? n. ????? ?? ?????
????? ???????? ????? ???? ????? ???? ?????? (???
4)Cormen, Leiserson, Rivest, Introduction to
Algorithms .
22
???????? ??? (????)
????? ?????? S 0 for ( i 1 i lt n i
) for ( j 0 jlt n j i ) S
?????? ??? ??? ?????? ???????. T(n) ? n (n-1) .
?????? ????? ???? i 1,
??????? n ??????. ,i 2
?n/2? ,i 3
?n/3? ??? i n
, n/n 1
???? ??? ???? ??? ????? ????? ?? ?? ????????
????? ??????T(n) O( n?log n)
23
??? ????? ?????????
????? ???? f(n), g(n) ???????? ???????. ????
????????? f(n) ????? ?????? ????????? ?(g(n))
(?????) ?? ?????? ?????? n0,c ?? ???? n0 ? n
?????? f(n) ? c?g(n)
24
??? ???? ?????????
????? ???? f(n), g(n) ???????? ???????. ????
??????? f(n)?(g(n)) (???) ?? f(n)O(g(n)) ???
f(n) ?(g(n)).
c2 g(n)
f(n)
c1 g(n)
f(n) ?(g(n))
n0
????? (??????????) ???? ??????? f(n)?(g(n)) ??
?????? ?????? n0,c1,c2 ?? ???? n0 ? n ??????
c1?g(n) ? f(n) ? c2?g(n).
25
?????? o ???
????? ???? f(n), g(n) ???????? ???????. ????
????????? f(n) ????? ?????? ????????? o(g(n)) ??
??? ???? c ???? ???? n0 ?? ???? n0 ? n ??????
f(n) ? c?g(n)
????? (??????????) ???? ??????? f(n)o(g(n))
?? .
??????? log n o(n), n-100 ? o(n)
26
?????? ?????? ??????????
??? ?????? ???????? ??????????? ???? ???????
????? ??????? ?????? ????? ????? ???? ????. ???
????? ???????? ??? ????? ?????. ??? ?????? ??
?????? ??????? ???? ?????? ?????? ???? ???? T(n)
n2 ?? ??? ?????? ???? ???? ???? ?? 1080
(?????? ???? ?"? ???? ????? ?? ?????? ??? ??????)
???? ????????? ?????? ??? ??????? ????? ??? n
???? ???? ????? ??????? ?-1040 . ????? ????
????? ???????? n0,c ???????? ???????
??????????? O, ?, ? ???? "??????".
Write a Comment
User Comments (0)
About PowerShow.com