SlideShare a Scribd company logo
1
Chapter 8:
Data Abstractions
Computer Science: An OverviewComputer Science: An Overview
Eleventh Edition
by
J. Glenn Brookshear
Copyright © 2012 Pearson Education, Inc.
Chapter 8: Data Abstractions
• 8.1 Data Structure Fundamentals
• 8.2 Implementing Data Structures
• 8.3 A Short Case Study
• 8.4 Customized Data Types
• 8.5 Classes and Objects
Copyright © 2012 Pearson Education, Inc. 0-2
• 8.6 Pointers in Machine Language
2
Basic Data Structures
• Homogeneous array
• Heterogeneous array
• List
– Stack
– Queue
T
Copyright © 2012 Pearson Education, Inc. 0-3
• Tree
Figure 8.1 Lists, stacks, and queues
Copyright © 2012 Pearson Education, Inc. 0-4
3
Terminology for Lists
• List: A collection of data whose entries are
d ti llarranged sequentially
• Head: The beginning of the list
• Tail: The end of the list
Copyright © 2012 Pearson Education, Inc. 0-5
Terminology for Stacks
• Stack: A list in which entries are removed
d i t d l t th h dand inserted only at the head
• LIFO: Last-in-first-out
• Top: The head of list (stack)
• Bottom or base: The tail of list (stack)
Copyright © 2012 Pearson Education, Inc. 0-6
• Pop: To remove the entry at the top
• Push: To insert an entry at the top
4
Terminology for Queues
• Queue: A list in which entries are removed
t th h d d i t d t th t ilat the head and are inserted at the tail
• FIFO: First-in-first-out
Copyright © 2012 Pearson Education, Inc. 0-7
Figure 8.2 An example of an
organization chart
Copyright © 2012 Pearson Education, Inc. 0-8
5
Terminology for a Tree
• Tree: A collection of data whose entries
h hi hi l i tihave a hierarchical organization
• Node: An entry in a tree
• Root node: The node at the top
• Terminal or leaf node: A node at the
bottom
Copyright © 2012 Pearson Education, Inc. 0-9
bottom
Terminology for a Tree (continued)
• Parent: The node immediately above a
specified nodespecified node
• Child: A node immediately below a
specified node
• Ancestor: Parent, parent of parent, etc.
• Descendent: Child, child of child, etc.
Copyright © 2012 Pearson Education, Inc. 0-10
• Siblings: Nodes sharing a common parent
6
Terminology for a Tree (continued)
• Binary tree: A tree in which every node
h t t t hildhas at most two children
• Depth: The number of nodes in longest
path from root to leaf
Copyright © 2012 Pearson Education, Inc. 0-11
Figure 8.3 Tree terminology
Copyright © 2012 Pearson Education, Inc. 0-12
7
Additional Concepts
• Static Data Structures: Size and shape of
d t t t d t hdata structure does not change
• Dynamic Data Structures: Size and shape
of data structure can change
• Pointers: Used to locate data
Copyright © 2012 Pearson Education, Inc. 0-13
Figure 8.4 Novels arranged by title
but linked according to authorship
Copyright © 2012 Pearson Education, Inc. 0-14
8
Storing Arrays
• Homogeneous arrays
Ro major order ers s col mn major– Row-major order versus column major
order
– Address polynomial
• Heterogeneous arrays
– Components can be stored one after the other
in a contiguous block
Copyright © 2012 Pearson Education, Inc. 0-15
in a contiguous block
– Components can be stored in separate
locations identified by pointers
Figure 8.5 The array of temperature
readings stored in memory starting
at address x
Copyright © 2012 Pearson Education, Inc. 0-16
9
Figure 8.6 A two-dimensional array with
four rows and five columns stored in row
major order
Copyright © 2012 Pearson Education, Inc. 0-17
Figure 8.7 Storing the heterogeneous
array Employee
Copyright © 2012 Pearson Education, Inc. 0-18
10
Storing Lists
• Contiguous list: List stored in a
hhomogeneous array
• Linked list: List in which each entries are
linked by pointers
– Head pointer: Pointer to first entry in list
– NIL pointer: A “non-pointer” value used to
Copyright © 2012 Pearson Education, Inc. 0-19
NIL pointer: A non pointer value used to
indicate end of list
Figure 8.8 Names stored in memory
as a contiguous list
Copyright © 2012 Pearson Education, Inc. 0-20
11
Figure 8.9 The structure of a linked
list
Copyright © 2012 Pearson Education, Inc. 0-21
Figure 8.10 Deleting an entry from a
linked list
Copyright © 2012 Pearson Education, Inc. 0-22
12
Figure 8.11 Inserting an entry into a
linked list
Copyright © 2012 Pearson Education, Inc. 0-23
Storing Stacks and Queues
• Stacks usually stored as contiguous lists
• Queues usually stored as Circular
Queues
– Stored in a contiguous block in which the first
entry is considered to follow the last entry
– Prevents a queue from crawling out of its
Copyright © 2012 Pearson Education, Inc. 0-24
Prevents a queue from crawling out of its
allotted storage space
13
Figure 8.12 A stack in memory
Copyright © 2012 Pearson Education, Inc. 0-25
Figure 8.13 A queue implementation with
head and tail pointers
Copyright © 2012 Pearson Education, Inc. 0-26
14
Storing Binary Trees
• Linked structure
– Each node = data cells + two child pointers
– Accessed via a pointer to root node
• Contiguous array structure
– A[1] = root node
A[2] A[3] = children of A[1]
Copyright © 2012 Pearson Education, Inc. 0-27
– A[2],A[3] = children of A[1]
– A[4],A[5],A[6],A[7] = children of A[2] and A[3]
Figure 8.14 A circular queue
containing the letters P through V
Copyright © 2012 Pearson Education, Inc. 0-28
15
Figure 8.15 The structure of a node
in a binary tree
Copyright © 2012 Pearson Education, Inc. 0-29
Figure 8.16 The conceptual and
actual organization of a binary tree
using a linked storage system
Copyright © 2012 Pearson Education, Inc. 0-30
16
Figure 8.17 A tree stored without
pointers
Copyright © 2012 Pearson Education, Inc. 0-31
Figure 8.18 A sparse, unbalanced tree
shown in its conceptual form and as it
would be stored without pointers
Copyright © 2012 Pearson Education, Inc. 0-32
17
Manipulating Data Structures
• Ideally, a data structure should be
manipulated solely by pre definedmanipulated solely by pre-defined
procedures.
– Example: A stack typically needs at least
push and pop procedures.
– The data structure along with these
procedures constitutes a complete abstract
Copyright © 2012 Pearson Education, Inc. 0-33
procedures constitutes a complete abstract
tool.
Figure 8.19 A procedure for printing
a linked list
Copyright © 2012 Pearson Education, Inc. 0-34
18
Case Study
Problem: Construct an abstract tool
i ti f li t f i l h b ti lconsisting of a list of names in alphabetical
order along with the operations search,
print, and insert.
Copyright © 2012 Pearson Education, Inc. 0-35
Figure 8.20 The letters A through M
arranged in an ordered tree
Copyright © 2012 Pearson Education, Inc. 0-36
19
Figure 8.21 The binary search as
it would appear if the list were
implemented as a linked binary tree
Copyright © 2012 Pearson Education, Inc. 0-37
Figure 8.22 The successively smaller trees
considered by the procedure in Figure
8.18 when searching for the letter J
Copyright © 2012 Pearson Education, Inc. 0-38
20
Figure 8.23 Printing a search tree in
alphabetical order
Copyright © 2012 Pearson Education, Inc. 0-39
Figure 8.24 A procedure for printing
the data in a binary tree
Copyright © 2012 Pearson Education, Inc. 0-40
21
Figure 8.25 Inserting the entry
M into the list B, E, G, H, J, K, N, P stored
as a tree
Copyright © 2012 Pearson Education, Inc. 0-41
Figure 8.26 A procedure for inserting a
new entry in a list stored as a binary tree
Copyright © 2012 Pearson Education, Inc. 0-42
22
User-defined Data Type
• A template for a heterogeneous structure
• Example:
define type EmployeeType to be
{char Name[25];
int Age;
l SkillR ti
Copyright © 2012 Pearson Education, Inc. 0-43
real SkillRating;
}
Abstract Data Type
• A user-defined data type with procedures for access and
manipulation
• Example:
define type StackType to be
{int StackEntries[20];
int StackPointer = 0;
procedure push(value)
{StackEntries[StackPointer] ← value;
StackPointer ¬ StackPointer + 1;
}
Copyright © 2012 Pearson Education, Inc. 0-44
}
procedure pop . . .
}
23
Class
• An abstract data type with extra features
– Characteristics can be inherited
– Contents can be encapsulated
– Constructor methods to initialize new objects
Copyright © 2012 Pearson Education, Inc. 0-45
Figure 8.27 A stack of integers
implemented in Java and C#
Copyright © 2012 Pearson Education, Inc. 0-46
24
Pointers in Machine Language
• Immediate addressing: Instruction
t i th d t t b dcontains the data to be accessed
• Direct addressing: Instruction contains
the address of the data to be accessed
• Indirect addressing: Instruction contains
the location of the address of the data to
Copyright © 2012 Pearson Education, Inc. 0-47
the location of the address of the data to
be accessed
Figure 8.28 Our first attempt at expanding the
machine language in Appendix C to take
advantage of pointers
Copyright © 2012 Pearson Education, Inc. 0-48
25
Figure 8.29 Loading a register from a
memory cell that is located by means of a
pointer stored in a register
Copyright © 2012 Pearson Education, Inc. 0-49

