CS2013 Lecture 7 John Hurley Cal State LA.

Slides:



Advertisements
Similar presentations
Chapter 7. Binary Search Trees
Advertisements

Pointers.
23-Apr-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
Written by: Dr. JJ Shepherd
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
26-Jun-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
13-Jul-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Course: Object Oriented Programming - Abstract Data Types Unit1: IntroductionSlide Number 1 Introduction Course: Object Oriented Programming Abstract Data.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Priority Queues Dr. David Matuszek
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Arrays Chapter 7.
Lecture 6 of Computer Science II
Objects as a programming concept
EECE 310: Software Engineering
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Chapter 4 The easy stuff.
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Big-O notation Linked lists
CS2006- Data Structures I Chapter 5 Linked Lists I.
Object-Oriented Programming
Ch. 2 Object-Oriented Programming
Java Primer 1: Types, Classes and Operators
B-Trees 7/5/2018 4:26 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Creating Objects & String Class
Lecture 2 of Computer Science II
Switch, Rounding Errors, Libraries
Data Structures Mohammed Thajeel To the second year students
Pointers and References
Object-Oriented Programming
structures and their relationships." - Linus Torvalds
Pointers and References
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Data Structures and Analysis (COMP 410)
Lesson 2: Building Blocks of Programming
Introduction to Abstract Data Types
Further Data Structures
Lecture 18 Arrays and Pointer Arithmetic
Pointers and References
CS212D: Data Structures Week 5-6 Linked List.
CC 215 Data Structures Pointers (review and examples)
CS2013 Lecture 4 John Hurley Cal State LA.
CS2013 Lecture 7 John Hurley Cal State LA.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
CSE 501N Fall ‘09 13: Interfaces and Multiple Representation
Stacks Abstract Data Types (ADTs) Stacks
ArrayLists 22-Feb-19.
Abstract Data Types 24-Feb-19.
Focus of the Course Object-Oriented Software Development
Introduction to Data Structure
Java Programming Language
Data Structures & Algorithms
Stacks, Queues, and Deques
Lists CMSC 202, Version 4/02.
Lecture 8 Object Oriented Programming (OOP)
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
structures and their relationships." - Linus Torvalds
Week 7 - Monday CS 121.
Lecture 4 – Data collection List ADT
Presentation transcript:

CS2013 Lecture 7 John Hurley Cal State LA

Review: Data types I Application data is typed--classified into various categories--such as int, boolean, String A data type represents a set of possible values, such as {..., -2, -1, 0, 1, 2, ...}, or {true, false} By typing our variables, we allow the computer to find some of our errors Some operations only make sense when applied to certain kinds of data--multiplication, searching Typing simplifies internal representation A String requires more and different storage than a boolean Slide by David Matuszek, University of Pennsylvania

Data types II A data type is characterized by: a set of values a data representation, which is common to all these values, and a set of operations, which can be applied uniformly to all these values Slide by David Matuszek, University of Pennsylvania

Primitive types A primitive data type like char, byte, short, int, long, double has a set of values a data representation a set of operations These are “set in stone”—there is nothing the programmer can do to change anything about them Slide by David Matuszek, University of Pennsylvania

Classes A class is a data type The possible values of a class are objects The data representation is a reference (pointer) to a block of storage The structure of this block is defined by the fields (both inherited and immediate) of the class The operations on the objects are its methods Slide by David Matuszek, University of Pennsylvania, edited

Insertion into a List There are many ways you could insert a new node into a List: • As the new first element • As the new last element • Before a given node • After a given node • Before a given value • After a given value • Before the nth element • After the nth element • Before the nth from the end • After the nth from the end • In the correct location to keep the list in sorted order We need to supply the ones that are useful and efficient for applications in which we might use the List type Slide by David Matuszek, University of Pennsylvania, edited

Efficiency A list is just a sequence of values—it could be implemented by a linked list or by an array Inserting as a new first element is efficient for a linked list representation, inefficient for an array Accessing the nth element is efficient for an array representation, inefficient for a linked list Inserting in the nth position is efficient for neither We don’t want to make it easy for the user (programmer writing an application that uses our data type) to be inefficient The user should just have to learn to use the interface of our data type. S/he should not have to understand the implementation. Slide by David Matuszek, University of Pennsylvania, edited

Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures gives rise to abstract data types (ADTs). An ADT is a model of a data structure that specifies the type of data stored, the operations supported on them, and the types of parameters of the operations. An ADT specifies what each operation does, but not how it does it. The collective set of behaviors supported by an ADT is its public interface. © 2014 Goodrich, Tamassia, Goldwasser Object-Oriented Programming 8

Data Structures Many kinds of data consist of multiple parts, organized (structured) in some way A data structure consists of multiple values Hence, an array is a data structure, but an integer is not When we talk about data structures, we are talking about the implementation of a data type If I talk about the possible values of, say, complex numbers, and the operations I can perform with them, I am talking about them as an ADT If I talk about the way the parts (“real” and “imaginary”) of a complex number are stored in memory, I am talking about a data structure An ADT may be implemented in several different ways A complex number might be stored as two separate doubles, or as an array of two doubles, or in some other way Slide by David Matuszek, University of Pennsylvania, edited

Data representation in an ADT An ADT must obviously have some kind of representation for its data The user need not know the representation The user should not be allowed to tamper with the representation Solution: Make all data private But what if it’s really more convenient for the user to have direct access to the data? setters and getters Slide by David Matuszek, University of Pennsylvania, edited

What’s the point? Setters and getters allow you to keep control of your implementation For example, you decide to define a Point in a plane by its x-y coordinates, providing two public variables Later on, as you gradually add methods to this class, you decide that it’s more efficient to represent a point by its angle and distance from the origin, θ and ρ Sorry, you can’t do that—you’ll break too much code that accesses x and y directly If you had used setters and getters, you could redefine them to compute x and y from θ and ρ Slide by David Matuszek, University of Pennsylvania, edited

Implementing an ADT To implement an ADT, you need to choose: a data representation must be able to represent all necessary values of the ADT Data should be private an algorithm for each of the necessary operations must be consistent with the chosen representation all auxiliary (helper) operations that are not in the contract should be private Remember: Once other people (or other classes) are using your code: It’s easy to add functionality You can only remove functionality if no one is using it! Slide by David Matuszek, University of Pennsylvania, edited

Summary A Data Type describes values, representations, and operations An Abstract Data Type describes values and operations, but not representations An ADT should protect its data and keep it valid All, or nearly all, data should be private Access to data should be via getters and setters An ADT should provide: A contract; definitions of what needs to be done A necessary and sufficient set of operations Slide by David Matuszek, University of Pennsylvania, edited

Declaring ADTs In Java, ADTs are often specified using Java interfaces or abstract classes. The actual data structures that implement the ADTs, are, of course, defined using classes. Slide by David Matuszek, University of Pennsylvania, edited