41
Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Embed Size (px)

Citation preview

Page 1: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structure Introduction

Dr. Bernard Chen Ph.D.University of Central Arkansas

Fall 2010

Page 2: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Outline

Software Development Abstract Data Type (ADT)

Page 3: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Hardware: actual physical components

(such as CPU, memory, hard drive…)

Software: refers to programs used to control the operation of the hardware. Is a complex process that is both art and

science Requires a good deal of imagination,

creativity and ingenuity

Page 4: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Hardware Progress Trend

1

10

100

1000

10000

1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006

Pe

rfo

rma

nce

(vs

. V

AX

-11

/78

0)

25%/year

52%/year

??%/year

Page 5: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance

Page 6: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Model

One of the earliest strategies for development software is known as the Waterfall Model

Page 7: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Waterfall Model

Page 8: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Realistic Waterfall Model

Page 9: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification

Design Coding Testing, Execution, and Debugging Maintenance

Page 10: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Problem Analysis and Specification

Problem Analysis and Specification: The problem is analyzed and a specification for the problem is formulated

For example: if we obtain a job request looks like:

Page 11: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Task Example

Because of new government regulations, we must keep more accurate record of all students currently receiving financial aid and submit regular report to FFAO (Federal Financial Aid Office). Could we get the computer to do this for us???

Page 12: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Task Analysis

Purpose Pre-condition (input): describe

the state of processing before the program is executed

Post-condition (output): describe the state of processing after the program is executed

Page 13: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance

Page 14: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Design

Design: A plan for solving the problem is formulated

Various design methods have been developed, two of major designs we describe here: top-down design and object-oriented design

Page 15: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Top-down design The original problem is partitioned

into simpler sub-problems

For example, the problem we just had can be obviously divided into:

1. Get the student records2. Process the records3. Prepare the reports

Page 16: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

One level partition

Page 17: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Two level partition

Page 18: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Three level partition

Page 19: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

OOD: Object-Oriented Design Identify the objects

in the problem's specification and their types.

Identify the operations or tasks to manipulate the objects

Page 20: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Program=Algorithm + Data Structure

Algorithm: “a step by step procedure for solving a problem or accomplishing some end”

In computer science, algorithm must be:

1. Definite, unambiguous2. Simple3. Finite

Page 21: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance

Page 22: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Coding There’s not much we can talk in

coding, you all know what it is. After you select the language, three major principles you need to follow:

1. Programs and Subprograms should be well structured

2. All source code should be documented3. It should be formatted in a style that

enhances its readability

Page 23: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification Design Coding Testing, Execution, and

Debugging Maintenance

Page 24: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Testing, Execution, and Debugging

Errors happen all the time!!!

There are three different points at which errors can be introduced:

1. Syntax errors2. Run-time errors3. Logic errors

Page 25: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

The "V" Life Cycle Model

Page 26: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Two major types of testing Black box testing:Outputs produced for various inputs

Checked for correctness Do not consider structure of program

component itself.

(so basically, it just test a lot of different inputs and match with the expected outputs )

Page 27: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Two major types of testing

White box testing:examine code’s internal structure(Test for every loop, if statement,

functions…)

Test data is carefully selected

Page 28: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Software Development Phases

Problem Analysis and Specification Design Coding Testing, Execution, and Debugging Maintenance

Page 29: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Maintenance After the software has

been used for several years, they will require modifications

Studies show that a higher percentage of computing budgets and programmer time are devoted to software maintenance

1970s 35-40%

1980s 40-60%

1990s 70-80%

2000s 80-90%

Page 30: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Program

Algorithms + Data Structure = Programs

Algorithms: Must be definite and unambiguous Simple enough to carry out by computer Need to be terminated after a finite

number of operations

Page 31: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Outline

Software Development Abstract Data Type (ADT)

Page 32: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

A first look an ADTs Solving a problem involves processing data, and

an important part of the solution is the careful organization of the data

In order to do that, we need to identify:1. The collection of data items 2. Basic operation that must be performed on them

Abstract Data Type (ADT): a collection of data items together with the operations on the data

Page 33: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Abstract Data Type (ADT)

The word “abstract” refers to the fact that the data and the basic operations defined on it are being studied independently of how they are implemented

We think about what can be done with the data, not how it is done

Page 34: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Implementation of ADT

An implementation of ADT consists of storage structures to store the data items and algorithms for basic operation

Page 35: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structures, Abstract Data Types, and Implementations

Consider example of an airplane flight with 10 seats to be assigned

Tasks List available seats Reserve a seat

How to store, access data?

Page 36: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structures, Abstract Data Types, and Implementations

Consider example of an airplane flight with 10 seats to be assigned

Tasks List available seats Reserve a seat

How to store, access data? 10 individual variables

Page 37: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Use 10 individual variables Algorithm to List

available seats

1. If seat1 == ‘ ’:display 1

2. If seat2 == ‘ ’: display 2

.

.

.10. If seat10 == ‘ ’:

display 10

Algorithm to Reserve a seat

1. Set DONE to false2. If seat1 ==‘ ’:

print “do you want seat #1??”Get answerif answer==‘Y’:

set seat1 to ‘X’set Done to True

3. If seat2 ==‘ ’:print “do you want seat #2??”Get answerif answer==‘Y’:

set seat2 to ‘X’set Done to True

.

.

.

Page 38: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structures, Abstract Data Types, and Implementations

Consider example of an airplane flight with 10 seats to be assigned

Tasks List available seats Reserve a seat

How to store, access data? 10 individual variables An array of variables

Page 39: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Use Array Algorithm to List available seats

For number ranging from 0 to max_seats-1, do:If seat[number] == ‘ ’:

Display number

Algorithm to Reserve a seat

Readin number of seat to be reservedIf seat[number] is equal to ‘ ’:

set seat[number] to ‘X’Else

Display a message that the seat having this number is occupied

Page 40: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

ADTs In this simple example, it does illustrate the

concept of an Abstract Data Type

ADT consists of1. The collection of data items 2. Basic operation that must be performed on

them

In the example, a collection of data is a list of seats

The basic operations are (1) Scan the list to determine which seats are occupied (2) change seat’s status

Page 41: Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010

Data Structure and Abstract Data Type The term of Data Structure and Abstract

Data Type are often used interchangeably

However, we use ADT when data is studied at a logical level

The term data structure refers to a construct in programming language that can be used to store data