SlideShare uma empresa Scribd logo
1 de 48
Chapter 8
Data Abstractions
© 2007 Pearson Addison-Wesley.
All rights reserved
© 2007 Pearson Addison-Wesley. All rights reserved 0-2
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
• 8.6 Pointers in Machine Language
© 2007 Pearson Addison-Wesley. All rights reserved 0-3
Basic Data Structures
• Homogeneous array
• Heterogeneous array
• List
– Stack
– Queue
• Tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-4
Figure 8.1 Lists, stacks, and
queues
© 2007 Pearson Addison-Wesley. All rights reserved 0-5
Terminology for Lists
• List: A collection of data whose entries are
arranged sequentially
• Head: The beginning of the list
• Tail: The end of the list
© 2007 Pearson Addison-Wesley. All rights reserved 0-6
Terminology for Stacks
• Stack: A list in which entries are removed and
inserted only at the head
• LIFO: Last-in-first-out
• Top: The head of list (stack)
• Bottom or base: The tail of list (stack)
• Pop: To remove the entry at the top
• Push: To insert an entry at the top
© 2007 Pearson Addison-Wesley. All rights reserved 0-7
Terminology for Queues
• Queue: A list in which entries are removed at
the head and are inserted at the tail
• FIFO: First-in-first-out
© 2007 Pearson Addison-Wesley. All rights reserved 0-8
Figure 8.2 An example of an
organization chart
© 2007 Pearson Addison-Wesley. All rights reserved 0-9
Terminology for a Tree
• Tree: A collection of data whose entries have 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
© 2007 Pearson Addison-Wesley. All rights reserved 0-10
Terminology for a Tree (continued)
• Parent: The node immediately above a
specified node
• Child: A node immediately below a specified
node
• Ancestor: Parent, parent of parent, etc.
• Descendent: Child, child of child, etc.
• Siblings: Nodes sharing a common parent
© 2007 Pearson Addison-Wesley. All rights reserved 0-11
Terminology for a Tree (continued)
• Binary tree: A tree in which every node has at
most two children
• Depth: The number of nodes in longest path
from root to leaf
© 2007 Pearson Addison-Wesley. All rights reserved 0-12
Figure 8.3 Tree terminology
© 2007 Pearson Addison-Wesley. All rights reserved 0-13
Additional Concepts
• Static Data Structures: Size and shape of data
structure does not change
• Dynamic Data Structures: Size and shape of
data structure can change
• Pointers: Used to locate data
© 2007 Pearson Addison-Wesley. All rights reserved 0-14
Figure 8.4 Novels arranged by
title but linked according to
authorship
© 2007 Pearson Addison-Wesley. All rights reserved 0-15
Storing Arrays
• Homogeneous arrays
– Row-major order versus column major order
– Address polynomial
• Heterogeneous arrays
– Components can be stored one after the other in a
contiguous block
– Components can be stored in separate locations
identified by pointers
© 2007 Pearson Addison-Wesley. All rights reserved 0-16
Figure 8.5 The array of
temperature readings stored in
memory starting at address x
© 2007 Pearson Addison-Wesley. All rights reserved 0-17
Figure 8.6 A two-dimensional array
with four rows and five columns stored
in row major order
© 2007 Pearson Addison-Wesley. All rights reserved 0-18
Figure 8.7 Storing the heterogeneous
array Employee
© 2007 Pearson Addison-Wesley. All rights reserved 0-19
Storing Lists
• Contiguous list: List stored in a homogeneous
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
indicate end of list
© 2007 Pearson Addison-Wesley. All rights reserved 0-20
Figure 8.8 Names stored in
memory as a contiguous list
© 2007 Pearson Addison-Wesley. All rights reserved 0-21
Figure 8.9 The structure of a
linked list
© 2007 Pearson Addison-Wesley. All rights reserved 0-22
Figure 8.10 Deleting an entry
from a linked list
© 2007 Pearson Addison-Wesley. All rights reserved 0-23
Figure 8.11 Inserting an entry
into a linked list
© 2007 Pearson Addison-Wesley. All rights reserved 0-24
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 allotted
storage space
© 2007 Pearson Addison-Wesley. All rights reserved 0-25
Figure 8.12 A stack in memory
© 2007 Pearson Addison-Wesley. All rights reserved 0-26
Figure 8.13 A queue implementation
with head and tail pointers
© 2007 Pearson Addison-Wesley. All rights reserved 0-27
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]
– A[4],A[5],A[6],A[7] = children of A[2] and A[3]
© 2007 Pearson Addison-Wesley. All rights reserved 0-28
Figure 8.14 The structure of a
node in a binary tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-29
Figure 8.15 The conceptual and
actual organization of a binary tree
using a linked storage system
© 2007 Pearson Addison-Wesley. All rights reserved 0-30
Figure 8.16 A tree stored without
pointers
© 2007 Pearson Addison-Wesley. All rights reserved 0-31
Figure 8.17 A sparse, unbalanced
tree shown in its conceptual form and
as it would be stored without pointers
© 2007 Pearson Addison-Wesley. All rights reserved 0-32
Manipulating Data Structures
• Ideally, a data structure should be manipulated
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 tool.
© 2007 Pearson Addison-Wesley. All rights reserved 0-33
Figure 8.18 A procedure for
printing a linked list
© 2007 Pearson Addison-Wesley. All rights reserved 0-34
Case Study
Problem: Construct an abstract tool consisting of
a list of names in alphabetical order along with
the operations search, print, and insert.
© 2007 Pearson Addison-Wesley. All rights reserved 0-35
Figure 8.19 The letters A
through M arranged in an
ordered tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-36
Figure 8.20 The binary search as
it would appear if the list were
implemented as a linked binary tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-37
Figure 8.21 The successively smaller trees
considered by the procedure in Figure
8.18 when searching for the letter J
© 2007 Pearson Addison-Wesley. All rights reserved 0-38
Figure 8.22 Printing a search tree
in alphabetical order
© 2007 Pearson Addison-Wesley. All rights reserved 0-39
Figure 8.23 A procedure for
printing the data in a binary tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-40
Figure 8.24 Inserting the entry
M into the list B, E, G, H, J, K, N, P
stored as a tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-41
Figure 8.25 A procedure for
inserting a new entry in a list
stored as a binary tree
© 2007 Pearson Addison-Wesley. All rights reserved 0-42
User-defined Data Type
• A template for a heterogeneous structure
• Example:
define type EmployeeType to be
{char Name[25];
int Age;
real SkillRating;
}
© 2007 Pearson Addison-Wesley. All rights reserved 0-43
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;
}
procedure pop . . .
}
© 2007 Pearson Addison-Wesley. All rights reserved 0-44
Class
• An abstract data type with extra features
– Characteristics can be inherited
– Contents can be encapsulated
– Constructor methods to initialize new objects
© 2007 Pearson Addison-Wesley. All rights reserved 0-45
Figure 8.26 A stack of integers
implemented in Java and C#
© 2007 Pearson Addison-Wesley. All rights reserved 0-46
Pointers in Machine Language
• Immediate addressing: Instruction contains
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 be
accessed
© 2007 Pearson Addison-Wesley. All rights reserved 0-47
Figure 8.27 Our first attempt at expanding
the machine language in Appendix C to take
advantage of pointers
© 2007 Pearson Addison-Wesley. All rights reserved 0-48
Figure 8.28 Loading a register from a
memory cell that is located by means
of a pointer stored in a register

