Bài giảng cấu trúc dữ liệu và giải thuật giới thiệu TS đào nam anh (tt)

57 165 0
Bài giảng cấu trúc dữ liệu và giải thuật giới thiệu   TS  đào nam anh (tt)

Đ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

DATA STRUCTURE AND ALGORITHM FLOWCHARTS CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT Dr Dao Nam Anh Data Structure and Algorithm Resource - Reference Slides of Achmad Yani (Electrical Engineering Department, Gadjah Mada University), and Rasime Uyguroğlu (Electrical & Electronic Eng.Dept, Eastern Mediterranean University) edit by Dao Nam Anh Major Reference: • Robert Sedgewick, and Kevin Wayne, “Algorithms” Princeton University, 2011, Addison Wesley • Cấu trúc liệu giải thuật, Đinh Mạnh Tường Data Structure and Algorithm Symbol Bắt đầu kết thúc Dữ liệu đầu vào đầu Một việc Một việc xác định trước Sự lựa chọn sai Data Structure and Algorithm The three basic control structures Các thành phần Data Structure and Algorithm Sequence – Nối tiếp Statemement a Statemement b Statemement c Data Structure and Algorithm Selection – Lựa chọn T Statemement a Condition p? F Statemement b Data Structure and Algorithm Selection – Lựa chọn Condition p? F T Statemement a Data Structure and Algorithm Repetition – Lặp lại Condition p? F T Statemement block Data Structure and Algorithm Ví dụ Cộng số Một chương trình A cần đọc số, cộng chúng với in kết Data Structure and Algorithm • Defining diagram – Thiết kế sơ đồ Input Processing Đầu vào Thực Số thứ Đọc số Số thứ Cộng vào Số thứ In tổng Output Kết Tổng Data Structure and Algorithm 10 Validate_input_fields Start Hours_ Worked > 60 Valid_input_ fields = T Pay_rate > $ 25 Print Error message Print Error message Valid_ Input_ Fields = T Valid_ Input_ Fields = F Stop Data Structure and Algorithm 43 Bài tập Thiết kế chương trình nhập cạnh hình chữ nhật Tính hiển thị diện tích hình chữ nhật Data Structure and Algorithm 44 Bài tập • Viết chương trình giải phương trình bậc hai ax + bx + c = • Gợi ý: tính Delta d = sqrt ( b − 4ac ), hai nghiệm là: x1 = (–b + d)/2a, x2 = (–b – d)/2a Data Structure and Algorithm 45 Bài tập Algorithm • • • START Step 1: Input W,L Step 2: A←L x W Step 3: Print A Input W, L A ←LxW Print A STOP Data Structure and Algorithm 46 Bài tập • Viết chương trình giải phương trình bậc hai ax + bx + c = • Gợi ý: tính Delta d = sqrt ( b − 4ac ), hai nghiệm là: x1 = (–b + d)/2a, x2 = (–b – d)/2a Data Structure and Algorithm 47 Bài tập Pseudocode: • Input the coefficients (a, b, c) of the quadratic equation • Calculate d • Calculate x1 • Calculate x2 • Print x1 and x2 Data Structure and Algorithm 48 Bài tập • Chương trình nhập số, tìm số lớn hiển thị số • Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX ← VALUE1 else MAX ← VALUE2 endif Step 3: Print “The largest value is”, MAX Data Structure and Algorithm 49 Bài tập START Input a, b, c • Algorithm: • • • • • Step 1: Input a, b, c Step 2: d ← sqrt ( b × b − × a × c) Step 3: x1 ← (–b + d) / (2 x a) Step 4: x2 ← (–b – d) / (2 x a) Step 5: Print x1, x2 d ← sqrt(b x b – x a x c) x1 ←(–b + d) / (2 x a) X2 ← (–b – d) / (2 x a) Print x1 ,x2 STOP Data Structure and Algorithm 50 Bài tập • Chương trình nhập số, tìm số lớn hiển thị số • Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX ← VALUE1 else MAX ← VALUE2 endif Step 3: Print “The largest value is”, MAX Data Structure and Algorithm 51 Bài tập • Chương trình nhập số, tìm số lớn hiển thị số Data Structure and Algorithm 52 Bài tập START Input VALUE1,VALUE2 Y is VALUE1>VALUE2 ← N ← MAX VALUE1 MAX VALUE2 Print “The largest value is”, MAX STOP Data Structure and Algorithm 53 Bài tập • Chương trình nhập số, tìm số lớn hiển thị số Data Structure and Algorithm 54 Bài tập Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX ← N1 [N1>N2, N1>N3] else MAX ← N3 [N3>N1>N2] endif else if (N2>N3) then MAX ← N2 [N2>N1, N2>N3] else MAX ← N3 [N3>N2>N1] endif endif Step 3: Print “The largest number is”, MAX Data Structure and Algorithm 55 START Bài tập Input VALUE1,VALUE2, VALUE3 Y Y is VALUE1>VALUE3 ← MAX VALUE1 N is VALUE1>VALUE2 Y N ← MAX VALUE3 is VALUE2>VALUE3 ← MAX VALUE2 N ← MAX VALUE3 Print “The largest value is”, MAX STOP Data Structure and Algorithm 56 Discussion – Câu hỏi • https://sites.google.com/site/daona manhedu/data-structure-algorithm Data Structure and Algorithm 57 ... Mediterranean University) edit by Dao Nam Anh Major Reference: • Robert Sedgewick, and Kevin Wayne, “Algorithms” Princeton University, 2011, Addison Wesley • Cấu trúc liệu giải thuật, Đinh Mạnh Tường Data... Thiết kế sơ đồ Input Processing Đầu vào Thực Số thứ Đọc số Số thứ Cộng vào Số thứ In tổng Output Kết Tổng Data Structure and Algorithm 10 Solution Algorithm – Giải thuật Start Read Number1 Number2... House_lenght House_width Processing Prompt for block measurements Get block measurements Prompt for house measurements Get house measurements Calculate mowing area Calculate mowing time Output Mowing_time

Ngày đăng: 06/11/2017, 12:35

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan