Professional Documents
Culture Documents
Outline: 1-1 Pseudocode 1-2 The Abstract Data Type 1-3 A Model For An Abstract Data Type 1-4 Algorithm Efficiency
Outline: 1-1 Pseudocode 1-2 The Abstract Data Type 1-3 A Model For An Abstract Data Type 1-4 Algorithm Efficiency
1-1 Pseudocode
Chapter 1.
1-2 The Abstract Data Type
Introduction 1-3 A Model for an Abstract Data Type
Instructor: Kuen-Liang Sue 1-4 Algorithm Efficiency
IM/NCU
1
Pseudocode Pseudocode
Purpose
A short statement about what the algorithm does
Precondition
lists any precursor requirements for the parameters
Sometimes there are no preconditions, we still list it as
shown below
2
Header in Pseudocode Header in Pseudocode
Pseudocode Pseudocode
Algorithm analysis
Style or efficiency considerations
2015/9/24 DFS by KLSue/NCU 11 2015/9/24 DFS by KLSue/NCU 12
3
Statement constructs State constructs
4
1-2 The Abstract Data Type The Abstract Data Type
Composite data
The opposite of atomic data
e.g. telephone number has three different part
Area code, three-digit exchange and the number within the
exchange
2015/9/24 DFS by KLSue/NCU 19 2015/9/24 DFS by KLSue/NCU 20
5
The Abstract Data Type The Abstract Data Type
Data Structure
An aggregation of atomic and composite data types into a Abstract Data Type
set with defined relationships Users are not concerned with how the task is done but
rather with what it can do
ADT consists of a set of definitions that allow
programmers to use the functions while hiding the
implementation
Abstraction
If we place our list in an ADT Consider a system analyst who needs to simulate
user should not be aware of the structure we use the waiting line of a bank
Four logical structures that might be used to hold a list This analysis requires the simulation of a queue
However, queues are not generally available in programming
languages
Even if a queue type were available, the analyst would still need
some basic queue operations
• Enqueuing and dequeuing
6
Example of an ADT The Abstract Data Type
Two potential solutions to this problem Formal definition of an ADT
Writing a program that simulates the needed queue A data declaration packaged together with the operations
• The solution is good only for one application at hand
that are meaningful for the data type
Writing a queue ADT that can be used to solve any queue
problem
If choosing the latter course
writing a program to simulate the banking application is still
needed
but he can concentrate on the application rather than queue
1-3 A Model for an Abstract Data Type A Model for an Abstract Data Type
ADT Model
e.g. Shown in Figure 1-2
Shaded area with irregular outline represent the model
Inside the area are two different aspects of the model
the data structure and the operational functions
Both are entirely contained in the model
Both are not within the user’s scope
7
A Model for an Abstract Data Type A Model for an Abstract Data Type
8
1-4 Algorithm Efficiency Algorithm Efficiency
Logarithmic loops
The controlling variable is multiplied or divided in each
loop
9
Algorithm Efficiency Algorithm Efficiency
Linear logarithmic
10
Algorithm Efficiency Algorithm Efficiency
11
Algorithm Efficiency Algorithm Efficiency
Multiply matrices
When two matrices are multiplied, we must multiply each
element in a row of the first matrix by its corresponding
element in a column of the second matrix
12
Algorithm Efficiency Multiply Two Matrices (contd.)
In this algorithm loops with three nested loops have a
big-O efficiency of O(size3) or O(n3)
13