Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.

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.
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
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.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chapter 2 Data Design and Implementation. Homework You should have already read section 2.2 You should have already read section 2.2 Read Section 2.3.
Using ArrayList. Lecture Objectives To understand the foundations behind the ArrayList class Explore some of the methods of the ArrayList class.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Aalborg Media Lab 28-Jun-15 Software Design Lecture 8 “Arrays”
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
Chapter 8 Lists. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2 Chapter Objectives Examine list processing and various ordering techniques.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Lecture 9 Concepts of Programming Languages
Basic Concepts Chapter 1 Objectives
CS 171: Introduction to Computer Science II Stacks Ymir Vigfusson.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 3 Introduction to Collections – Stacks Modified
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Lists Based on content from: Java Foundations, 3rd Edition.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Data structures Abstract data types Java classes for Data structures and ADTs.
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.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Software Development
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Object-Oriented Design Concepts University of Sunderland.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
CSE 501N Fall ‘09 10: Introduction to Collections and Linked Lists 29 September 2009 Nick Leidenfrost.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Introduction toData structures and Algorithms
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Chapter 12: Data Structures
structures and their relationships." - Linus Torvalds
Lecture 9 Concepts of Programming Languages
Dynamic Data Structures and Generics
Dynamic Data Structures and Generics
Introduction to Data Structure
Dynamic Array: Implementation of Stack
structures and their relationships." - Linus Torvalds
Arrays.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Data Design and Implementation

Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type A data type whose elements are composed of multiple data items Structured composite type An organized collection of components in which the organization determines the means of accessing individual data components or subsets of the collection 2

Atomic (Simple) and Composite Data Types 3

Java’s Built-In Types 4

Definitions Data abstraction The separation of a data type’s logical properties from its implementation Data encapsulation The separation of the representation of data from the applications that use the data - a feature that enforces information hiding 5

Collections  A collection is an object that serves as a repository for other objects.  The Java Collections Framework contains classes that represent collections of objects.  In general, a collection refers to an object whose role is to provide methods to add, remove and manage the elements that are in the collection. 6

Collections  The ArrayList class in the Collections Framework represents a collection that is implemented with an array.  Some collections are homogeneous – that is they contain objects all of the same type., others are heterogeneous – e.g. a ArrayList – so they can contain objects of different types. 7

Collections & ADT’s  Collections can be implemented in a variety of ways. The ArrayList uses an array.  All operations are performed by using the methods that perform operations on array.  A data structure is a way to organize and access data  A structure that is supposed to store a collection of numbers in order should never allow unordered numbers to occur 8

9 An abstract data type is a collection of data and the particular operations that are allowed on that data. An ADT, therefore has a name, a domain of values(data) and a set of operations that can be performed (methods) on the data An ADT is considered abstract because the operations that you can perform on it are separated from the underlying implementation. ABSTRACT DATA TYPES

ADT & Objects.  We define a Stack ADT with LIFO(Last in-first out) characteristics that requires special operations. We do not specify whether the underlying implementation must be an array or a linked list.  The ADT specifies what can be done, not how it is to be done,  The concept of the ADT is separate from the details of how it stores its data and implements its operations. 10

Data Structures and Interfaces 11 Classes are perfect for ADT’s because all objects have a well-defined interface whose implementation is hidden in the class. In Java, an ADT is expressed in an Interface and implemented in a concrete data structure – specifically in a class. The data structure is usually an array or a linked list. The class defines the data stored and how it is stored and what operations can be performed on it. E.g. in a Stack, items may only be taken from the top.

ADT’s – Abstract Data Types  This encapsulated ADT is reusable and reliable because its interaction with the rest of the system is controlled.  E.g., for an ArrayList, access to the collection is allowed anywhere in the array.  ADT’s can be represented in classes by arrays or by linked lists. The choice of an array or a linked list depends upon the implementation 12

Basic Operations on Encapsulated Data  A constructor is an operation that creates a new instance (object) of the data type.  Transformers (sometimes called mutators) are operations that change the state of one or more of the data values. (setters and getters) 13

Basic Operations on Encapsulated Data  An observer is an operation that allows us to observe the state of one or more of the data values with out changing them. The method peek() in a stack  An iterator is an operation that allows us to process all the components in a data structure sequentially. 14

Data Levels of an ADT  Logical (or abstract) level an ADT: Abstract view of the data values (the domain) and the set of operations to manipulate them. A Stack or Queue  Application (or user) level: Here the application programmer uses the ADT to solve a problem.  Implementation level: A specific representation of the structure to hold the data items, and the coding of the operations in a programming language. Can be implemented with either a linked list or an array 15

Communication between the Application Level and Implementation Level 16

Combining our Built-In Types and Classes into Versatile Hierarchies 1. Aggregate objects—The instance variables of our objects can themselves be references to objects. 2. Arrays of objects—Simply define an array whose components are objects. 17

Example of an Aggregate Object Suppose we define: public class Point { private int xValue private int yValue Then, we could define a new circle class as: public class NewCircle { private Point location;// class contains another object private float radius; public boolean solid; } 18

Designing ADTs  Determine the general purpose.  List the specific types of operations the application program performs.  Identify a set of public methods to be provided by the ADT class that allow the application program to perform the desired operations. 19

Designing ADTs  Identify other public methods which help make the ADT generally usable.  Identify potential error situations and classify into 1. Those that are handled by throwing an exception 2. Those that are handled by contract 3. Those that are ignored. 20

Designing ADTs 6. Define the needed exception classes. 7. Decide how to structure the data. 8. Decide on a protection level for the identified data. 9. Identify private structures and methods. 10. Implement the ADT. 11. Create a test driver and test your ADT. 21

The ArrayList Class  Part of the java.util package. Functionality is similar to that of an array.  However, an array list can grow and shrink; its size is not fixed for its lifetime. Thus is virtually a vector.  Hold variables of type Object.  Capacities grow and shrink, depending on need. 22

Array Lists  An array list has a size indicating how many objects it is currently holding, and  Has a capacity indicating how many elements the underlying implementation could hold without having to be increased. 23

24 Implementing Lists with Arrays An array implementation of a list could follow strategies similar to those used for a queue – which we will look at later We could fix the beginning of the list at index 0 and shift as needed when an element is added or removed However, there is no avoiding a shift when an element in the middle is added or removed Let's examine the fixed version

ArrayList Operations 25

26

27

Use an array list when  Space is an issue.  The amount of space required may change from one execution of the program to the next.  The actively used size of an array list changes during execution. 5. The position of an element in the array list has no relevance to the application ad ArrayList is not ordered. 28