Abstract Data Types (ADTs) An ADT consists of: –a set of values, and –a set of operations on those values. Example: rational numbers –some values: 15/7,

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

ITEC200 Week04 Lists and the Collection Interface.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Computer Science 112 Fundamentals of Programming II Overview of Collections.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
CHAPTER 3 COLLECTIONS Abstract Data Types. 2 A data type consists of a set of values or elements, called its domain, and a set of operators acting on.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Abstract Data Types: stepping back from specifics.
Chapter 12: Data Structures
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
CS Winter 2011 Abstract Data Types. Container Classes Over the years, programmers have identified a small number of different ways of organizing.
Abstract Data Types (ADTs) An ADT consists of: –a set of values –a set of operations on those values Rational numbers –15/7, -3/4, 123/1, 0/1 (but NOT.
1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
CSE 143 Lecture 20 Binary Search Trees continued; Tree Sets read slides created by Marty Stepp and Hélène Martin
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Data Structures and Abstractions with Java, 4e Frank Carrano
Data structures Abstract data types Java classes for Data structures and ADTs.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
ELC 310 Day 24. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Agenda Questions? Problem set 5 Parts A & B Corrected  Good results  2 A’s, 1.
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Interface: (e.g. IDictionary) Specification class Appl{ ---- IDictionary dic; dic= new XXX(); application class: Dictionary SortedDictionary ----
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Object-Oriented Programming (OOP) Lecture No. 2. Information Hiding ► Information is stored within the object ► It is hidden from the outside world ►
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Abstract Data Type EnhanceEdu.
Data-structure-palooza Checkout DataStructures from SVN.
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
Using the Java Collection Libraries COMP 103 # T2
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Abstraction A tool (concept) to manage complexity
JAVA COLLECTIONS LIBRARY
A tree set Our SearchTree class is essentially a set.
Object-Oriented Programming (OOP) Lecture No. 2
Data Structures and Database Applications Abstract Data Types
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
structures and their relationships." - Linus Torvalds
A tree set Our SearchTree class is essentially a set.
Object-Oriented Programming
Collections Not in our text.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Abstract Data Types (ADTs) An ADT consists of: –a set of values, and –a set of operations on those values. Example: rational numbers –some values: 15/7, -3/4, 123/1, 0/1 (but NOT 1/0 !) –some operations: addition, multiplication, negation An ADT therefore specifies: –what the members are, and –what operations are supported.

What an ADT isn’t: An ADT does not specify: –how the data is stored/represented, or –how the operations are implemented. These details are abstracted away. An ADT is implementation independent An ADT is language independent. In Java, an ADT is typically specified in an interface.

Data Structures (DS) A data structure is an implementation of an ADT. In Java, data structures are classes. In the Java Collections framework, the List interface specifies an ADT that is implemented by several data structures: –ArrayList (an array-based structure) –LinkedList (a linked structure)

Analogy #1: vending machine You can perform only the specific tasks that the machine's interface presents to you. You must understand these tasks. E.g. you must know what to do to buy a beverage. You cannot see or access the inside of the machine, because a steel shell encapsulates it. You can use the machine even though you don't know what happens inside. If someone replaced the machine's inner mechanism with an improved version, leaving the interface unchanged, you could still use the machine the same way.

Analogy #2: car Basic interface is the same: –steering wheel to determine path –gearshift (on an automatic) to determine direction (drive/reverse) –pedals to determine speed (accelerator/brake) Underlying implementation is irrelevant –steering: recirculating ball, rack & pinion –transmission: 3, 4 or 5 speed, CVT –engine: 4, 5, 6 or 8 cylinder, gas, diesel, CNG or hybrid Client treats them all the same!

What if the interface changes? How easy is it for people to switch from driving an automatic to a manual transmission car? Automatic: –gear selector: drive/reverse –pedals: accelerator, brake Manual: –gear selector: 1, 2, 3, 4, 5, R –pedals: accelerator, brake, clutch Client needs to adjust to the new interface!

With an ADT The client can only perform the operations specific to the ADT. The client must adhere to the specifications of the operations that the ADT provides. Thus, client must understand how to use the operations.

Interacting with a List (ADT) The client cannot access the data within the list without using an ADT operation. The principle of encapsulation hides the data within the ADT. The client can use the ADT, even though it can't access the data directly, and does not know how it is stored. If you vary the implementation, but maintain the interface, the client isn’t affected and doesn’t have to care.

Examples of ADTs Bag – unordered collection, allowing duplicates Set – unordered collection, no duplicates List – ordered collection – client determines order Sorted list – comparator determines ordering Stack – Last-In First-Out (insert/remove from front) Queue – First-In First-Out (insert back, remove front) Tree – hierarchical organization Binary Search Tree – comparator determines ordering –a simple BST makes no performance guarantees –more advanced BSTs can make performance guarantees Dictionary – collection of key-value pairs Graph – collection of vertices and arcs

Creating an ADT To define an ADT, we Describe its data Specify the operations on that data Focus on “what”, not “how”.

Bag ADT Values: object references (unordered). We use generics to define a parameterized type. The type of the members of the ADT is specified by a type parameter in the definition of the interface.

Bag Operations Basic operations: –add (client has no control over placement; returns a boolean, multiple references to same object are permitted) –remove (based on object identity, i.e. == on object references; returns a boolean) –contains (membership test, based on object identity; returns a boolean) –size (how many values are in a given bag)

Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first consider what the essential functionality of a given ADT is.