Data Structures: Abstract Data Types (ADTs)

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Data Structures ADT List
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Designing an ADT The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT What data does.
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.
Hand Crafting your own program By Eric Davis for CS103.
Prepared by Dr. Inayatullah Shah1 Data Structures CSC212.
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
1 Data Structures CSC Data Types & Data Structures Applications/programs read, store and operate on data. Finally output results. What is data?
1 Data Structures: Introduction CSC Data Types & Data Structures Applications/programs read data, store data temporarily, process it and finally.
Arrays in Java An array is a collection of elements of the same type Declaration (we will use integers in this example) int[] A; int A[]; after this the.
Fall 2007CS 2251 Stacks Chapter 5. Fall 2007CS 2252 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop,
Abstract Data Types II. Sufficient operations Operations on an ADT are sufficient if they meet all the requirements –They must be able to create all the.
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
MIT AITI 2003 Lecture 7 Class and Object - Part I.
Course: Object Oriented Programming - Abstract Data Types Unit1: IntroductionSlide Number 1 Introduction Course: Object Oriented Programming Abstract Data.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
2-1 Week 2 Sets Set concepts (you should know these!) Set applications. A set ADT (abstract data type): requirements, contract. Implementations of sets:
Generic abstraction  Genericity  Generic classes  Generic procedures Programming Languages 3 © 2012 David A Watt, University of Glasgow.
Basic Concepts of OOP in C++ Darvay Zsolt. C++ 2 Outline  The namespace and its members  The using declaration and directive  The address operator.
ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs.
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Lecture4: Arrays Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
1 Introduction  Algorithms  Data structures  Abstract data types  Programming with lists and sets © 2008 David A Watt, University of Glasgow Algorithms.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Interfaces and Inner Classes
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Lecture 1 Data Structures Shafay Shamail September 05, 2006.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Object Oriented Programming Lecture 2: BallWorld.
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Examples of Classes & Objects
using System; namespace Demo01 { class Program
Introduction to Computer Science / Procedural – 67130
Lecture 2: Data Types, Variables, Operators, and Expressions
Prepared by Dr. Inayatullah Shah
Building Java Programs
نوع داده هاي انتزاعي Abstract Data Types
Data Structures ADT List
Data Structures ADT List
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Classes & Objects: Examples
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
COMPUTER 2430 Object Oriented Programming and Data Structures I
class PrintOnetoTen { public static void main(String args[]) {
Queues CSC212.
Data Structures ADT List
Data Structures: Introduction
Arrays in Java.
Agenda Types and identifiers Practice Assignment Keywords in Java
Topics OOP Review Inheritance Review Abstract Classes
Data Structures: Introduction
Introduction to java Part I By Shenglan Zhang.
More on iterations using
Presentation transcript:

Data Structures: Abstract Data Types (ADTs) GC211

Abstract Data Types (ADTs) Abstraction? Anything that hides details & provides only the essentials. Examples: an integer 165 = 1.102+6.101+5.100, procedures/subprograms, etc. Abstract Data Types (ADTs): Simple or structured data types whose implementation details are hidden…

ADTs While designing ADTs, a designer has to deal with two types of questions: (i) What values are in the domain? What operations can be performed on the values of a particular data type? (ii) How is the data type represented? How are the operations implemented?

ADTs ADTs specification answers the ‘what’ questions. Specification is written first. ADTs implementation answers the ‘how’ questions. Done after specification. Users & Implementers. Users of an ADT need only know the specification …. no implementation details. advantage Programmer (Implementer) who implements ADT is concerned with..specification, representation, implementation.

ADTs Elements Structure Operations Domain Specification Representation Implementation User of an ADT must know only this Implementer must know all these.

ADT: Example ADT String1 Specification: Elements: type char. Structure: elements (characters) are linearly arranged. Domain: type String, finite domain, there are 0 to 80 chars in a string, therefore 1+128+1282+…..+12880 possible stings in the domain. Operations: Assume that there is a string S. 1.Procedure Append (c: char) Requires: length(S) < 80. Results: c is appended to the right end of S.

ADT: Example 2. Procedure Remove (c: char) Requires: length(S) > 0. Results: The rightmost character of S is removed and placed in c, S’s length decreases by 1. 3. Procedure MakeEmpty () Results: all characters are removed. 4. Procedure Concatenate (R: String) Results: String R is concatenated to the right of string S, result placed into S. 5. Procedure Reverse () 6. Procedure Length (L: int) 7. Procedure Equal (S: String, flag: boolean) 8. Procedure GetChar (int i)

Note .. In Java the class construct is used to declare new data types. In Java operations are implemented as function members of classes or methods.

ADT String: Implementation public class String1 extends Object { private char[] str; private int size; public String1 () { size = -1; str = new char[80]; } public void Append (char c) { size++; str[size] = c; Representation Implementation

ADT String: Implementation public char Remove (){ char c = str[size]; size--; return(c); } public char GetChar(int i){ return(str[i]); public void MakeEmpty (){ size = -1; public int Length (){ return(size); }

ADT String: Implementation public void Concatenate (String1 s){ for (int i = 0; i<=s.Length(); i++) { char c = s.GetChar(i); Append(c); } public boolean Equal (String1 s){ public void Reverse () {

Using ADT String import java.lang.*; public class Test { public static void main(String[] args) { String1 s = new String1(); String1 s1 = new String1(); System.out.println("Hello, World"); s.Append('a'); s1.Append('b'); s.Concatenate(s1); System.out.print(s.GetChar(0)); System.out.println(s.GetChar(1)); }