More Related Content

Similar to Chap08 data abstraction

IT244 - Week 2 -Ch 1.pptx
IT244 - Week 2 -Ch 1.pptxIT244 - Week 2 -Ch 1.pptx
IT244 - Week 2 -Ch 1.pptx
Ahmed337083
 
Data structures
Data structuresData structures
Data structures
MADHAVASAIYENDUVA
 
Database tia11
Database tia11Database tia11
Database tia11
Jayne Dissette
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
Mahmud Hasan Tanvir
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
Prof. Dr. K. Adisesha
 
Chapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdfChapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdf
TamiratDejene1
 
Lecture-8-The-GIS-Database-Part-1.ppt
Lecture-8-The-GIS-Database-Part-1.pptLecture-8-The-GIS-Database-Part-1.ppt
Lecture-8-The-GIS-Database-Part-1.ppt
Prabin Pandit
 
DBMS-2.pptx
DBMS-2.pptxDBMS-2.pptx
DBMS-2.pptx
kingVox
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
suthi
 
Chapter 7. Databases Chapter In Introduction to Computer. Pptx
Chapter 7. Databases Chapter In Introduction to Computer. PptxChapter 7. Databases Chapter In Introduction to Computer. Pptx
Chapter 7. Databases Chapter In Introduction to Computer. Pptx
MohsinChaudhary17
 
