1 Data Structures: Introduction CSC212. 2 Data Types & Data Structures Applications/programs read data, store data temporarily, process it and finally.

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
Introduction to Programming G51PRG University of Nottingham Revision 1
Data Structure & Abstract Data Type
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 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
Stacks, Queues, and Deques
Prepared by Dr. Inayatullah Shah1 Data Structures CSC212.
1 Data Structures CSC Data Types & Data Structures Applications/programs read, store and operate on data. Finally output results. What is data?
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.
Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
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.
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.
Chapter 3 Introduction to Collections – Stacks Modified
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.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
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.
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
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.
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.
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
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
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.
Lecture 1 Data Structures Shafay Shamail September 05, 2006.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
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 toData structures and Algorithms
Introduction to Computer Science / Procedural – 67130
Lecture 2: Data Types, Variables, Operators, and Expressions
Prepared by Dr. Inayatullah Shah
Introduction to Abstract Data Types
Data Structures ADT List
Data Structures ADT List
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Some slides are borrowed from Mr. Mohammad Alqahtani
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:

1 Data Structures: Introduction CSC212

2 Data Types & Data Structures Applications/programs read data, store data temporarily, process it and finally output results. What is data? Numbers, Characters, etc. Application/ Program Data

3 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. Compiler signals an error if wrong operation is performed on data of a certain type. For example, char x,y,z; z = x*y is not allowed.

4 Data Types & Data Structures Examples Data TypeDomainOperations boolean0,1and, or, =, etc. charASCII=, <>, <, etc. integer-maxint to +maxint +, _, =, ==, <>, <, etc.

5 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 or class.

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

7 Data Types & Data Structures Structured Data types: can be broken into component parts. E.g. an object, array, set, file, etc. Example: a student object. AHMAD 20 CSC Name Age Branch A Component part

8 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.

9 Data Types & Data Structure Possible Structures: Set, Linear, Tree, Graph. SET LINEAR TREE GRAPH

10 Data Types & Data Structures What is the domain of a structured data type? Operations? Example: boolean[] Sample[3]; Domain 100

11 Data Types & Data Structures Example: Operations: Sample[0] = True; C = Sample[1]; etc. Elements Structure Domain Operations Data Type/ Structure

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

13 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?

14 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.

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

16 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 … 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.

17 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 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)

18 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.

19 ADT String 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; } Implementation Representation

20 ADT String 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);}

21 ADT String 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 () { }

22 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)); }