ADSA UNIT 3 Notes (Part 1)
ADSA UNIT 3 Notes (Part 1)
A type is a collection of values. For example, the Boolean type consists of the
values true and false. The integers also form a type. An integer is a simple
type because its values contain no subparts. A bank account record will typically contain
several pieces of information such as name, address, account number, and account
balance. Such a record is an example of an aggregate type or composite type. A data
item is a piece of information or a record whose value is drawn from a type. A data item is
said to be a member of a type.
A data type is a type together with a collection of operations to manipulate the type. For
example, an integer variable is a member of the integer data type. Addition is an example of
an operation on the integer data type.
A distinction should be made between the logical concept of a data type and its physical
implementation in a computer program. For example, there are two traditional
implementations for the list data type: the linked list and the array-based list. The list data
type can therefore be implemented using a linked list or an array. But we don’t need to know
how the list is implemented when we wish to use a list to help in a more complex design. For
example, a list might be used to help implement a graph data structure.
As another example, the term “array” could refer either to a data type or an implementation.
“Array” is commonly used in computer programming to mean a contiguous block of memory
locations, where each memory location stores one fixed-length data item. By this meaning,
an array is a physical data structure. However, array can also mean a logical data type
composed of a (typically homogeneous) collection of data items, with each data item
identified by an index number. It is possible to implement arrays in many different ways
besides as a block of contiguous memory locations. The sparse matrix refers to a large,
two-dimensional array that stores only a relatively few non-zero values. This is often
implemented with a linked structure, or possibly using a hash table. But it could be
implemented with an interface that uses traditional row and column indices, thus appearing
to the user in the same way that it would if it had been implemented as a block of contiguous
memory locations.
An abstract data type (ADT) is the specification of a data type within some language,
independent of an implementation. The interface for the ADT is defined in terms of a type
and a set of operations on that type. The behavior of each operation is determined by its
inputs and outputs. An ADT does not specify how the data type is implemented. These
implementation details are hidden from the user of the ADT and protected from outside
access, a concept referred to as encapsulation.
The term data structure often refers to data stored in a computer’s main memory. The
related term file structure often refers to the organization of data on peripheral storage,
such as a disk drive or CD.
LIST ADT
Each list element must have some data type. In the simple list implementations discussed in
this chapter, all elements of the list are usually assumed to have the same data type,
although there is no conceptual objection to lists whose elements have differing data types if
the application requires it. The operations defined as part of the list ADT do not depend on
the elemental data type. For example, the list ADT can be used for lists of integers, lists of
characters, lists of payroll records, even lists of lists.
We need some notation to show the contents of a list, so we will use the same angle bracket
notation that is normally used to represent sequences. To be consistent with standard array
indexing, the first position on the list is denoted as 0. Thus, if there are nn elements in the
list, they are given positions 0 through n−1n−1 as ⟨ a0, a1, ..., an−1 ⟩⟨ a0, a1, ..., an−1 ⟩. The
subscript indicates an element’s position within the list. Using this notation, the empty list
would appear as ⟨ ⟩⟨ ⟩.
A list should be able to grow and shrink in size as we insert and remove elements. We
should be able to insert and remove elements from anywhere in the list. We should be able
to gain access to any element’s value, either to read it or to change it. We must be able to
create and clear (or reinitialize) lists. It is also convenient to access the next or previous
element from the “current” one.
we can define the ADT for a list object in terms of a set of operations on that object. We will
use an interface to formally define the list ADT. List defines the member functions that any
list implementation inheriting from it must support, along with their parameters and return
types.
void *DataPtr;
} Node;
typedef struct
int count;
Node *pos;
Node *head;
Node *rear;
} LIST;
The List ADT Functions is given below:
The head node and the data nodes are encapsulated in the
ADT. The calling function can only see the pointer to the stack.
The stack head structure also contains a pointer
to top and count of number of entries currently in stack.
//Stack ADT Type Definitions
void *DataPtr;
} StackNode;
typedef struct
int count;
StackNode *top;
} STACK;
{
void *DataPtr;
} QueueNode;
typedef struct
QueueNode *front;
QueueNode *rear;
int count;
} QUEUE;