Mais conteúdo relacionado

Destaque

Pelichet mobility solutions (presentation in english)
Pelichet mobility solutions (presentation in english)Pelichet mobility solutions (presentation in english)
Pelichet mobility solutions (presentation in english)
pierrejeronimo
 
Presentación Webprendedor Desarrollo
Presentación Webprendedor DesarrolloPresentación Webprendedor Desarrollo
Presentación Webprendedor Desarrollo
amigojean
 
Pucca
PuccaPucca
Pucca
john
 
ALSO Company Presentation 2015
ALSO Company Presentation 2015ALSO Company Presentation 2015
ALSO Company Presentation 2015
Ari Rikkilä
 

Destaque (18)

Abstract siop
Abstract siopAbstract siop
Abstract siop
 
Pelichet mobility solutions (presentation in english)
Pelichet mobility solutions (presentation in english)Pelichet mobility solutions (presentation in english)
Pelichet mobility solutions (presentation in english)
 
Presentación Webprendedor Desarrollo
Presentación Webprendedor DesarrolloPresentación Webprendedor Desarrollo
Presentación Webprendedor Desarrollo
 
Agenda Qulturas | Septiembre 2013
Agenda Qulturas | Septiembre 2013Agenda Qulturas | Septiembre 2013
Agenda Qulturas | Septiembre 2013
 
