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 a.
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++)