ORE en Fedora Op Klompen
ORE en Fedora Op KlompenORE en Fedora Op Klompen
ORE en Fedora Op Klompen
Lodewijk Bogaards
 
Ch1
Ch1Ch1
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
DataGraft: Data-as-a-Service for Open Data
DataGraft: Data-as-a-Service for Open DataDataGraft: Data-as-a-Service for Open Data
DataGraft: Data-as-a-Service for Open Data
dapaasproject
 
lecture5 (1) (2).pptx
lecture5 (1) (2).pptxlecture5 (1) (2).pptx
lecture5 (1) (2).pptx
RabiullahNazari
 
Sachin noire 2024
Sachin noire 2024Sachin noire 2024
Sachin noire 2024
sachin kumar
 

Similar to Chap08 data abstraction (20)

IT244 - Week 2 -Ch 1.pptx
IT244 - Week 2 -Ch 1.pptxIT244 - Week 2 -Ch 1.pptx
IT244 - Week 2 -Ch 1.pptx
 
Data structures
Data structuresData structures
Data structures
 
Database tia11
Database tia11Database tia11
Database tia11
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
 
Chapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdfChapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdf
 
Lecture-8-The-GIS-Database-Part-1.ppt
Lecture-8-The-GIS-Database-Part-1.pptLecture-8-The-GIS-Database-Part-1.ppt
Lecture-8-The-GIS-Database-Part-1.ppt
 
DBMS-2.pptx
DBMS-2.pptxDBMS-2.pptx
DBMS-2.pptx
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
 
Chapter 7. Databases Chapter In Introduction to Computer. Pptx
Chapter 7. Databases Chapter In Introduction to Computer. PptxChapter 7. Databases Chapter In Introduction to Computer. Pptx
Chapter 7. Databases Chapter In Introduction to Computer. Pptx
 
ORE en Fedora Op Klompen
ORE en Fedora Op KlompenORE en Fedora Op Klompen
ORE en Fedora Op Klompen
 
Ch1
Ch1Ch1
Ch1
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
DataGraft: Data-as-a-Service for Open Data
DataGraft: Data-as-a-Service for Open DataDataGraft: Data-as-a-Service for Open Data
DataGraft: Data-as-a-Service for Open Data
 
Data models
Data modelsData models
Data models
 
Data models
Data modelsData models
Data models
 
Cs501 intro
Cs501 introCs501 intro
Cs501 intro
 
lecture5 (1) (2).pptx
lecture5 (1) (2).pptxlecture5 (1) (2).pptx
lecture5 (1) (2).pptx
 
Sachin noire 2024
Sachin noire 2024Sachin noire 2024
Sachin noire 2024
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
amberjdewit93
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
SriSurya50
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 