Yakhouba
YakhoubaYakhouba
Yakhouba
 
Severus snape
Severus snapeSeverus snape
Severus snape
 
Punt de Mira
Punt de MiraPunt de Mira
Punt de Mira
 
EWGT 2013 - Bid Price heuristics for unrestricted fare structures in cargo re...
EWGT 2013 - Bid Price heuristics for unrestricted fare structures in cargo re...EWGT 2013 - Bid Price heuristics for unrestricted fare structures in cargo re...
EWGT 2013 - Bid Price heuristics for unrestricted fare structures in cargo re...
 
Webinar Presentation New Story for Earth
Webinar Presentation New Story for Earth Webinar Presentation New Story for Earth
Webinar Presentation New Story for Earth
 
SERVISEG Hoy
SERVISEG HoySERVISEG Hoy
SERVISEG Hoy
 
VI FESTIVAL
VI FESTIVAL VI FESTIVAL
VI FESTIVAL
 
Pucca
PuccaPucca
Pucca
 
ACS Relay for Life GOLF Tournament
ACS Relay for Life GOLF TournamentACS Relay for Life GOLF Tournament
ACS Relay for Life GOLF Tournament
 
Organización de eventos e Internet
Organización de eventos e InternetOrganización de eventos e Internet
Organización de eventos e Internet
 
The Kilmore International School Newsletter 17 2013
The Kilmore International School Newsletter 17 2013The Kilmore International School Newsletter 17 2013
The Kilmore International School Newsletter 17 2013
 
ALSO Company Presentation 2015
ALSO Company Presentation 2015ALSO Company Presentation 2015
ALSO Company Presentation 2015
 
Motor de pagos en línea - Openpay
Motor de pagos en línea - OpenpayMotor de pagos en línea - Openpay
Motor de pagos en línea - Openpay
 
inmunología básica
inmunología básicainmunología básica
inmunología básica
 

Semelhante a Cs ch08 (9)

Chap08 data abstraction
Chap08   data abstractionChap08   data abstraction
Chap08 data abstraction
 
Cso gaddis java_chapter8
Cso gaddis java_chapter8Cso gaddis java_chapter8
Cso gaddis java_chapter8
 
datastructure-201021140600.pptx
datastructure-201021140600.pptxdatastructure-201021140600.pptx
datastructure-201021140600.pptx
 
Data structures - unit 1
Data structures - unit 1Data structures - unit 1
Data structures - unit 1
 
Data Structures
Data StructuresData Structures
Data Structures
 
Cs ch01
Cs ch01Cs ch01
Cs ch01
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
2nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 12nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 1
 
CSCI 4140-AA Pre-Req.ppt
CSCI 4140-AA Pre-Req.pptCSCI 4140-AA Pre-Req.ppt
CSCI 4140-AA Pre-Req.ppt
 

Mais de - (13)

Introduction to computer (shaheen)
Introduction to computer (shaheen)Introduction to computer (shaheen)
Introduction to computer (shaheen)
 
Introduction to computer (boys scout)
Introduction to computer (boys scout)Introduction to computer (boys scout)
Introduction to computer (boys scout)
 
Hci with emotional intelligence
Hci with emotional intelligenceHci with emotional intelligence
Hci with emotional intelligence
 
Surf smart
Surf smartSurf smart
Surf smart
 
Planning presentation
Planning presentationPlanning presentation
Planning presentation
 
Cultural enviroment
Cultural enviromentCultural enviroment
Cultural enviroment
 
Quantitative approach
Quantitative approachQuantitative approach
Quantitative approach
 
Project vlm (al halal meat factory)
Project vlm (al halal meat factory)Project vlm (al halal meat factory)
Project vlm (al halal meat factory)
 
Cs ch06
Cs ch06Cs ch06
Cs ch06
 
