SlideShare a Scribd company logo
12.1
1212
AbstractAbstract
Data TypesData Types
Foundations of Computer Science © Cengage
Learning
12.2
12-1 BACKGROUND12-1 BACKGROUND
Problem solving with a computer means processingProblem solving with a computer means processing
data. To process data, we need to define the data typedata. To process data, we need to define the data type
and the operation to be performed on the data. Theand the operation to be performed on the data. The
definition of the data type and the definition of thedefinition of the data type and the definition of the
operation to be applied to the data is part of the ideaoperation to be applied to the data is part of the idea
behind anbehind an abstract data type (ADT)abstract data type (ADT)—to hide how the—to hide how the
operation is performed on the data. In other words, theoperation is performed on the data. In other words, the
user of an ADT needs only to know that a set ofuser of an ADT needs only to know that a set of
operations are available for the data type, but does notoperations are available for the data type, but does not
need to know how they are applied.need to know how they are applied.
12.3
Simple ADTs
Many programming languages already define some simple
ADTs as integral parts of the language. For example, the C
language defines a simple ADT as an integer. The type of
this ADT is an integer with predefined ranges. C also defines
several operations that can be applied to this data type
(addition, subtraction, multiplication, division and so on). C
explicitly defines these operations on integers and what we
expect as the results. A programmer who writes a C program
to add two integers should know about the integer ADT and
the operations that can be applied to it.
12.4
Complex ADTs
Although several simple ADTs, such as integer, real,
character, pointer and so on, have been implemented and are
available for use in most languages, many useful complex
ADTs are not. As we will see in this chapter, we need a list
ADT, a stack ADT, a queue ADT and so on. To be efficient,
these ADTs should be created and stored in the library of the
computer to be used.
The concept of abstraction means:
1. We know what a data type can do.
2. How it is done is hidden.
i
12.5
Definition
Let us now define an ADT. An abstract data type is a data
type packaged with the operations that are meaningful for the
data type. We then encapsulate the data and the operations
on the data and hide them from the user.
Abstract data type:
1. Definition of data.
2. Definition of operations.
3. Encapsulation of data and operation.
i
12.6
Model for an abstract data type
The ADT model is shown in Figure 12.1. Inside the ADT are
two different parts of the model: data structure and
operations (public and private).
Figure 12.1 The model for an ADT
12.7
Implementation
Computer languages do not provide complex ADT packages.
To create a complex ADT, it is first implemented and kept in
a library. The main purpose of this chapter is to introduce
some common user-defined ADTs and their applications.
However, we also give a brief discussion of each ADT
implementation for the interested reader. We offer the
pseudocode algorithms of the implementations as
challenging exercises.
12.8
12-4 GENERAL LINEAR LISTS12-4 GENERAL LINEAR LISTS
Stacks and queues defined in the two previous sectionsStacks and queues defined in the two previous sections
areare restricted linear listsrestricted linear lists. A. A general linear listgeneral linear list is a listis a list
in which operations, such as insertion and deletion, canin which operations, such as insertion and deletion, can
be done anywhere in the list—at the beginning, in thebe done anywhere in the list—at the beginning, in the
middle or at the end. Figure 12.14 shows a generalmiddle or at the end. Figure 12.14 shows a general
linear list.linear list.
Figure 12.14 General linear list
12.9
Operations on general linear lists
Although we can define many operations on a general linear
list, we discuss only six common operations in this chapter:
list, insert, delete, retrieve, traverse and empty.
The list operation
The list operation creates an empty list. The following shows
the format:
12.10
The insert operation
Since we assume that data in a general linear list is sorted,
insertion must be done in such a way that the ordering of the
elements is maintained. To determine where the element is to
be placed, searching is needed. However, searching is done
at the implementation level, not at the ADT level.
Figure 12.15 The insert operation
12.11
The delete operation
Deletion from a general list (Figure 12.16) also requires that
the list be searched to locate the data to be deleted. After the
location of the data is found, deletion can be done. The
following shows the format:
Figure 12.16 The dequeue operation
12.12
The retrieve operation
By retrieval, we mean access of a single element. Like
insertion and deletion, the general list should be first
searched, and if the data is found, it can be retrieved. The
format of the retrieve operation is:
Figure 12.17 The retrieve operation
12.13
The traverse operation
Each of the previous operations involves a single element in
the list, randomly accessing the list. List traversal, on the
other hand, involves sequential access. It is an operation in
which all elements in the list are processed one by one. The
following shows the format:
The empty operation
The empty operation checks the status of the list. The
following shows the format:
12.14
The empty operation
The empty operation checks the status of the list. The
following shows the format:
This operation returns true if the list is empty, or false if the
list is not empty.
12.15
General linear list ADT
We define a general linear list as an ADT as shown below:
12.16
Example 12.7
Figure 12.18 shows a segment of an algorithm that applies theFigure 12.18 shows a segment of an algorithm that applies the
previously defined operations on a list L. Note that the third andpreviously defined operations on a list L. Note that the third and
fifth operation inserts the new data at the correct position,fifth operation inserts the new data at the correct position,
because the insert operation calls the search algorithm at thebecause the insert operation calls the search algorithm at the
implementation level to find where the new data should beimplementation level to find where the new data should be
inserted. The fourth operation does not delete the item with valueinserted. The fourth operation does not delete the item with value
3 because it is not in the list.3 because it is not in the list.
Figure 12. 18 Example 12.7
12.17
General linear list applications
General linear lists are used in situations in which the
elements are accessed randomly or sequentially. For
example, in a college a linear list can be used to store
information about students who are enrolled in each
semester.
12.18
Example 12.8
Assume that a college has a general linear list that holdsAssume that a college has a general linear list that holds
information about the students and that each data element is ainformation about the students and that each data element is a
record with three fields: ID, Name and Grade. Algorithm 12.4record with three fields: ID, Name and Grade. Algorithm 12.4
shows an algorithm that helps a professor to change the grade forshows an algorithm that helps a professor to change the grade for
a student. The delete operation removes an element from the list,a student. The delete operation removes an element from the list,
but makes it available to the program to allow the grade to bebut makes it available to the program to allow the grade to be
changed. The insert operation inserts the changed element backchanged. The insert operation inserts the changed element back
into the list. The element holds the whole record for the student,into the list. The element holds the whole record for the student,
and the target is the ID used to search the list.and the target is the ID used to search the list.
12.19
Example 12.8 (Continued)(Continued)
12.20
Example 12.9
Continuing with Example 12.8, assume that the tutor wants toContinuing with Example 12.8, assume that the tutor wants to
print the record of all students at the end of the semester.print the record of all students at the end of the semester.
Algorithm 12.5 can do this job. We assume that there is anAlgorithm 12.5 can do this job. We assume that there is an
algorithm called Print that prints the contents of the record. Foralgorithm called Print that prints the contents of the record. For
each node, the list traverse calls the Print algorithm and passeseach node, the list traverse calls the Print algorithm and passes
the data to be printed to it.the data to be printed to it.
12.21
Example 12.9 (Continued)(Continued)
12.22
General linear list implementation
At the ADT level, we use the list and its six operations but at
the implementation level we need to choose a data structure
to implement it. A general list ADT can be implemented
using either an array or a linked list. Figure 12.19 shows an
example of a list ADT with five items. The figure also shows
how we can implement it.
The linked list implementation is similar: we have an extra
node that has the name of the list. This node also has two
fields, a counter and a pointer that points to the first element.
12.23
Figure 12.19 General linear list implementation

