1. Trang chủ
  2. » Giáo án - Bài giảng

slide cấu trúc dữ liệu và giải thuật bản đầy đủ (hay) ở file đính kèm

46 456 1

Đ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 46
Dung lượng 365,72 KB
File đính kèm slide.zip (2 MB)

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Cấu trúc dữ liệu và giải thuật (Data Structure and Algorithms) Với các sinh viên chuyên nghành tin học thì cụm từ Cấu trúc dữ liệu (Data Structure) không còn là xa lạ. ... Cấu trúc dữ liệu là cách lưu trữ, tổ chức dữ liệu có thứ tự, có hệ thống để dữ liệu có thể được sử dụng một cách hiệu quả Data structures and Algorithms Introduction Pham Quang Dung Hanoi

Trang 1

Data structures and Algorithms

Basic definitions and notations

Pham Quang Dung

Hanoi, 2012

Trang 3

sequence : -2, 11, -4, 13, -5, 2

The largest weight subsequence is 11, -4, 13 having weight 20

Trang 6

Recursive algorithm

The largest subsequence might

be in s 1 or

be in s 2 or

start at some position of s 1 and end at some position of s 2

C++ code :

Trang 8

Aggregation : establish the solution to the initial problem by

aggregating solutions to subproblems stored in the memory

Trang 9

Solution to the original problem is max{s 1 , , s n }

Trang 10

Comparison between algorithms

Trang 12

Algorithms and complexity

Trang 14

Worst-case time complexity :

The longest execution time the algorithm takes given any input of size n

Used to compare the efficiency of algorithms

Average-case time complexity : execution time the algorithm takes on

a random input

Best-case time complexity : The smallest execution time the

algorithm takes given any input of size n

Trang 19

Big-Oh notation

When we say ”the time complexity is O(f (n))” : the time complexity

in the worst case is O(f (n))

When we say ”the time complexity is Ω(f (n))” : the time complexity

in the best case is Ω(f (n))

Trang 37

Analysis of algorithms

Experiments studies

Write a program implementing the algorithm

Execute the program on a machine with different input sizes

Measure the actual execution times

Plot the results

Trang 38

Analysis of algorithms

Shortcomings of experiments studies

Need to implement the algorithm, sometime difficult

Results may not indicate the running time of other input not

experimented

To compare two algorithms, it is required to use the same hardwareand software environments

Trang 39

Analysis of algorithms

Asymptotic algorithm analysis

Use high-level description of the algorithm (pseudo code)

Determine the running time of an algorithm as a function of the inputsize

Express this function with Big-Oh notation

Trang 40

Analysis of algorithms

Sequential structure : P and Q are two segments of the algorithm(the sequence P; Q)

Time(P; Q) = Time(P) + Time(Q) or

Time(P; Q) = Θ(max (Time(P), Time(Q)))

for loop : for i = 1 to m do P(i )

t(i ) is the time complexity of P(i )

time complexity of the for loop is P m

i =1 t(i )

Trang 41

Analysis of algorithms

while (repeat) loop

Specify a function of variables of the loop such that this functionreduces during the loop

To evaluate the running time, we analyze how the function reducesduring the loop

Trang 43

Analysis of algorithms

Example : binary search

Denote

d = j − i + 1 (number of elements of the array to be investigated)

i∗, j∗, d∗ respectively the values of i , j , d after a loop

Trang 46

Analysis of algorithms

Primitive operations (be careful ! !)

Consider the case T [i ] = i2, ∀i = 1, , n

U[k] =



1, if k = q2

0, otherwise

s = n2, the running time is Θ(n2) not Θ(n)

Reason :The primitive operation is not well-chosen Many null-loopwhere U[k] = 0

If the primitive operation is the checking instruction U[k] > 0, then

Ngày đăng: 11/06/2017, 21:30

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w