introduction cs 3358 data structures. what is computer science? computer science is the study of...

32
Introduction CS 3358 Data Structures

Upload: brian-patterson

Post on 03-Jan-2016

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Introduction

CS 3358 Data Structures

Page 2: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

What is Computer Science?

Computer Science is the study of algorithms, including their Formal and mathematical properties

The logic used to prove that we have the correct solutions

Hardware realizations Creating microchips, processors, and other hardware

Linguistic realizations Creating the languages to express the algorithms precisely

Applications The actual real-life problems that are solved

Page 3: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Software Engineering Goal

Production of software that is effective and reliable, understandable, cost effective, adaptable, and reusable

Because of the long lifetime many people will be involved

Creation Debugging Maintenance Enhancement

Two-thirds of the cost is typically beyond creation

Page 4: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Design Principles

Abstraction

Encapsulation

Modularity

Hierarchy

Page 5: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Principles

Abstraction

Encapsulation

Modularity

Hierarchy

Determine the relevant properties and

features while ignoring nonessential details

Page 6: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Principles

Abstraction

Encapsulation

Modularity

Hierarchy

Separate components into external and internal aspects

Page 7: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Principles

Abstraction

Encapsulation

Modularity

Hierarchy

Construct a system from

components and packages

Page 8: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Principles

Abstraction

Encapsulation

Modularity

Hierarchy

Ranking or ordering of objects

Page 9: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Abstract Data Types (ADT)

A specification of a set of data and the set of operations that can be performed on the data.

Independent of concrete implementation Uses defined interface Hides details from the user (information hiding) Not the same as a data structure

Page 10: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

ADT Example -- Stack  bool empty()

Tests if this stack is empty.  

E peek() Looks at the object at the top of this stack without

removing it from the stack.

E pop() Removes the object at the top of this stack and

returns that object as the value of this function.  

push(E item) Pushes an item onto the top of this stack.

Page 11: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Why?

Allows implementation to be changed without violating ADT definitions

Gives a standard list of structures to use and study

Building blocks and tools Foundation for OOP Abstraction, Encapsulation, Modularity,

Hierarchy

Page 12: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Object-Oriented Design

PurposePromote thinking about software in a way that

models the way we think and interact with the physical word

Including specialization

ObjectProperties or attributesBehaviors

Page 13: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Programming

Class Term for a type of

software object Object

An instance of a class with

specific properties andattributes

Page 14: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Programming

Problem solving through the use of a computer system

MaximYou cannot make a computer do something if

you do not know how to do it yourself

Page 15: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving

AcceptThe process is iterative

In solving the problem increased understanding might require restarting

Page 16: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving

SolutionsOften require both concrete and abstract

thinking Teamwork

Page 17: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving Process

What is it?AnalysisDesign ImplementationTesting

Determine the inputs, outputs, and other components of the problem

Description should be sufficiently specific to allow you to solve the problem

Page 18: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving Process

What is it?AnalysisDesign ImplementationTesting

Describe the components and associated processes for solving the problem

Straightforward and flexible

Method – process

Object – component and associated methods

Page 19: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving Process

What is it?AnalysisDesign ImplementationTesting

Develop solutions for the components and use those components to produce an overall solution

Straightforward and flexible

Page 20: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving Process

What is it?AnalysisDesign ImplementationTesting

Test the components individually and collectively

Page 21: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Problem Solving Process

Testing

Design

Analysis

Implementation

Determineproblem features

Describe objectsand methods

Produce theclasses and code

Examine forcorrectness

Rethink asappropriate

Page 22: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Tips

Find out as much as you can Reuse what has been done before Expect future reuse Break complex problems into subproblems

Find out what is known about the problem

Talk to the presenter

Determine what attempts have succeeded and what attempts have failed

Page 23: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Preconditions and Postconditions

Frequently a programmer must communicate precisely what a function accomplishes, without any indication of how the function does its work.

Can you think of a situationCan you think of a situationwhere this would occur ?where this would occur ?

Page 24: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Example

You are the head of a programming team and you want one of your programmers to write a function for part of a project.

HERE ARETHE REQUIREMENTS

FOR A FUNCTION THAT IWANT YOU TO

WRITE.

I DON'T CAREWHAT METHOD THE

FUNCTION USES,AS LONG AS THESE

REQUIREMENTSARE MET.

Page 25: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

What are Preconditions and Postconditions?

One way to specify such requirements is with a pair of statements about the function.

The precondition statement indicates what must be true before the function is called.

The postcondition statement indicates what will be true when the function finishes its work.

Page 26: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Example

void write_sqrt( double x)

// Precondition: x >= 0.// Postcondition: The square root of x has// been written to the standard output.

...

Page 27: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Example

write_sqrt( -10 );write_sqrt( 0 );write_sqrt( 5.6 );

Which of these function callsWhich of these function callsmeet the precondition ?meet the precondition ?

Page 28: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Always make sure the precondition is valid . . .

The programmer who calls the function is responsible for ensuring that the precondition is valid when the function is called.

Page 29: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

. . . so the postcondition becomes true at the function’s end.

The programmer who writes the function counts on the precondition being valid, and ensures that the postcondition becomes true at the function’s end.

Page 30: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

On the other hand, careful programmers also follow these rules:

When you write a function, you should make every effort to detect when a precondition has been violated.

If you detect that a precondition has been violated, then print an error message and halt the program...

...rather than causing

a disaster.

Page 31: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Example

void write_sqrt( double x)// Precondition: x >= 0.// Postcondition: The square root of x has// been written to the standard output.{ assert(x >= 0);

...

Page 32: Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical

Advantages of Using Preconditions and Postconditions

Succinctly describes the behavior of a function...

... without cluttering up your thinking with details of how the function works.

At a later point, you may reimplement the function in a new way ...

... but programs (which only depend on the precondition/postcondition) will still work with no changes.