Prepared by Dr. Inayatullah Shah1 Data Structures CSC212.

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

Data Structures ADT List
Data Structure & Abstract Data Type
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
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.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
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.
Compiler Construction
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.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
MIT AITI 2003 Lecture 7 Class and Object - Part I.
Programming Languages
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
DAT602 Database Application Development Lecture 5 JAVA Review.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Generic abstraction  Genericity  Generic classes  Generic procedures Programming Languages 3 © 2012 David A Watt, University of Glasgow.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Java Java Translation Program Structure
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
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,
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
1 Introduction  Algorithms  Data structures  Abstract data types  Programming with lists and sets © 2008 David A Watt, University of Glasgow Algorithms.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
ABSTRACT DATA TYPES, ABSTRACT CLASSES AND INTERFACES And abstract art….
CSC 205 Java Programming II Introduction. Topics Syllabus Course goals and approach Review I Java language fundamentals.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
REEM ALMOTIRI Information Technology Department Majmaah University.
© 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.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Lecture 1 Data Structures Shafay Shamail September 05, 2006.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
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.
Introduction to Computer Science / Procedural – 67130
Lecture 2: Data Types, Variables, Operators, and Expressions
Prepared by Dr. Inayatullah Shah
نوع داده هاي انتزاعي Abstract Data Types
Data Structures ADT List
Data Structures ADT List
Introduction to Java Programming
An Introduction to Java – Part I, language basics
COMPUTER 2430 Object Oriented Programming and Data Structures I
Data Structures ADT List
Data Structures: Introduction
Introduction to Data Structure
Data Structures: Abstract Data Types (ADTs)
Agenda Types and identifiers Practice Assignment Keywords in Java
Data Structures: Introduction
Introduction to java Part I By Shenglan Zhang.
Presentation transcript:

Prepared by Dr. Inayatullah Shah1 Data Structures CSC212

Prepared by Dr. Inayatullah Shah2 Data Types & Data Structures Applications/programs read, store and operate on data. Finally output results. What is data? Numbers, Characters, etc. Application/ Program Data

Prepared by Dr. Inayatullah Shah3 Data Types & Data Structures Data is classified into data types. e.g. char, float, int, etc. A data type is (i) a domain of allowed values and (ii) a set of operations on these values.

Prepared by Dr. Inayatullah Shah4 Data Types & Data Structures Examples Data TypeDomainOperations boolean0,1and, or, =, etc. charASCII=, <>, <, etc. integer-maxint to +maxint +, _, =, ==, <>, <, etc.

Prepared by Dr. Inayatullah Shah5 Data Types & Data Structures int i,j;  i, j can take only integer values and only integer operations can be carried out on i, j. Built-in types: defined within the language e.g. int,float, etc. User-defined types: defined and implemented by the user e.g. using typedef.

Prepared by Dr. Inayatullah Shah6 Data Types & Data Structures Simple Data types: also known as atomic data types  have no component parts. E.g. int, char, float, etc ‘a’

Prepared by Dr. Inayatullah Shah7 Data Types & Data Structures Structured Data types: can be broken into component parts. E.g. record, array, set, file, etc. Example: a student record. AHMAD 20 CSC Name Age Branch A Component part

Prepared by Dr. Inayatullah Shah8 Data Types & Data Structures A data structure is a data type whose values (i) can be decomposed into a set of component elements each of which is either simple (atomic) or another data structure (ii) include a structure involving the component parts.

Prepared by Dr. Inayatullah Shah9 Data Types & Data Structure Possible Structures: Set, Linear, Tree, Graph. SET LINEAR TREE GRAPH

Prepared by Dr. Inayatullah Shah10 Data Types & Data Structures What is the domain of a structured data type? Operations? Example: boolean Sample[3]; Domain 100

Prepared by Dr. Inayatullah Shah11 Data Types & Data Structures Example: Operations: Sample[0] = 1; C = Sample[1]; etc. Elements Structure Domain Operations Data Type/ Structure

Prepared by Dr. Inayatullah Shah12 Abstract Data Types (ADTs) Abstraction? Hides details, provides only the essentials. Example: an integer 165 = , procedures/subprograms, etc. Abstract Data Types (ADTs): Simple or structured data types whose implementation details are hidden…

Prepared by Dr. Inayatullah Shah13 ADTs Questions about data types: –(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?

Prepared by Dr. Inayatullah Shah14 ADTs ADTs specification answers the ‘what’ questions. Done 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 who implements ADT is concerned with..specification, representation, implementation.

Prepared by Dr. Inayatullah Shah15 ADTs Elements Structure OperationsDomain Specification Representation Implementation User of an ADT must only know this Implementer must know all these.

Prepared by Dr. Inayatullah Shah16 ADT: Example ADT String1 Design (Specification): Elements: One character. Structure: elements (characters) are linearly arranged. Domain: There are 0 to 80 chars in a string, therefore … possible strings in the domain. Operations: 1. Append (c: char) Requires: The length of the string must be less than 80. Results: c is appended to the right end of the string.

Prepared by Dr. Inayatullah Shah17 ADT: Example 2. Remove Requires: The length of the string must be greater than 0. Results: The rightmost character of the string is removed and it is returned as the output of this operation. The string’s length is decreases by MakeEmpty Requires: The length of the string must be less than 80. Results: all characters are removed. 4. Concatenate (R: String) Results: A string R is concatenated to the right of the string. 5. Reverse 6. Length 7. Equal (R: String) 8. GetChar (int i) Requires: The length of the string must be greater than or equal to i. Results: Return the i-th character in the string.

Prepared by Dr. Inayatullah Shah18 Note.. In Java the class construct is used to declare new data types. In Java operations are implemented as methods.

Prepared by Dr. Inayatullah Shah19 ADT Representation in Java public class String1 extends Object { private char[] str; private int size; public void Append (char c) { }

Prepared by Dr. Inayatullah Shah20 ADT Representation in Java public char Remove (){ } public char GetChar(int i){ } public void MakeEmpty (){ } public int Length (){ }

Prepared by Dr. Inayatullah Shah21 ADT Representation in Java public void Concatenate (String1 s){ } public boolean Equal (String1 s){ } public void Reverse () { }

Prepared by Dr. Inayatullah Shah22 ADT Implementation in Java public class String1 extends Object { private char[] str; private int size; public String1 () { size = 0; str = new char[80]; } public void Append (char c) { str[size] = c; size++; }

Prepared by Dr. Inayatullah Shah23 ADT Implementation in Java public char Remove (){ size--; return(str[size]); } public char GetChar(int i){ return(str[i-1]); } public void MakeEmpty (){ size = 0; } public int Length (){ return(size);}

Prepared by Dr. Inayatullah Shah24 ADT Implementation in Java public void Concatenate (String1 s){ char c; for (int i = 0; i<s.Length(); i++) { c = s.GetChar(i+1); Append(c); } And we do the same thing for all other methods.

Prepared by Dr. Inayatullah Shah25 ADT Implementation in Java 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(1)); System.out.println(s.GetChar(2)); }