Chap08 data abstraction

  • 1. 1 Chapter 8: Data Abstractions Computer Science: An OverviewComputer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright © 2012 Pearson Education, Inc. Chapter 8: Data Abstractions • 8.1 Data Structure Fundamentals • 8.2 Implementing Data Structures • 8.3 A Short Case Study • 8.4 Customized Data Types • 8.5 Classes and Objects Copyright © 2012 Pearson Education, Inc. 0-2 • 8.6 Pointers in Machine Language
  • 2. 2 Basic Data Structures • Homogeneous array • Heterogeneous array • List – Stack – Queue T Copyright © 2012 Pearson Education, Inc. 0-3 • Tree Figure 8.1 Lists, stacks, and queues Copyright © 2012 Pearson Education, Inc. 0-4
  • 3. 3 Terminology for Lists • List: A collection of data whose entries are d ti llarranged sequentially • Head: The beginning of the list • Tail: The end of the list Copyright © 2012 Pearson Education, Inc. 0-5 Terminology for Stacks • Stack: A list in which entries are removed d i t d l t th h dand inserted only at the head • LIFO: Last-in-first-out • Top: The head of list (stack) • Bottom or base: The tail of list (stack) Copyright © 2012 Pearson Education, Inc. 0-6 • Pop: To remove the entry at the top • Push: To insert an entry at the top
  • 4. 4 Terminology for Queues • Queue: A list in which entries are removed t th h d d i t d t th t ilat the head and are inserted at the tail • FIFO: First-in-first-out Copyright © 2012 Pearson Education, Inc. 0-7 Figure 8.2 An example of an organization chart Copyright © 2012 Pearson Education, Inc. 0-8
  • 5. 5 Terminology for a Tree • Tree: A collection of data whose entries h hi hi l i tihave a hierarchical organization • Node: An entry in a tree • Root node: The node at the top • Terminal or leaf node: A node at the bottom Copyright © 2012 Pearson Education, Inc. 0-9 bottom Terminology for a Tree (continued) • Parent: The node immediately above a specified nodespecified node • Child: A node immediately below a specified node • Ancestor: Parent, parent of parent, etc. • Descendent: Child, child of child, etc. Copyright © 2012 Pearson Education, Inc. 0-10 • Siblings: Nodes sharing a common parent
  • 6. 6 Terminology for a Tree (continued) • Binary tree: A tree in which every node h t t t hildhas at most two children • Depth: The number of nodes in longest path from root to leaf Copyright © 2012 Pearson Education, Inc. 0-11 Figure 8.3 Tree terminology Copyright © 2012 Pearson Education, Inc. 0-12
  • 7. 7 Additional Concepts • Static Data Structures: Size and shape of d t t t d t hdata structure does not change • Dynamic Data Structures: Size and shape of data structure can change • Pointers: Used to locate data Copyright © 2012 Pearson Education, Inc. 0-13 Figure 8.4 Novels arranged by title but linked according to authorship Copyright © 2012 Pearson Education, Inc. 0-14
  • 8. 8 Storing Arrays • Homogeneous arrays Ro major order ers s col mn major– Row-major order versus column major order – Address polynomial • Heterogeneous arrays – Components can be stored one after the other in a contiguous block Copyright © 2012 Pearson Education, Inc. 0-15 in a contiguous block – Components can be stored in separate locations identified by pointers Figure 8.5 The array of temperature readings stored in memory starting at address x Copyright © 2012 Pearson Education, Inc. 0-16
  • 9. 9 Figure 8.6 A two-dimensional array with four rows and five columns stored in row major order Copyright © 2012 Pearson Education, Inc. 0-17 Figure 8.7 Storing the heterogeneous array Employee Copyright © 2012 Pearson Education, Inc. 0-18
  • 10. 10 Storing Lists • Contiguous list: List stored in a hhomogeneous array • Linked list: List in which each entries are linked by pointers – Head pointer: Pointer to first entry in list – NIL pointer: A “non-pointer” value used to Copyright © 2012 Pearson Education, Inc. 0-19 NIL pointer: A non pointer value used to indicate end of list Figure 8.8 Names stored in memory as a contiguous list Copyright © 2012 Pearson Education, Inc. 0-20
  • 11. 11 Figure 8.9 The structure of a linked list Copyright © 2012 Pearson Education, Inc. 0-21 Figure 8.10 Deleting an entry from a linked list Copyright © 2012 Pearson Education, Inc. 0-22
  • 12. 12 Figure 8.11 Inserting an entry into a linked list Copyright © 2012 Pearson Education, Inc. 0-23 Storing Stacks and Queues • Stacks usually stored as contiguous lists • Queues usually stored as Circular Queues – Stored in a contiguous block in which the first entry is considered to follow the last entry – Prevents a queue from crawling out of its Copyright © 2012 Pearson Education, Inc. 0-24 Prevents a queue from crawling out of its allotted storage space
  • 13. 13 Figure 8.12 A stack in memory Copyright © 2012 Pearson Education, Inc. 0-25 Figure 8.13 A queue implementation with head and tail pointers Copyright © 2012 Pearson Education, Inc. 0-26
  • 14. 14 Storing Binary Trees • Linked structure – Each node = data cells + two child pointers – Accessed via a pointer to root node • Contiguous array structure – A[1] = root node A[2] A[3] = children of A[1] Copyright © 2012 Pearson Education, Inc. 0-27 – A[2],A[3] = children of A[1] – A[4],A[5],A[6],A[7] = children of A[2] and A[3] Figure 8.14 A circular queue containing the letters P through V Copyright © 2012 Pearson Education, Inc. 0-28
  • 15. 15 Figure 8.15 The structure of a node in a binary tree Copyright © 2012 Pearson Education, Inc. 0-29 Figure 8.16 The conceptual and actual organization of a binary tree using a linked storage system Copyright © 2012 Pearson Education, Inc. 0-30
  • 16. 16 Figure 8.17 A tree stored without pointers Copyright © 2012 Pearson Education, Inc. 0-31 Figure 8.18 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers Copyright © 2012 Pearson Education, Inc. 0-32
  • 17. 17 Manipulating Data Structures • Ideally, a data structure should be manipulated solely by pre definedmanipulated solely by pre-defined procedures. – Example: A stack typically needs at least push and pop procedures. – The data structure along with these procedures constitutes a complete abstract Copyright © 2012 Pearson Education, Inc. 0-33 procedures constitutes a complete abstract tool. Figure 8.19 A procedure for printing a linked list Copyright © 2012 Pearson Education, Inc. 0-34
  • 18. 18 Case Study Problem: Construct an abstract tool i ti f li t f i l h b ti lconsisting of a list of names in alphabetical order along with the operations search, print, and insert. Copyright © 2012 Pearson Education, Inc. 0-35 Figure 8.20 The letters A through M arranged in an ordered tree Copyright © 2012 Pearson Education, Inc. 0-36
  • 19. 19 Figure 8.21 The binary search as it would appear if the list were implemented as a linked binary tree Copyright © 2012 Pearson Education, Inc. 0-37 Figure 8.22 The successively smaller trees considered by the procedure in Figure 8.18 when searching for the letter J Copyright © 2012 Pearson Education, Inc. 0-38
  • 20. 20 Figure 8.23 Printing a search tree in alphabetical order Copyright © 2012 Pearson Education, Inc. 0-39 Figure 8.24 A procedure for printing the data in a binary tree Copyright © 2012 Pearson Education, Inc. 0-40
  • 21. 21 Figure 8.25 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree Copyright © 2012 Pearson Education, Inc. 0-41 Figure 8.26 A procedure for inserting a new entry in a list stored as a binary tree Copyright © 2012 Pearson Education, Inc. 0-42
  • 22. 22 User-defined Data Type • A template for a heterogeneous structure • Example: define type EmployeeType to be {char Name[25]; int Age; l SkillR ti Copyright © 2012 Pearson Education, Inc. 0-43 real SkillRating; } Abstract Data Type • A user-defined data type with procedures for access and manipulation • Example: define type StackType to be {int StackEntries[20]; int StackPointer = 0; procedure push(value) {StackEntries[StackPointer] ← value; StackPointer ¬ StackPointer + 1; } Copyright © 2012 Pearson Education, Inc. 0-44 } procedure pop . . . }
  • 23. 23 Class • An abstract data type with extra features – Characteristics can be inherited – Contents can be encapsulated – Constructor methods to initialize new objects Copyright © 2012 Pearson Education, Inc. 0-45 Figure 8.27 A stack of integers implemented in Java and C# Copyright © 2012 Pearson Education, Inc. 0-46
  • 24. 24 Pointers in Machine Language • Immediate addressing: Instruction t i th d t t b dcontains the data to be accessed • Direct addressing: Instruction contains the address of the data to be accessed • Indirect addressing: Instruction contains the location of the address of the data to Copyright © 2012 Pearson Education, Inc. 0-47 the location of the address of the data to be accessed Figure 8.28 Our first attempt at expanding the machine language in Appendix C to take advantage of pointers Copyright © 2012 Pearson Education, Inc. 0-48
  • 25. 25 Figure 8.29 Loading a register from a memory cell that is located by means of a pointer stored in a register Copyright © 2012 Pearson Education, Inc. 0-49