More Related Content

What's hot

9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
Kathirvel Ayyaswamy
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
LakshmiSarvani6
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
Gopi Nath
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
LakshmiSarvani6
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
Rai University
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
faran nawaz
 
8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Hoang Nguyen
 
Unit4
Unit4Unit4
Algo>Abstract data type
Algo>Abstract data typeAlgo>Abstract data type
Algo>Abstract data type
Ain-ul-Moiz Khawaja
 

What's hot (19)

9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil12. Heaps - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
 
14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil14. Files - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Unit4
Unit4Unit4
Unit4
 
Algo>Abstract data type
Algo>Abstract data typeAlgo>Abstract data type
Algo>Abstract data type
 

Viewers also liked

AHTS Penguin1 FOR SALE
AHTS Penguin1 FOR SALEAHTS Penguin1 FOR SALE
AHTS Penguin1 FOR SALE
Dorian Schiffer Ltd
 
Remote control based home appliance control system
Remote control based home appliance control systemRemote control based home appliance control system
Remote control based home appliance control system
Jagadeesh Yadav
 
Presentacion eventpadel
Presentacion eventpadelPresentacion eventpadel
Presentacion eventpadel
eventpadel
 
Resume Fall 2016 Calton Zheng
Resume Fall 2016 Calton ZhengResume Fall 2016 Calton Zheng
Resume Fall 2016 Calton Zheng
Calton Zheng
 
types
typestypes
types
Rajendran
 
Modulo a la introduccion
Modulo a la introduccionModulo a la introduccion
Modulo a la introduccion
dianitaca
 
