Chapter 1 - Introduction
Chapter 1 - Introduction
• Pseudocode
• Abstract data type
• Algorithm efficiency
Algorithm Header
Algorithm Body
Interface
User knows what a data
Implementation of
type can do.
data and operations
How it is done is hidden.
data structure
internal
function
data
function A
data
function B
• Rectangle: r
– length: x (hidden)
– width: y (hidden)
– get_length()
– get_width()
• Implementation:
– Array, or
– Linked list
The number of times the body The number of times the body
of the loop is replicated is of the loop is replicated is
1000 500
f(n) = (n/2).T
f(n) = (log2n).T
log2n
End addMatrix
Cao Hoang Tru 38
CSE Faculty - HCMUT 10 September 2008
Time Costing Operations
• The most time consuming: data movement
to/from memory/storage.
• Operations under consideration:
– Comparisons
– Arithmetic operations
– Assignments
a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[12]
4 7 8 10 14 21 22 36 62 77 81 91
a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[12]
4 7 8 10 14 21 22 36 62 77 81 91
a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[12]
4 8 7 10 21 14 22 36 62 91 77 81
a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[12]
4 8 7 10 21 14 22 36 62 91 77 81
⇒ NP problem
A
1 10
B
D E
5 5
15 5
C
P
NP
NP-complete