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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Computer Science 112 Fundamentals of Programming II Overview of Collections.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 The Stack ADT (§4.2) The Stack ADT stores arbitrary objects Insertions and deletions.
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,
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
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.
CS Winter 2011 Abstract Data Types. Container Classes Over the years, programmers have identified a small number of different ways of organizing.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
111 © 2002, Cisco Systems, Inc. All rights reserved.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
1 CSE 1342 Programming Concepts Lists. 2 Basic Terminology A list is a finite sequence of zero or more elements. –For example, (1,3,5,7) is a list of.
CSE 373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
Data structures Abstract data types Java classes for Data structures and ADTs.
ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,
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.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
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.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
List Interface and Linked List Mrs. Furman March 25, 2010.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Data-structure-palooza Checkout DataStructures from SVN.
C++ Review STL CONTAINERS.
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
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.
Fundamentals of Programming II Overview of Collections
Data Structures and Database Applications Abstract Data Types
ECET 370 HELPS Education for Service- - ecet370helps.com.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
structures and their relationships." - Linus Torvalds
Review & Lab assignments
Introduction to Data Structure
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
slides created by Marty Stepp and Hélène Martin
Presentation transcript:

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/0 !) –addition, multiplication, negation, reciprocal

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

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 Dictionary – key-value pairs Graph – vertices and arcs

Bag ADT values: object references (unordered) basic operations: –insert (client has no control over placement) –remove (based on object identity) –find (membership test) common operations –size (how many values are in a given bag) a simple but often useful ADT

insert Given an object reference R and a bag B, after B.insert(R), B.find(R) must return true. Size of B must be one more after an insertion than the size of B immediately prior to insertion. B.insert(R) may fail if memory to store R in B cannot be allocated B.insert(R) should not fail otherwise (duplicates are allowed)

Unit tests for ‘insert’? REQUIREMENT: Given an object reference R and a bag B, after B.insert(R), B.find(R) must return true. UNIT TEST: Bag b = new Bag(); SomeType r = new SomeType(); b.insert(r); assertTrue(r+“ should be in ”+b+“ but isn’t!”, b.find(r));

Unit tests for ‘insert’? REQUIREMENT: Size of B must be one more after an insertion than the size of B immediately prior to insertion. UNIT TEST: Bag b = new Bag(); SomeType r = new SomeType(); int sizeBefore = b.size(); b.insert(r); int sizeAfter = b.size(); assertTrue(sizeAfter+“ should be ”+sizeBefore+“+1, but isn’t!”, sizeAfter==sizeBefore+1);

Unit tests for ‘insert’ / ‘remove’ / ‘find’ / ‘size’ / other operations? Left as exercise for you!

Let’s look at some code… Unit tests for Bag Exception handling (continued from Friday)