SlideShare a Scribd company logo
1 of 4
Download to read offline
Abstract Data Types
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
(b) Write out a signature, or interface, that defines the operations of a stack ADT.
(c) Consider a string of characters of the form
... (.( ... ).) ...
where ... indicates an arbitrary sequence of characters (except for parentheses),
(.( indicates an arbitrary number (one or more) of opening parentheses, and
similarly ).) indicates an arbitrary number of closing parentheses.
Using only the stack abstraction operations defined above, write pseudocode for
an algorithm that determines, using a stack, whether or not the number of closing
parentheses is the same as the number of opening parentheses.
You may assume the existence of a function read(str,ch) that reads the next character
of string str into ch.
You may also assume that you can invoke a function reportFail, that will cause
termination with failure, and similarly, reportSuccess causes termination with a
success indication.
Further, you may also assume that you can call a function newStack(S) to create
a new empty stack S, and eos(str) that returns false when you reach the end of
the string.
Solution
(a) Explain briefly what is meant by the term abstract data type (ADT). Give two
reasons why use of ADTs is good programming practice.
A data type is a collection of values and a set of operations on those values. That collection and
these operations form a mathematical construct that may be implemented with the use of a
particular hardware or software data structure. The term abstract data type (ADT) refers to the
basic mathematical concept that defines the data type. We have discussed four different
implementations of the list data structure.
In case of implementation of the list with the use of an array, the size of the array gives difficulty
if increased.
To avoid this, we allocate memory dynamically for nodes before connecting these nodes with the
help of pointers.
For this purpose, we made a singly linked list and connected it with the next pointer to make a
chain.
Moving forward is easy but going back is a difficult task.
To overcome this problem, we made a doubly linked list using prev andnext pointers. With the
help of these pointers, we can move forward and backward very easily. Now we face another
problem that the prev pointer of first node and the next pointer of the last node are NULL.
Therefore, we have to be careful in case of NULL pointers. To remove the NULL pointers, we
made the circular link list by connecting the first and last node.
The program employing the list data structure is not concerned with its implementation.
We do not care how the list is being implemented whether through an array, singly linked list,
doubly linked list or circular linked list. It has been witnessed that in these four implementations
of the list, the interface remained the same i.e. it implements the same methods like add, get,
next, start and remove etc.
"This proves that with this encapsulation attained by making a class, we are not concerned with
its internal implementation."
The implementation of these abstract data types can be changed anytime.
These abstract data types are implemented using classes in C++.
If the list is implemented using arrays while not fulfilling the requirements, we can change the
list implementation. It can be implemented with the use of singly-link list or doubly link list.
As long as the interface is same, a programmer can change the internal implementation of the list
and the program using this list will not be affected at all. This is the abstract data type (ADT).
What benefits can we get with the help of these ADTs and classes? When we develop an ADT or
a class or factory then the users of this factory are independent of how this factory works
internally. Suppose that we have ordered the car factory (car class) to produce a new car and it
replies after a long time. If we ordered the remove method to remove one node and we are
waiting and it keeps on working and working.
(b) Write out a signature, or interface, that defines the operations of a stack ADT.
interface IntStack {
void push(int item); // store an item
int pop(); // retrieve an item
}
// An implementation of IntStack that uses fixed storage.
class FixedStack implements IntStack {
private int stck[];
private int tos;
// allocate and initialize stack
FixedStack(int size) {
stck = new int[size];
tos = -1;
}
// Push an item onto the stack
public void push(int item) {
if(tos==stck.length-1) // use length member
System.out.println("Stack is full.");
else
stck[++tos] = item;
}
// Pop an item from the stack
public int pop() {
if(tos < 0) {
System.out.println("Stack underflow.");
return 0;
}
else
return stck[tos--];
}
}
class test {
public static void main(String args[]) {
FixedStack mystack1 = new FixedStack(5);
FixedStack mystack2 = new FixedStack(8);
// push some numbers onto the stack
for(int i=0; i<5; i++) mystack1.push(i);
for(int i=0; i<8; i++) mystack2.push(i);
// pop those numbers off the stack
System.out.println("Stack in mystack1:");
for(int i=0; i<5; i++)
System.out.println(mystack1.pop());
System.out.println("Stack in mystack2:");
for(int i=0; i<8; i++)
System.out.println(mystack2.pop());
}
}

More Related Content

Similar to Abstract Data Types (a) Explain briefly what is meant by the ter.pdf

1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
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 structureRai University
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptxSajalFayyaz
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdfMemeMiner
 
computer notes - Circular list
computer notes - Circular listcomputer notes - Circular list
computer notes - Circular listecomputernotes
 
C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaManoj Kumar kothagulla
 
Data Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxData Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxR S Anu Prabha
 
computer notes - Linked list inside computer memory
computer notes - Linked list inside computer memorycomputer notes - Linked list inside computer memory
computer notes - Linked list inside computer memoryecomputernotes
 
