งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

MAT 231: คณิตศาสตร์ไม่ต่อเนื่อง (3) Function Growth & Time-Complexity

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "MAT 231: คณิตศาสตร์ไม่ต่อเนื่อง (3) Function Growth & Time-Complexity"— ใบสำเนางานนำเสนอ:

1 MAT 231: คณิตศาสตร์ไม่ต่อเนื่อง (3) Function Growth & Time-Complexity
ดร.ธนา สุขวารี ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.

2 วัตถุประสงค์ เพื่อศึกษาวิธีการวิเคราะห์ประสิทธิภาพขั้นตอนวิธี เบื้องต้น โดยใช้สัญญลักษ์ Big-Oh แทนการประมาณค่าความซับซ้อนด้านเวลา(time complexity)ของขั้นตอนวิธี

3 Orders of Growth For functions over numbers, we often need to know a rough measure of how fast a function grows. If f(x) is faster growing than g(x), then f(x) always eventually becomes larger than g(x) in the limit (for large enough values of x). Useful in engineering for showing that one design scales better or worse than another.

4 การวัดประสิทธิภาพขั้นตอนวิธี
ประสิทธิภาพ -> การใช้ทรัพยากรในระบบ : เวลา (excecution time: e-time) หรือ หน่วยความจำ(memory) ที่ใช้สำหรับการทำงานตามขั้นตอนวิธีจนได้ผลลัพธ์ y1=x y2= x2 y4=log(x) y3=ex data e-time

5 ประเภทของฟังก์ชัน (types of functions)
Linear function: y = mx+b y1 = 2x +1 or y2= 0.5x+1 or y3=20x-4 Polynomial function: y= anxn+an-1xn a0x0 degree-2 : y1= 5x2 + 3x +4 degree-3 : y2 = 2x3-10x2 Exponential function: y = ax y= ex Logarithmic function : y= log(x)

6 Linear fuctions e-time y2=0.5x +1 y1=x x1 x2 x3 data

7 Polynomial fuctions time t3 y1 > y2 > y3 t2 t1 xi data y3=x4

8 ฟังก์ชัน & ค่าความซับซ้อน (Functions ordered & Complexity)
Time complexity: Exponential order> Polynomail order > Linear order > logarithmic order Time complexity (high) -> Algorithm performance(low) How to choose the algorithm’s order for me? expo < polynomail < linear < log avoid < > best

9 Linear order Vs. Polynomial order
y1=x y2= x2 y4=log(x) y3=ex data time t3 t2 t1 x x2 x3 y2 better than y1 where xi < x2 y1 better than y2 where xi > x2

10 Time complexity of MAX()
procedure max({ai} : integers) [1] v := a1 ; [2] for i := 2 to n [3] if ai > v then v := ai ; [4] return v ; 1 + (n+1) n-1 + 1 total execution-time time complexity = n+1 (linear ordered)

11 Time complexity of Linear search
procedure Linear_search (x: integer, {ai}: distinct integers) i := 1 ; while (i  n  x  ai) i := i + 1; if i  n then location := i else location := 0 ; return location; total execution-time 1 + n + n+3 1 + 1 time complexity = n+3 (linear ordered)

12 Time complexity of Binary_search()
procedure binary search (x:integer, {ai}: distinct integers) i := 1; j := n ; while i<j begin m := (i+j)/2 ; if x>am then i := m+1 else j := m; end if x = ai then location := i else location := 0 return location; 1 + 1 + 2log2n + 1 + 1 time complexity = 2log2n +4 (log ordered)

13 Time complexity of Binary_search()
#n = 2h-1 n/2 n/4 h n/8 2 h log2 n = h.log22 1 h=log2n n + n/2 + n/4 + n/

14 Linear search Vs. Binary search
time complexity Linear ordered (n+3) Linear search time complexity Log. ordered (2log2n +4) Binary search Searching performance Binary search > Linear search