Ashford samariaposter2009
Ashford samariaposter2009Ashford samariaposter2009
Ashford samariaposter2009
SaMaria Hughes
 
Consulta y operación en access
Consulta y operación en accessConsulta y operación en access
Consulta y operación en access
Yeison Muñoz Perez
 
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
Tien Thao
 
Segundo Parcial
Segundo ParcialSegundo Parcial
Segundo Parcial
Monserrat Rivera
 
Casos sin resolver
Casos sin resolverCasos sin resolver
Casos sin resolver
locas0309
 
Management manual for a start up entrepreneur - managing teams and leading ne...
Management manual for a start up entrepreneur - managing teams and leading ne...Management manual for a start up entrepreneur - managing teams and leading ne...
Management manual for a start up entrepreneur - managing teams and leading ne...
Charles Pozzo di Borgo
 
Nanang Sjahrian Nur's Resume
Nanang Sjahrian Nur's ResumeNanang Sjahrian Nur's Resume
Nanang Sjahrian Nur's Resume
Nanang Sjahrian Nur
 
Sponsorship Proposal - Indonesia Human Capital Summit 2016
Sponsorship Proposal - Indonesia Human Capital Summit 2016Sponsorship Proposal - Indonesia Human Capital Summit 2016
Sponsorship Proposal - Indonesia Human Capital Summit 2016
Indonesia Human Capital Summit
 
Ventajas y desventajas de la tecnologia en General
Ventajas y desventajas de la tecnologia en GeneralVentajas y desventajas de la tecnologia en General
Ventajas y desventajas de la tecnologia en General
Breyner Otero
 

Viewers also liked (15)

AHTS Penguin1 FOR SALE
AHTS Penguin1 FOR SALEAHTS Penguin1 FOR SALE
AHTS Penguin1 FOR SALE
 
Remote control based home appliance control system
Remote control based home appliance control systemRemote control based home appliance control system
Remote control based home appliance control system
 
Presentacion eventpadel
Presentacion eventpadelPresentacion eventpadel
Presentacion eventpadel
 
Resume Fall 2016 Calton Zheng
Resume Fall 2016 Calton ZhengResume Fall 2016 Calton Zheng
Resume Fall 2016 Calton Zheng
 
types
typestypes
types
 
Modulo a la introduccion
Modulo a la introduccionModulo a la introduccion
Modulo a la introduccion
 
Ashford samariaposter2009
Ashford samariaposter2009Ashford samariaposter2009
Ashford samariaposter2009
 
Consulta y operación en access
Consulta y operación en accessConsulta y operación en access
Consulta y operación en access
 
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
Công ty tổ chức sự kiện chuyên nghiệp,khánh thành, khai trương, đại hội cổ đô...
 
Segundo Parcial
Segundo ParcialSegundo Parcial
Segundo Parcial
 
Casos sin resolver
Casos sin resolverCasos sin resolver
Casos sin resolver
 
Management manual for a start up entrepreneur - managing teams and leading ne...
Management manual for a start up entrepreneur - managing teams and leading ne...Management manual for a start up entrepreneur - managing teams and leading ne...
Management manual for a start up entrepreneur - managing teams and leading ne...
 
Nanang Sjahrian Nur's Resume
Nanang Sjahrian Nur's ResumeNanang Sjahrian Nur's Resume
Nanang Sjahrian Nur's Resume
 
Sponsorship Proposal - Indonesia Human Capital Summit 2016
Sponsorship Proposal - Indonesia Human Capital Summit 2016Sponsorship Proposal - Indonesia Human Capital Summit 2016
Sponsorship Proposal - Indonesia Human Capital Summit 2016
 
Ventajas y desventajas de la tecnologia en General
Ventajas y desventajas de la tecnologia en GeneralVentajas y desventajas de la tecnologia en General
Ventajas y desventajas de la tecnologia en General
 

Similar to List moderate

January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
Zurich_R_User_Group
 
Lists
ListsLists
Data structure
Data structureData structure
Data structure
Mohd Arif
 
android.ppt
android.pptandroid.ppt
android.ppt
ShivamChaturvedi67
 
Lecture-3.ppt
Lecture-3.pptLecture-3.ppt
Lecture-3.ppt
ShivamChaturvedi67
 
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
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 
Adt
AdtAdt
Adt
MrSaem
 
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
Axmedcarb
 
UNIT II.docx
UNIT II.docxUNIT II.docx
UNIT II.docx
Revathiparamanathan
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
SisayNegash4
 
