18
©Brooks/Cole, 2001 Chapter 1 Introduction

CHAP01 Data Structures: A Pseudo Code Approach

Embed Size (px)

DESCRIPTION

Powerpoint presentation for Chapter 1 of Data Structures: A Pseudocode Approach by Gilberg and Forouzan

Citation preview

PowerPoint PresentationIn this text, algorithms consist of:
Header (purpose, conditions, and return)
Statement numbers
Meaningful variables
Brooks/Cole, 2001
Data Structure
Combination of either a data type or another data structure, into a set with defined relationships
Examples:
Array
Position association among elements
We know what a data type can do
Details of how this is done, is hidden
Hiding details of how operations are performed, allows a programmer to focus on what needs to be done
Brooks/Cole, 2001
Figure 1-1
Brooks/Cole, 2001
Abstract Data Type Model
User is not able to access the data structure and operational functions inside the model
All functions within the model are within scope of each other
Users access the ADT through the external interface (operation name and parameters)
Brooks/Cole, 2001
Figure 1-2
Brooks/Cole, 2001
Implemented using a C++ class
ADT Class Templates are used to provide flexibility in handling different data types
Brooks/Cole, 2001
Figure 1-3
Brooks/Cole, 2001
Algorithm Efficiency
Efficiency is a function of the number of elements to be processed (n):
f(n) = efficiency
Standard measures:
Exponential f(n) = cn (c is a constant)
Factorial f(n) = n!
Matrix Addition Example
Add corresponding elements (first element of first matrix, to first element of second matrix)
Put result of the addition into their corresponding locations in a third matrix.
Brooks/Cole, 2001
Figure 1-5
Brooks/Cole, 2001
Algorithm 1-3
algorithm addMatrix (val matrix1 <matrix>, val matrix2 <matrix>, val size <integer>, ref matrix3 <matrix>)
r = 0
c = c + 1
Matrix Multiplication Example
Multiply each element in a row of the first matrix, by its corresponding element in a column of the second matrix
Value of the matrix is the sum of the products:
matrix3 [r,c] =

where s = size of matrix
Brooks/Cole, 2001
Figure 1-6
Brooks/Cole, 2001
Algorithm 1-4
algorithm multiplyMatrix(val matrix1 <matrix>, val matrix2 <matrix>, val size <integer>, ref matrix3 <matrix>)
r = 0
matrix3[r, c] = matrix3[r,c] + matrix1[r,m] x matrix2[m,c]
m = m + 1
Big-O efficiency of O(size3), or O(n3)