CS 3358 Data Structures - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

CS 3358 Data Structures

Description:

Introduction CS 3358 Data Structures – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 26
Provided by: JimCo394
Category:

less

Transcript and Presenter's Notes

Title: CS 3358 Data Structures


1
Introduction
  • CS 3358 Data Structures

2
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

3
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

4
Design Principles
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy

5
Principles
  • Determine the relevant properties and features
    while ignoring nonessential details
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy

6
Principles
  • Separate components into external and internal
    aspects
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy

7
Principles
  • Construct a system from
  • components and packages
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy

8
Principles
  • Ranking or ordering of objects
  • Abstraction
  • Encapsulation
  • Modularity
  • Hierarchy

9
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

10
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.

11
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

12
Object-Oriented Design
  • Purpose
  • Promote thinking about software in a way that
    models the way we think and interact with the
    physical word
  • Including specialization
  • Object
  • Properties or attributes
  • Behaviors

13
Programming
  • Class
  • Term for a type of software object
  • Object
  • An instance of a class with
  • specific properties andattributes

14
Programming
  • Problem solving through the use of a computer
    system
  • Maxim
  • You cannot make a computer do something if you do
    not know how to do it yourself

15
Problem Solving Process
Determine
Analysis
problem features
Rethink as
appropriate
Describe objects
Design
and methods
Produce the
Implementation
classes and code
Examine for
Testing
correctness
16
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
17
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 situation where this would
occur ?
18
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.

19
Example
void write_sqrt( double x) // Precondition x
gt 0. // Postcondition The square root of x
has // been written to the standard output.
...
20
Example
Which of these function calls meet the
precondition ?
21
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.

22
. . . so the postcondition becomes true at the
functions end.
  • The programmer who writes the function counts on
    the precondition being valid, and ensures that
    the postcondition becomes true at the functions
    end.

23
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.

24
Example
void write_sqrt( double x) // Precondition x
gt 0. // Postcondition The square root of x
has // been written to the standard output.
assert(x gt 0) ...
25
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.
Write a Comment
User Comments (0)
About PowerShow.com