1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu về Pseudocode tiếng anh

49 992 5
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đ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

Tiêu đề Pseudocode
Tác giả Cao Hoang Tru
Trường học Ho Chi Minh City University of Technology
Chuyên ngành Computer Science and Engineering
Thể loại Bài báo
Năm xuất bản 2008
Thành phố Ho Chi Minh City
Định dạng
Số trang 49
Dung lượng 153,23 KB

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

Nội dung

Tài liệu về Pseudocode tiếng anh

Trang 1

Chapter 1: Introduction

¢ Pseudocode

¢ Abstract data type

¢ Algorithm efficiency

Trang 2

Pseudocode

¢ What is an algorithm’

Trang 3

Pseudocode

¢ What is an algorithm’

— The logical steps to solve a problem

Trang 4

Pseudocode

¢ What is a program?

— Program = Data structures + Algorithms (Niklaus Wirth)

Trang 5

Pseudocode

¢ The most common tool to define algorithms

¢ English-like representation of the code

required for an algorithm

Trang 6

Pseudocode

¢ Pseudocode = English + Code

relaxed syntax being instructions using

(sequential, conditional, iterative)

Trang 12

Abstract Data Type

¢ What is a data type?

— Class of data objects that have the same properties

Trang 13

Abstract Data Type

¢ Development of programming concepts:

Trang 14

Abstract Data Type

¢ ADT = Data structures + Operations

Trang 15

Abstract Data Type

Interface

User knows what a data

Implementation of type can do

data and operations

How it is done Is hidden

Trang 16

Abstract Data Type

data

data

Trang 17

Example: Variable Access

Trang 19

Algorithm Efficiency

¢ How fast an algorithm is?

¢ How much memory does it cost?

¢ Computational complexity: measure of the difficulty degree (time or space) of an

algorithm

Trang 20

Algorithm Efficiency

¢ General format:

f(n) nis the size of a problem (the key number that determines

the size of input data)

Trang 21

The number of times the body The number of times the body

of the loop is replicated is of the loop is replicated is

Trang 22

Linear Loops

time | f(n) = n.T

Trang 25

Logarithmic Loops

time

f(n) = (logon) T

Trang 26

Nested Loops

lterations = Outer loop iterations x Inner loop iterations

Trang 27

Linear Logarithmic Loops

Trang 28

Linear Logarithmic Loops

time tín) = (nlogzn) [

Trang 30

Dependent Quadratic Loops

Trang 31

Quadratic Loops

time f(n) = n2.T

Trang 32

Asymptotic Complexity

¢ Algorithm efficiency is considered with only big problem sizes

¢ We are not concerned with an exact

measurement of an algorithm's efficiency

¢ Terms that do not substantially change the function's magnitude are eliminated

Trang 33

Big-O Notation

¢ f(n) =c.n => f(n) = O(n)

¢ f(n) =n(n + 1)/2 = n7/2 + n/2 = f(n) = O(n’)

Trang 34

Big-O Notation

¢ Set the coefficient of the term to one

¢ Keep the largest term and discard the

others

logzn n nlogn ne nme nk 2 nl

Trang 35

Standard Measures of Efficiency

Trang 36

Standard Measures of Efficiency

O(n) | n2 nlog,n n

Trang 37

Big-O Analysis Examples

Algorithm addMatrix (val matrix1 <matrix>, val matrix2 <matrix>,

val size <integer>, ref matrix3 <matrix>)

Add matrix1 to matrix2 and place results in matrix3

Pre matrix1 and matrix2 have data

size is number of columns and rows in matrix

Post matrices added - result in matrix3

Trang 38

Big-O Analysis Examples

Algorithm addMatrix (val matrix1 <matrix>, val matrix2 <matrix>,

val size <integer>, ref matrix3 <matrix>)

Add matrix1 to matrix2 and place results in matrix3

Pre matrix1 and matrix2 have data

size is number of columns and rows in matrix

Post matrices added - result in matrix3

Trang 39

Time Costing Operations

¢ The most time consuming: data movement to/from memory/storage

¢ Operations under consideration:

— Comparisons

— Arithmetic operations

— Assignments

Trang 40

Recurrence Equation

¢ An equation or inequality that describes a

function in terms of its value on smaller

Input

Trang 41

Recurrence Equation

¢ Example: binary search

41/7 | 8 | 10] 14} 21 | 22 | 36 | 62 | 77 | 81 | 91

Trang 42

Recurrence Equation

¢ Example: binary search

41/7 | 8 | 10] 14} 21 | 22 | 36 | 62 | 77 | 81 | 91

f(n) =1+f(n/2) = f(n) = O(logsn)

Trang 43

Best, Average, Worst Cases

¢ Best case: when the number of steps is

Trang 44

Best, Average, Worst Cases

¢ Example: sequential search

4/8] 7 | 10 | 21} 14] 22 | 36 | 62 | 91} 77 | 81

Best case: f(n) = O(1)

Worst case: f(n) = O(n)

Trang 45

Best, Average, Worst Cases

Example: sequential search

4/8] 7 | 10 | 21} 14] 22 | 36 | 62 | 91} 77 | 81

Average case: f(n) = Dip;

p;: probability for the target being at ali]

p= 1/n > f(n) = (d/j)/n = O(n)

Trang 46

P and NP Problems

¢ P: Polynomial (can be solved in polynomial time on a deterministic machine)

¢ NP: Nondeterministic Polynomial (can be

solved in polynomial time on a non-

deterministic machine)

Trang 47

P and NP Problems

Travelling Salesman Problem:

A salesman has a list of cities, each of which he must visit

exactly once There are direct roads between each pair of

cities on the list

Find the route the salesman should follow for the shortest

possible round trip that both starts and finishes at any one of

the cities

Trang 48

P and NP Problems Travelling Salesman Problem:

Deterministic machine: f(n) = n(n-1)(n-2) 1 = O(n!)

— NP problem

Trang 49

P and NP Problems

¢ NP-complete: NP and every other problem

in NP is polynomially reducible to it

¢ Open question: P = NP?

NP-complete

NP

Ngày đăng: 20/08/2012, 12:06

TỪ KHÓA LIÊN QUAN