22827361 ab initio-fa-qs
22827361 ab initio-fa-qs22827361 ab initio-fa-qs
22827361 ab initio-fa-qsCapgemini
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 

Similar to Abstract Data Types (a) Explain briefly what is meant by the ter.pdf (20)

Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
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
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
Data structure
 Data structure Data structure
Data structure
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdf
 
computer notes - Circular list
computer notes - Circular listcomputer notes - Circular list
computer notes - Circular list
 
C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kella
 
Data Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptxData Structure and Algorithms –Introduction.pptx
Data Structure and Algorithms –Introduction.pptx
 
computer notes - Linked list inside computer memory
computer notes - Linked list inside computer memorycomputer notes - Linked list inside computer memory
computer notes - Linked list inside computer memory
 
22827361 ab initio-fa-qs
22827361 ab initio-fa-qs22827361 ab initio-fa-qs
22827361 ab initio-fa-qs
 
A04
A04A04
A04
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
06 linked list
06 linked list06 linked list
06 linked list
 

More from karymadelaneyrenne19

Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdfPart A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdfkarymadelaneyrenne19
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfkarymadelaneyrenne19
 
Is this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdfIs this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdfkarymadelaneyrenne19
 
in the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdfin the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdfkarymadelaneyrenne19
 
In HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdfIn HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdfkarymadelaneyrenne19
 
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdfHow is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdfkarymadelaneyrenne19
 
How do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdfHow do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdfkarymadelaneyrenne19
 
How do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdfHow do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdfkarymadelaneyrenne19
 
Describe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdfDescribe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdfkarymadelaneyrenne19
 
Day care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdfDay care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdfkarymadelaneyrenne19
 
Consider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdfConsider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdfkarymadelaneyrenne19
 
An administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdfAn administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdfkarymadelaneyrenne19
 
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdfBelow is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdfkarymadelaneyrenne19
 
Across the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdfAcross the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdfkarymadelaneyrenne19
 
A linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdfA linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdfkarymadelaneyrenne19
 
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdfkarymadelaneyrenne19
 
With respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdfWith respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdfkarymadelaneyrenne19
 
Why do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdfWhy do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdfkarymadelaneyrenne19
 
When you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdfWhen you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdfkarymadelaneyrenne19
 
What type of rock can be dated with radiometric methodsSolution.pdf
What type of rock can be dated with radiometric methodsSolution.pdfWhat type of rock can be dated with radiometric methodsSolution.pdf
What type of rock can be dated with radiometric methodsSolution.pdfkarymadelaneyrenne19
 

More from karymadelaneyrenne19 (20)

Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdfPart A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
Part A - Lymph Node Structure and FunctionUsing no more than 14 pr.pdf
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
Is this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdfIs this a binomial probability experiment Please give a reason for .pdf
Is this a binomial probability experiment Please give a reason for .pdf
 
in the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdfin the case of the Bacillis strain, why would a young culture be use.pdf
in the case of the Bacillis strain, why would a young culture be use.pdf
 
In HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdfIn HTTP response headers, what is the syntax of most lines (which ar.pdf
In HTTP response headers, what is the syntax of most lines (which ar.pdf
 
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdfHow is the mouth of planaria similar to the proboscis of Nemertean.pdf
How is the mouth of planaria similar to the proboscis of Nemertean.pdf
 
How do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdfHow do you define a species for asexually reproducing organisms; orga.pdf
How do you define a species for asexually reproducing organisms; orga.pdf
 
How do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdfHow do cognitive changes contribute to decision-making during adoles.pdf
How do cognitive changes contribute to decision-making during adoles.pdf
 
Describe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdfDescribe the various types of computer-based information systems in .pdf
Describe the various types of computer-based information systems in .pdf
 
Day care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdfDay care centers expose children to a wider variety of germs than th.pdf
Day care centers expose children to a wider variety of germs than th.pdf
 
Consider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdfConsider a two-state paramagnet with a very large number N of elemen.pdf
Consider a two-state paramagnet with a very large number N of elemen.pdf
 
An administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdfAn administrator wishes to force remote access users to connect usin.pdf
An administrator wishes to force remote access users to connect usin.pdf
 
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdfBelow is a quote from Bobby Kennedy on what the Gross National Produ.pdf
Below is a quote from Bobby Kennedy on what the Gross National Produ.pdf
 
Across the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdfAcross the field of human development, “development” is defined as .pdf
Across the field of human development, “development” is defined as .pdf
 
A linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdfA linked list is a linear data structure consisting of a set of nodes.pdf
A linked list is a linear data structure consisting of a set of nodes.pdf
 
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
12. The white “Spirit” black bear, Ursys anerucabys kermodei, differ.pdf
 
With respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdfWith respect to the study of lawWhat is the purpose of discovery.pdf
With respect to the study of lawWhat is the purpose of discovery.pdf
 
Why do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdfWhy do you need proteins to allow ions to cross the cell membrane an.pdf
Why do you need proteins to allow ions to cross the cell membrane an.pdf
 
When you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdfWhen you digest a sample of your protein with Chymotrypsin you get a.pdf
When you digest a sample of your protein with Chymotrypsin you get a.pdf
 
What type of rock can be dated with radiometric methodsSolution.pdf
What type of rock can be dated with radiometric methodsSolution.pdfWhat type of rock can be dated with radiometric methodsSolution.pdf
What type of rock can be dated with radiometric methodsSolution.pdf
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Abstract Data Types (a) Explain briefly what is meant by the ter.pdf

  • 1. Abstract Data Types (a) Explain briefly what is meant by the term abstract data type (ADT). Give two reasons why use of ADTs is good programming practice. (b) Write out a signature, or interface, that defines the operations of a stack ADT. (c) Consider a string of characters of the form ... (.( ... ).) ... where ... indicates an arbitrary sequence of characters (except for parentheses), (.( indicates an arbitrary number (one or more) of opening parentheses, and similarly ).) indicates an arbitrary number of closing parentheses. Using only the stack abstraction operations defined above, write pseudocode for an algorithm that determines, using a stack, whether or not the number of closing parentheses is the same as the number of opening parentheses. You may assume the existence of a function read(str,ch) that reads the next character of string str into ch. You may also assume that you can invoke a function reportFail, that will cause termination with failure, and similarly, reportSuccess causes termination with a success indication. Further, you may also assume that you can call a function newStack(S) to create a new empty stack S, and eos(str) that returns false when you reach the end of the string. Solution (a) Explain briefly what is meant by the term abstract data type (ADT). Give two reasons why use of ADTs is good programming practice. A data type is a collection of values and a set of operations on those values. That collection and these operations form a mathematical construct that may be implemented with the use of a particular hardware or software data structure. The term abstract data type (ADT) refers to the basic mathematical concept that defines the data type. We have discussed four different implementations of the list data structure. In case of implementation of the list with the use of an array, the size of the array gives difficulty if increased.
  • 2. To avoid this, we allocate memory dynamically for nodes before connecting these nodes with the help of pointers. For this purpose, we made a singly linked list and connected it with the next pointer to make a chain. Moving forward is easy but going back is a difficult task. To overcome this problem, we made a doubly linked list using prev andnext pointers. With the help of these pointers, we can move forward and backward very easily. Now we face another problem that the prev pointer of first node and the next pointer of the last node are NULL. Therefore, we have to be careful in case of NULL pointers. To remove the NULL pointers, we made the circular link list by connecting the first and last node. The program employing the list data structure is not concerned with its implementation. We do not care how the list is being implemented whether through an array, singly linked list, doubly linked list or circular linked list. It has been witnessed that in these four implementations of the list, the interface remained the same i.e. it implements the same methods like add, get, next, start and remove etc. "This proves that with this encapsulation attained by making a class, we are not concerned with its internal implementation." The implementation of these abstract data types can be changed anytime. These abstract data types are implemented using classes in C++. If the list is implemented using arrays while not fulfilling the requirements, we can change the list implementation. It can be implemented with the use of singly-link list or doubly link list. As long as the interface is same, a programmer can change the internal implementation of the list and the program using this list will not be affected at all. This is the abstract data type (ADT). What benefits can we get with the help of these ADTs and classes? When we develop an ADT or a class or factory then the users of this factory are independent of how this factory works internally. Suppose that we have ordered the car factory (car class) to produce a new car and it replies after a long time. If we ordered the remove method to remove one node and we are waiting and it keeps on working and working. (b) Write out a signature, or interface, that defines the operations of a stack ADT. interface IntStack { void push(int item); // store an item int pop(); // retrieve an item } // An implementation of IntStack that uses fixed storage. class FixedStack implements IntStack { private int stck[];
  • 3. private int tos; // allocate and initialize stack FixedStack(int size) { stck = new int[size]; tos = -1; } // Push an item onto the stack public void push(int item) { if(tos==stck.length-1) // use length member System.out.println("Stack is full."); else stck[++tos] = item; } // Pop an item from the stack public int pop() { if(tos < 0) { System.out.println("Stack underflow."); return 0; } else return stck[tos--]; } } class test { public static void main(String args[]) { FixedStack mystack1 = new FixedStack(5); FixedStack mystack2 = new FixedStack(8); // push some numbers onto the stack for(int i=0; i<5; i++) mystack1.push(i); for(int i=0; i<8; i++) mystack2.push(i); // pop those numbers off the stack System.out.println("Stack in mystack1:"); for(int i=0; i<5; i++) System.out.println(mystack1.pop()); System.out.println("Stack in mystack2:"); for(int i=0; i<8; i++)