1. Trang chủ
  2. » Tất cả

Đề thi cấu trúc dữ liệu và giải thuật dsa ch2 complexity algorithm

33 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 33
Dung lượng 294,63 KB

Nội dung

Complexity of Algorithms Complexity of Algorithms Luong The Nhan, Tran Giang Son Algorithm Efficiency Big O notation Problems and common complexities P and NP Problems 2 1 Chapter 2 Complexity of Algo[.]

Complexity of Algorithms Luong The Nhan, Tran Giang Son Chapter Complexity of Algorithms Data Structures and Algorithms Algorithm Efficiency Big-O notation Problems and common complexities Luong The Nhan, Tran Giang Son Faculty of Computer Science and Engineering University of Technology, VNU-HCM P and NP Problems 2.1 Outcomes Complexity of Algorithms Luong The Nhan, Tran Giang Son • L.O.1.1 - Define concept “computational complexity” and its sepcial cases, best, average, and worst • L.O.1.2 - Analyze algorithms and use Big-O notation to characterize the computational complexity of algorithms composed by using the following control structures: sequence, branching, and iteration (not recursion) • L.O.1.3 - List, give examples, and compare complexity classes, for examples, constant, linear, etc • L.O.1.4 - Be aware of the trade-off between space and Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems time in solutions • L.O.1.5 - Describe strategies in algorithm design and problem solving 2.2 Contents Complexity of Algorithms Luong The Nhan, Tran Giang Son Algorithm Efficiency Big-O notation Algorithm Efficiency Big-O notation Problems and common complexities Problems and common complexities P and NP Problems P and NP Problems 2.3 Complexity of Algorithms Luong The Nhan, Tran Giang Son Algorithm Efficiency Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems 2.4 Algorithm Efficiency Complexity of Algorithms Luong The Nhan, Tran Giang Son • A problem often has many algorithms • Comparing two different algorithms ⇒ Computational complexity: measure of the difficulty degree (time and/or space) of an algorithm • • Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems How fast an algorithm is? How much memory does it cost? 2.5 Algorithm Efficiency Complexity of Algorithms Luong The Nhan, Tran Giang Son General format efficiency = f(n) n is the size of a problem (the key number that determines the size of input data) Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems 2.6 Complexity of Algorithms Linear Loops Luong The Nhan, Tran Giang Son for ( i = 0; i < 1000; i ++) application code The number of times the bodyof the loop is replicated is 1000 f(n) = n Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems for ( i = 0; i < 1000; i += 2) application code The number of times the bodyof the loop is replicated is 500 f(n) = n/2 2.7 Complexity of Algorithms Linear Loops time f (n) = n Luong The Nhan, Tran Giang Son Algorithm Efficiency Big-O notation f (n) = n/2 Problems and common complexities P and NP Problems n 2.8 Complexity of Algorithms Logarithmic Loops Luong The Nhan, Tran Giang Son Multiply loops i = while ( i = 1) application code i = i / P and NP Problems The number of times the body of the loop is replicated is f(n) = log2 n 2.9 Complexity of Algorithms Logarithmic Loops time Luong The Nhan, Tran Giang Son Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems f (n) = log2 n n 2.10 Complexity of Algorithms Standard Measures of Efficiency Luong The Nhan, Tran Giang Son Efficiency logarithmic linear linear log quadratic polynomial exponential factorial Big-O O(log2 n) O(n) O(n log2 n) O(n2 ) O(nk ) O(2n ) O(n!) Iterations 14 10 000 140 000 100002 10000k 2( 10000) 10000! Est Time microseconds 0.1 seconds seconds 15-20 hours intractable intractable Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems Assume instruction speed of microsecond and 10 instructions in loop n = 10000 2.19 Standard Measures of Efficiency n2 n log n time Complexity of Algorithms Luong The Nhan, Tran Giang Son n Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems log2 n n 2.20 ... 2.3 Complexity of Algorithms Luong The Nhan, Tran Giang Son Algorithm Efficiency Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems 2.4 Algorithm Efficiency Complexity. .. of an algorithm • • Algorithm Efficiency Big-O notation Problems and common complexities P and NP Problems How fast an algorithm is? How much memory does it cost? 2.5 Algorithm Efficiency Complexity. .. Asymptotic Complexity Complexity of Algorithms Luong The Nhan, Tran Giang Son • • • Algorithm efficiency is considered with only big problem sizes We are not concerned with an exact measurement of an algorithm? ??s

Ngày đăng: 25/03/2023, 08:37

w