SlideShare a Scribd company logo
1 of 22
1
Data Structures: Introduction
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 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 Type Domain Operations
boolean 0,1 and, or, =, etc.
char ASCII =, <>, <, 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.
21 3.14 ‘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.
A H M A D
20
C S C
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];
000
001
010
011 100
101
110
111
Domain
1 0 0
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 = 1.102+6.101+5.100,
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
Operations
Domain
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 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.
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 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)
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: 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;
}
Implementation
Representation
20
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); }
21
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 () {
}
}
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)); }

More Related Content

Similar to data types.pptx (20)

Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
 
DS.pptx
DS.pptxDS.pptx
DS.pptx
 
Lecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learningLecture 1 Pandas Basics.pptx machine learning
Lecture 1 Pandas Basics.pptx machine learning
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
 
Aspdot
AspdotAspdot
Aspdot
 
UNIT 3 PPT.ppt
UNIT 3 PPT.pptUNIT 3 PPT.ppt
UNIT 3 PPT.ppt
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Adt
AdtAdt
Adt
 
data-structures_unit-01.pdf
data-structures_unit-01.pdfdata-structures_unit-01.pdf
data-structures_unit-01.pdf
 
Algo>Abstract data type
Algo>Abstract data typeAlgo>Abstract data type
Algo>Abstract data type
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 

data types.pptx

  • 2. 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 Data
  • 3. 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. 4 Data Types & Data Structures • Examples Data Type Domain Operations boolean 0,1 and, or, =, etc. char ASCII =, <>, <, etc. integer -maxint to +maxint +, _, =, ==, <>, <, etc.
  • 5. 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. 6 Data Types & Data Structures • Simple Data types: also known as atomic data types 🡪 have no component parts. E.g. int, char, float, etc. 21 3.14 ‘a’
  • 7. 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. A H M A D 20 C S C Name Age Branch A Component part
  • 8. 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. 9 Data Types & Data Structure Possible Structures: Set, Linear, Tree, Graph. SET LINEAR TREE GRAPH
  • 10. 10 Data Types & Data Structures • What is the domain of a structured data type? Operations? • Example: boolean[] Sample[3]; 000 001 010 011 100 101 110 111 Domain 1 0 0
  • 11. 11 Data Types & Data Structures • Example: Operations: Sample[0] = True; C = Sample[1]; etc. Elements Structure Domain Operations Data Type/ Structure
  • 12. 12 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…
  • 13. 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. 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.
  • 16. 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 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.
  • 17. 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 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)
  • 18. 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. 19 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; } Implementation Representation
  • 20. 20 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); }
  • 21. 21 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 () { } }
  • 22. 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)); }