Docsity

ADTs vs. Data Structures - Algorithms and Abstract Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Toggle sidebar
bg1
8/31/10&
1&
CPSC 223
Algorithms & Abstract Data Structures
Lecture 1: !
Overview, ADTs vs. Data Structures, and
Class Inheritance!
* Some material adapted from F. Carrano, K. Yerion, and K. Fant!
Today …
• Course overview!
• Basic C++ Inheritance!
• Homework 1!
• Reading assignments!
– Appendix A!
– Sect. 1.3!
– Ch. 3 !
– Handout (optional)!
CPSC&223,&Fall&2010& 2&
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download ADTs vs. Data Structures - Algorithms and Abstract Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

CPSC 223

Algorithms & Abstract Data Structures

Lecture 1:

Overview, ADTs vs. Data Structures, and

Class Inheritance

  • Some material adapted from F. Carrano, K.Yerion, and K. Fant Today …
  • Course overview
  • Basic C++ Inheritance
  • Homework 1
  • Reading assignments
    • Appendix A
    • Sect. 1.
    • Ch. 3
    • Handout (optional) CPSC 223, Fall 2010 2

About this Course

Instructor

Shawn Bowers

  • Email: [email protected]
  • Office: 309C Herak
  • Office Hours: M-Th, 3:00pm–4:00pm ( or by appointment )

Course webpage

  • http://www.cs.gonzaga.edu/~bowers/courses/cpsc
  • Grades posted to http://blackboard.gonzaga.edu

Textbook

  • Data Abstraction & Problem Solving with C++:Walls and Mirrors , 5th edition, Carrano, Addison-Wesley, 2006 CPSC 223, Fall 2010 3 About this Course

Continuation of CS II, emphasis on Data Structures, ADTs,

and Algorithm Analysis

More C++ programming

Grades:

  • (35%) Individual Assignments
  • (10%) Group project
  • (15%) Quizzes
  • (20%) Two Midterm Exams
  • (20%) Final Exam Letter grade cutoffs A: 90-100%, B: 80-89%, etc. CPSC 223, Fall 2010 4

About this Course No classes …

  • Thursday, November 26 (Thanksgiving) Midterms and Final
  • Midterm I, Sept. 30 (in class)
  • Midterm II, Nov. 4 (in class)
  • Final, Dec. 16 (8:00am – 10:00am) Be sure to carefully read the syllabus CPSC 223, Fall 2010 7 Course Topics
  • Abstract Data Types & Data Structures
  • More C++ and Object-Oriented Programming
  • Inheritance, operator overloading, virtual functions, friends
  • Heavy emphasis on dynamic structures (i.e., pointers!)
  • Data structures
  • Linked lists, binary search trees, balanced trees, hash tables
  • Algorithms
  • Searching and sorting
  • Analysis using big O notation CPSC 223, Fall 2010 8

Course Topics

  • Abstract Data Types & Data Structures
  • More C++ and Object-Oriented Programming
    • Inheritance, operator overloading, virtual functions, friends
    • Heavy emphasis on dynamic structures (i.e., pointers!)
  • Data structures
    • Linked lists, binary search trees, balanced trees, hash tables
  • Algorithms
    • Searching and sorting
    • Analysis using big O notation CPSC 223, Fall 2010 9

WARNING

This class is tough!

  • Lots of programming
  • Some hard assignments Give yourself plenty of 0me First Quiz
  • This is an easy one …
  • Why quizzes?
  • To see the types of questions I ask on exams
  • To give feedback on understanding of material
  • To help you master the material The main way to do well on quizzes is to take them! CPSC 223, Fall 2010 10

Some Key Terminology

  • Modularity
  • Data Abstraction
  • Abstract Data Types
  • Data Structure
  • Client and User CPSC 223, Fall 2010 13 What we mean by “Modularity” Modularity is a design principle for managing the complexity of programs
  • Build software out of smaller, self-contained pieces
    • Modules may already exist (reuse)
    • New modules can be specified early
    • New modules can be implemented independently (even if other modules of the program are not implemented yet) CPSC 223, Fall 2010 14