15 Definition: Big-Oh, O(f(x))
ให้ f(x) เป็นฟังก์ชัน f: RR. นิยาม ฟังก์ชัน f(x) จะเขียนอยู่ในรูปO(f(x)) หรือ f(x) = O(f(x)) ก็ต่อเมื่อ { f: R  R | c,k: x>k: |f(x)|  c|g(x)| }

16 “Big-Oh” Proof Examples
Show that 30n+8 is O(n). Show c,k: n>k: 30n+8  cn. Let c=31, k=8. Assume n>8. Then cn = 31n = 30n + n > 30n+8, So n+8 < cn #

17 “Big-Oh” Proof Examples
Show that n2+1 is O(n2). Show c,k: n>k: n2+1  cn2. Let c=2, k=1. Assume n>1. Then cn2 = 2n2 = n2+n2 > n2+1, So n2+1< cn2 #

18 EX-1: Show that n2+n+3 is O(n2)
Proof: Show c, k: n>k: n2+n+3  cn2. assume that  n>= 1 , n2+n+3 <= 3n2+3n2+3n2 = 9n2 n2+n+3 <=9n2 ; let k=1 and c=9 then n2+n+3 = O(n2) #

19 EX-2: Show that 1+2+3+ ..+n is O(n2)
Proof: Show c, k: n>k: n  cn2. therefore n = n(n+1)/2 then n = n(n+1)/2 = n2/2 + n/2 assume that  n>= 1; n2/2 + n/2 <= n2/2+n2/2 n2 + n <= n2+n2 = 2n2 n(n + 1) <= 2n2 n(n+1)/2 <= n2 let, k=1 and c=1 then n(n+1)/2 = O(n2) or n = O(n2) #

20 EX-3: Show that 3n3+6n2-4n+2 is O(n3)
Proof: Show c, k: n>k: 3n3+6n2-4n+2  cn2. assume that  n>= 1 3n3+6n2-4n+2 <= 6n3+6n3+6n3+6n3 = 24n3 let k=1 and c=24 then n3+6n2-4n+2 = O(n3) #

21 More Big-O facts c>0, O(cf)=O(f+c)=O(fc)=O(f)
f1O(g1)  f2O(g2)  f1 f2 O(g1g2) f1+f2 O(g1+g2) = O(max(g1,g2)) = O(g1) if g2O(g1) (Very useful!)

22 Computer Time Examples
(125 kB) (1.25 bytes) Assume time = 1 ns (109 second) per op, problem size = n bits, and #ops is a function of n, as shown.

23 Exercises 2n3+4logn2 5en+7n2-1 10n6-3n3+5logn+n+1
Use the definition of big-oh to prove that n2 is O(n3) Use the definition of big-oh to prove that is O(n2). Arrange these functions form poor to best performance: 2n3+4logn2 5en+7n2-1 10n6-3n3+5logn+n+1 3n-8-4n3 2n-1

24 Exercises 4. Show the Big-Oh of the algorithm that takes a list of integers a1,a2,…,an (n ≥ 2) and finds the second-largest integer in the sequence which had written in the previous chapter. 5. Show the Big-Oh of the algorithm that takes a list of n integers (n ≥1) and finds the average of the largest and smallest integers in the list which had written in the previous chapter.

25 Quiz -III ให้วิเคราะห์ค่าความซับซ้อนของขั้นตอนวิธีใน Quiz-IIในเทอมสัญญลักษณ์ Big-oh (10 นาที)

26 ห้ามใช้เครื่องคิดเลข
Guideline Exam 1/2553 1(10) การคำนวณ 1,2 complement 2 ข้อย่อย 2(20) แปลงเลขฐาน 4 ข้อย่อย 3(20) เขียน pseudo code และแสดงผลลัพธ์การsort 4(20) เขียน pseudo code + ประมาณสัญลักษณ์ Big-Oh 5(10) ประมาณประสิทธิาภาพขั้นตอนวิธีในสัญลักษณ์ Big-Oh ห้ามใช้เครื่องคิดเลข


ดาวน์โหลด ppt MAT 231: คณิตศาสตร์ไม่ต่อเนื่อง (3) Function Growth & Time-Complexity

งานนำเสนอที่คล้ายกัน


Ads by Google