Data structure
 Data structure Data structure
Data structure
Shahariar limon
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
Ummiya Mohammedi
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
facebookrecovery1
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
Sankhya_Analytics
 
Lec1
Lec1Lec1
Lec1
Lec1Lec1
Lec1
Saad Gabr
 
01VD062009003760042.pdf
01VD062009003760042.pdf01VD062009003760042.pdf
01VD062009003760042.pdf
SunilMatsagar1
 

Similar to List moderate (20)

January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
 
Lists
ListsLists
Lists
 
Data structure
Data structureData structure
Data structure
 
android.ppt
android.pptandroid.ppt
android.ppt
 
Lecture-3.ppt
Lecture-3.pptLecture-3.ppt
Lecture-3.ppt
 
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
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Adt
AdtAdt
Adt
 
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
 
UNIT II.docx
UNIT II.docxUNIT II.docx
UNIT II.docx
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
Data structure
 Data structure Data structure
Data structure
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
 
Lec1
Lec1Lec1
Lec1
 
Lec1
Lec1Lec1
Lec1
 
01VD062009003760042.pdf
01VD062009003760042.pdf01VD062009003760042.pdf
01VD062009003760042.pdf
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Rajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Rajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Rajendran
 
Red black tree
Red black treeRed black tree
Red black tree
Rajendran
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Rajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Rajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Rajendran
 
Master method
Master method Master method
Master method
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Hash tables
Hash tablesHash tables
Hash tables
Rajendran
 
Lower bound
Lower boundLower bound
Lower bound
Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Rajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Rajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Rajendran
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
computer languages
computer languagescomputer languages
computer languages
Rajendran
 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