Cs ch04
Cs ch04Cs ch04
Cs ch04
 
Cs ch03
Cs ch03Cs ch03
Cs ch03
 
Cs ch02
Cs ch02Cs ch02
Cs ch02
 
Cs ch00
Cs ch00Cs ch00
Cs ch00
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Cs ch08

  • 1. Chapter 8 Data Abstractions © 2007 Pearson Addison-Wesley. All rights reserved
  • 2. © 2007 Pearson Addison-Wesley. All rights reserved 0-2 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 • 8.6 Pointers in Machine Language
  • 3. © 2007 Pearson Addison-Wesley. All rights reserved 0-3 Basic Data Structures • Homogeneous array • Heterogeneous array • List – Stack – Queue • Tree
  • 4. © 2007 Pearson Addison-Wesley. All rights reserved 0-4 Figure 8.1 Lists, stacks, and queues
  • 5. © 2007 Pearson Addison-Wesley. All rights reserved 0-5 Terminology for Lists • List: A collection of data whose entries are arranged sequentially • Head: The beginning of the list • Tail: The end of the list
  • 6. © 2007 Pearson Addison-Wesley. All rights reserved 0-6 Terminology for Stacks • Stack: A list in which entries are removed and inserted only at the head • LIFO: Last-in-first-out • Top: The head of list (stack) • Bottom or base: The tail of list (stack) • Pop: To remove the entry at the top • Push: To insert an entry at the top
  • 7. © 2007 Pearson Addison-Wesley. All rights reserved 0-7 Terminology for Queues • Queue: A list in which entries are removed at the head and are inserted at the tail • FIFO: First-in-first-out
  • 8. © 2007 Pearson Addison-Wesley. All rights reserved 0-8 Figure 8.2 An example of an organization chart
  • 9. © 2007 Pearson Addison-Wesley. All rights reserved 0-9 Terminology for a Tree • Tree: A collection of data whose entries have 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
  • 10. © 2007 Pearson Addison-Wesley. All rights reserved 0-10 Terminology for a Tree (continued) • Parent: The node immediately above a specified node • Child: A node immediately below a specified node • Ancestor: Parent, parent of parent, etc. • Descendent: Child, child of child, etc. • Siblings: Nodes sharing a common parent
  • 11. © 2007 Pearson Addison-Wesley. All rights reserved 0-11 Terminology for a Tree (continued) • Binary tree: A tree in which every node has at most two children • Depth: The number of nodes in longest path from root to leaf
  • 12. © 2007 Pearson Addison-Wesley. All rights reserved 0-12 Figure 8.3 Tree terminology
  • 13. © 2007 Pearson Addison-Wesley. All rights reserved 0-13 Additional Concepts • Static Data Structures: Size and shape of data structure does not change • Dynamic Data Structures: Size and shape of data structure can change • Pointers: Used to locate data
  • 14. © 2007 Pearson Addison-Wesley. All rights reserved 0-14 Figure 8.4 Novels arranged by title but linked according to authorship
  • 15. © 2007 Pearson Addison-Wesley. All rights reserved 0-15 Storing Arrays • Homogeneous arrays – Row-major order versus column major order – Address polynomial • Heterogeneous arrays – Components can be stored one after the other in a contiguous block – Components can be stored in separate locations identified by pointers
  • 16. © 2007 Pearson Addison-Wesley. All rights reserved 0-16 Figure 8.5 The array of temperature readings stored in memory starting at address x
  • 17. © 2007 Pearson Addison-Wesley. All rights reserved 0-17 Figure 8.6 A two-dimensional array with four rows and five columns stored in row major order
  • 18. © 2007 Pearson Addison-Wesley. All rights reserved 0-18 Figure 8.7 Storing the heterogeneous array Employee
  • 19. © 2007 Pearson Addison-Wesley. All rights reserved 0-19 Storing Lists • Contiguous list: List stored in a homogeneous 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 indicate end of list
  • 20. © 2007 Pearson Addison-Wesley. All rights reserved 0-20 Figure 8.8 Names stored in memory as a contiguous list
  • 21. © 2007 Pearson Addison-Wesley. All rights reserved 0-21 Figure 8.9 The structure of a linked list
  • 22. © 2007 Pearson Addison-Wesley. All rights reserved 0-22 Figure 8.10 Deleting an entry from a linked list
  • 23. © 2007 Pearson Addison-Wesley. All rights reserved 0-23 Figure 8.11 Inserting an entry into a linked list
  • 24. © 2007 Pearson Addison-Wesley. All rights reserved 0-24 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 allotted storage space
  • 25. © 2007 Pearson Addison-Wesley. All rights reserved 0-25 Figure 8.12 A stack in memory
  • 26. © 2007 Pearson Addison-Wesley. All rights reserved 0-26 Figure 8.13 A queue implementation with head and tail pointers
  • 27. © 2007 Pearson Addison-Wesley. All rights reserved 0-27 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] – A[4],A[5],A[6],A[7] = children of A[2] and A[3]
  • 28. © 2007 Pearson Addison-Wesley. All rights reserved 0-28 Figure 8.14 The structure of a node in a binary tree
  • 29. © 2007 Pearson Addison-Wesley. All rights reserved 0-29 Figure 8.15 The conceptual and actual organization of a binary tree using a linked storage system
  • 30. © 2007 Pearson Addison-Wesley. All rights reserved 0-30 Figure 8.16 A tree stored without pointers
  • 31. © 2007 Pearson Addison-Wesley. All rights reserved 0-31 Figure 8.17 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers
  • 32. © 2007 Pearson Addison-Wesley. All rights reserved 0-32 Manipulating Data Structures • Ideally, a data structure should be manipulated 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 tool.
  • 33. © 2007 Pearson Addison-Wesley. All rights reserved 0-33 Figure 8.18 A procedure for printing a linked list
  • 34. © 2007 Pearson Addison-Wesley. All rights reserved 0-34 Case Study Problem: Construct an abstract tool consisting of a list of names in alphabetical order along with the operations search, print, and insert.
  • 35. © 2007 Pearson Addison-Wesley. All rights reserved 0-35 Figure 8.19 The letters A through M arranged in an ordered tree
  • 36. © 2007 Pearson Addison-Wesley. All rights reserved 0-36 Figure 8.20 The binary search as it would appear if the list were implemented as a linked binary tree
  • 37. © 2007 Pearson Addison-Wesley. All rights reserved 0-37 Figure 8.21 The successively smaller trees considered by the procedure in Figure 8.18 when searching for the letter J
  • 38. © 2007 Pearson Addison-Wesley. All rights reserved 0-38 Figure 8.22 Printing a search tree in alphabetical order
  • 39. © 2007 Pearson Addison-Wesley. All rights reserved 0-39 Figure 8.23 A procedure for printing the data in a binary tree
  • 40. © 2007 Pearson Addison-Wesley. All rights reserved 0-40 Figure 8.24 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree
  • 41. © 2007 Pearson Addison-Wesley. All rights reserved 0-41 Figure 8.25 A procedure for inserting a new entry in a list stored as a binary tree
  • 42. © 2007 Pearson Addison-Wesley. All rights reserved 0-42 User-defined Data Type • A template for a heterogeneous structure • Example: define type EmployeeType to be {char Name[25]; int Age; real SkillRating; }
  • 43. © 2007 Pearson Addison-Wesley. All rights reserved 0-43 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; } procedure pop . . . }
  • 44. © 2007 Pearson Addison-Wesley. All rights reserved 0-44 Class • An abstract data type with extra features – Characteristics can be inherited – Contents can be encapsulated – Constructor methods to initialize new objects
  • 45. © 2007 Pearson Addison-Wesley. All rights reserved 0-45 Figure 8.26 A stack of integers implemented in Java and C#
  • 46. © 2007 Pearson Addison-Wesley. All rights reserved 0-46 Pointers in Machine Language • Immediate addressing: Instruction contains 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 be accessed
  • 47. © 2007 Pearson Addison-Wesley. All rights reserved 0-47 Figure 8.27 Our first attempt at expanding the machine language in Appendix C to take advantage of pointers
  • 48. © 2007 Pearson Addison-Wesley. All rights reserved 0-48 Figure 8.28 Loading a register from a memory cell that is located by means of a pointer stored in a register