What we mean by “Data Abstraction” Data abstraction is a design principle that separates the allowable operations on a collection of data from the implementation of these operations

  • Provides a separation (a “wall”) between a high-level definition and the concrete implementation - program against the high-level definition - focus on “ what ” can be done instead of “ how ” it is done
  • Allows changing implementation without changing dependencies CPSC 223, Fall 2010 15 Data type Interface (allowable operaIons) ImplementaIonImplementaIon Program ImplementaIon What we mean by “Abstract Data Type” (ADT) An Abstract Data Type (ADT) is a mechanism for realizing data abstraction
  • An ADT consists of a collection of (allowable) data and a set of operations on that data
  • Together they specify how a “data type” behaves
  • Ideally, all interaction with the data is only through ADT operations
  • The ADT specifies a “contract” with the client
  • “ Data type ” is broad … e.g., primitives like ints, doubles, strings, or structures like arrays, lists, trees CPSC 223, Fall 2010 16

What we mean by “Client” and “User” A Client is the program or module that uses a module

  • Sometimes referred to as a “dependency”
  • A program is a client of the modules it uses
  • A Queue implementation may be a client of a linked-list data structure A User is (typically) a person that executes and interacts with a program
  • We often call the program the “user application”
  • “ User app ” and “ Client program ” used interchangeably CPSC 223, Fall 2010 19 In this course, we mainly focus on Modular design through ADTs and Data Structures …
  • Use data abstraction
  • Learn (more of) the “standard” ADTs
  • lists, trees, tables
  • Learn (more of) the “standard” data structures
  • dynamic memory, pointer-based implementations
  • Analyze these approaches
  • algorithm efficiency (theoretical) Generic C++ components (re)used in many apps CPSC 223, Fall 2010 20

Aside: Theoretical vs. Empirical Evaluation We mainly discuss theoretical efficiency of algorithms

  • For example, upper bounds on algorithm complexity
  • Independent of data, machine, or implementation used The group project will focus on empirical (experimental) efficiency of implementations
  • How do approaches perform on actual data?
  • Analyzing algorithm complexity is often much harder
  • Experimental “benchmarking” is very common in CS We’ll talk more about the project later in the course CPSC 223, Fall 2010 21 Object-Oriented Programming In this course, what is “good” C++ software design?
  1. Use C++ classes to define ADTs
  2. All data members private
  3. All ADT operations public
  4. Client should not be aware of data structure used
  • For example, that there is a node or next pointer in a linked list, or an index to an array
  • Allow an ADT to “ plug and play ” different data structures to improve efficiency without disrupting client program CPSC 223, Fall 2010 22

Object-Oriented Programming In this course, what is “good” C++ software design?

  1. Our client programs represent
    • a “test bed”
    • main function should handle I/O, create objects, call and test methods
  2. Well-designed tests to exercise ADT operations
    • tests should help to ensure reusability
    • test range of data, including end points
    • test invalid data
    • as reasonable, use files for input CPSC 223, Fall 2010 25 Object-Oriented Programming In this course, what is “good” C++ software design?
  3. No global variables
  4. Focus on efficient implementation
    • E.g., only traverse structures when absolutely necessary
    • Use pass-by-reference to reduce instances of structs and classes from being copied CPSC 223, Fall 2010 26

Programming Assignments

  • Managing a simple Electronic Dictionary
    • Consisting of words and definitions
    • We will develop different ADTs and algorithms to store , search , and sort dictionaries
  • The basic types (modules) of our dictionaries are Key : a class to represent dictionary words Entry : a class to represent definitions of words Dictionary : a class to represent a collection entries CPSC 223, Fall 2010 27 Assignment 1
  • Implement a Key and Entry class
    • Entry is a subclass of Key
    • Do basic operator overloading (=, <, ==)
    • Hint: use the C++ string class CPSC 223, Fall 2010 28