List moderate

  • 1. 12.1 1212 AbstractAbstract Data TypesData Types Foundations of Computer Science © Cengage Learning
  • 2. 12.2 12-1 BACKGROUND12-1 BACKGROUND Problem solving with a computer means processingProblem solving with a computer means processing data. To process data, we need to define the data typedata. To process data, we need to define the data type and the operation to be performed on the data. Theand the operation to be performed on the data. The definition of the data type and the definition of thedefinition of the data type and the definition of the operation to be applied to the data is part of the ideaoperation to be applied to the data is part of the idea behind anbehind an abstract data type (ADT)abstract data type (ADT)—to hide how the—to hide how the operation is performed on the data. In other words, theoperation is performed on the data. In other words, the user of an ADT needs only to know that a set ofuser of an ADT needs only to know that a set of operations are available for the data type, but does notoperations are available for the data type, but does not need to know how they are applied.need to know how they are applied.
  • 3. 12.3 Simple ADTs Many programming languages already define some simple ADTs as integral parts of the language. For example, the C language defines a simple ADT as an integer. The type of this ADT is an integer with predefined ranges. C also defines several operations that can be applied to this data type (addition, subtraction, multiplication, division and so on). C explicitly defines these operations on integers and what we expect as the results. A programmer who writes a C program to add two integers should know about the integer ADT and the operations that can be applied to it.
  • 4. 12.4 Complex ADTs Although several simple ADTs, such as integer, real, character, pointer and so on, have been implemented and are available for use in most languages, many useful complex ADTs are not. As we will see in this chapter, we need a list ADT, a stack ADT, a queue ADT and so on. To be efficient, these ADTs should be created and stored in the library of the computer to be used. The concept of abstraction means: 1. We know what a data type can do. 2. How it is done is hidden. i
  • 5. 12.5 Definition Let us now define an ADT. An abstract data type is a data type packaged with the operations that are meaningful for the data type. We then encapsulate the data and the operations on the data and hide them from the user. Abstract data type: 1. Definition of data. 2. Definition of operations. 3. Encapsulation of data and operation. i
  • 6. 12.6 Model for an abstract data type The ADT model is shown in Figure 12.1. Inside the ADT are two different parts of the model: data structure and operations (public and private). Figure 12.1 The model for an ADT
  • 7. 12.7 Implementation Computer languages do not provide complex ADT packages. To create a complex ADT, it is first implemented and kept in a library. The main purpose of this chapter is to introduce some common user-defined ADTs and their applications. However, we also give a brief discussion of each ADT implementation for the interested reader. We offer the pseudocode algorithms of the implementations as challenging exercises.
  • 8. 12.8 12-4 GENERAL LINEAR LISTS12-4 GENERAL LINEAR LISTS Stacks and queues defined in the two previous sectionsStacks and queues defined in the two previous sections areare restricted linear listsrestricted linear lists. A. A general linear listgeneral linear list is a listis a list in which operations, such as insertion and deletion, canin which operations, such as insertion and deletion, can be done anywhere in the list—at the beginning, in thebe done anywhere in the list—at the beginning, in the middle or at the end. Figure 12.14 shows a generalmiddle or at the end. Figure 12.14 shows a general linear list.linear list. Figure 12.14 General linear list
  • 9. 12.9 Operations on general linear lists Although we can define many operations on a general linear list, we discuss only six common operations in this chapter: list, insert, delete, retrieve, traverse and empty. The list operation The list operation creates an empty list. The following shows the format:
  • 10. 12.10 The insert operation Since we assume that data in a general linear list is sorted, insertion must be done in such a way that the ordering of the elements is maintained. To determine where the element is to be placed, searching is needed. However, searching is done at the implementation level, not at the ADT level. Figure 12.15 The insert operation
  • 11. 12.11 The delete operation Deletion from a general list (Figure 12.16) also requires that the list be searched to locate the data to be deleted. After the location of the data is found, deletion can be done. The following shows the format: Figure 12.16 The dequeue operation
  • 12. 12.12 The retrieve operation By retrieval, we mean access of a single element. Like insertion and deletion, the general list should be first searched, and if the data is found, it can be retrieved. The format of the retrieve operation is: Figure 12.17 The retrieve operation
  • 13. 12.13 The traverse operation Each of the previous operations involves a single element in the list, randomly accessing the list. List traversal, on the other hand, involves sequential access. It is an operation in which all elements in the list are processed one by one. The following shows the format: The empty operation The empty operation checks the status of the list. The following shows the format:
  • 14. 12.14 The empty operation The empty operation checks the status of the list. The following shows the format: This operation returns true if the list is empty, or false if the list is not empty.
  • 15. 12.15 General linear list ADT We define a general linear list as an ADT as shown below:
  • 16. 12.16 Example 12.7 Figure 12.18 shows a segment of an algorithm that applies theFigure 12.18 shows a segment of an algorithm that applies the previously defined operations on a list L. Note that the third andpreviously defined operations on a list L. Note that the third and fifth operation inserts the new data at the correct position,fifth operation inserts the new data at the correct position, because the insert operation calls the search algorithm at thebecause the insert operation calls the search algorithm at the implementation level to find where the new data should beimplementation level to find where the new data should be inserted. The fourth operation does not delete the item with valueinserted. The fourth operation does not delete the item with value 3 because it is not in the list.3 because it is not in the list. Figure 12. 18 Example 12.7
  • 17. 12.17 General linear list applications General linear lists are used in situations in which the elements are accessed randomly or sequentially. For example, in a college a linear list can be used to store information about students who are enrolled in each semester.
  • 18. 12.18 Example 12.8 Assume that a college has a general linear list that holdsAssume that a college has a general linear list that holds information about the students and that each data element is ainformation about the students and that each data element is a record with three fields: ID, Name and Grade. Algorithm 12.4record with three fields: ID, Name and Grade. Algorithm 12.4 shows an algorithm that helps a professor to change the grade forshows an algorithm that helps a professor to change the grade for a student. The delete operation removes an element from the list,a student. The delete operation removes an element from the list, but makes it available to the program to allow the grade to bebut makes it available to the program to allow the grade to be changed. The insert operation inserts the changed element backchanged. The insert operation inserts the changed element back into the list. The element holds the whole record for the student,into the list. The element holds the whole record for the student, and the target is the ID used to search the list.and the target is the ID used to search the list.
  • 20. 12.20 Example 12.9 Continuing with Example 12.8, assume that the tutor wants toContinuing with Example 12.8, assume that the tutor wants to print the record of all students at the end of the semester.print the record of all students at the end of the semester. Algorithm 12.5 can do this job. We assume that there is anAlgorithm 12.5 can do this job. We assume that there is an algorithm called Print that prints the contents of the record. Foralgorithm called Print that prints the contents of the record. For each node, the list traverse calls the Print algorithm and passeseach node, the list traverse calls the Print algorithm and passes the data to be printed to it.the data to be printed to it.
  • 22. 12.22 General linear list implementation At the ADT level, we use the list and its six operations but at the implementation level we need to choose a data structure to implement it. A general list ADT can be implemented using either an array or a linked list. Figure 12.19 shows an example of a list ADT with five items. The figure also shows how we can implement it. The linked list implementation is similar: we have an extra node that has the name of the list. This node also has two fields, a counter and a pointer that points to the first element.
  • 23. 12.23 Figure 12.19 General linear list implementation