Unit - I Linear Data Structures - List: Elavarasi.K Ap/Cse S.A Engineering College
Unit - I Linear Data Structures - List: Elavarasi.K Ap/Cse S.A Engineering College
Elavarasi.K
AP/CSE
S.A Engineering College
• Thus, the array and record data structures are based on computing the
addresses of data items with arithmetic operations
• What is Program?
• A Set of Instructions
Data Structures + Algorithms
Data Structure = A Container stores Data
Algorithm = Logic + Control
06-06-2018 CS8351 - DATA STRUCTURES 2
• Data Structure
• Data: are simply a value are set of values of different type which is called data
types like string, integer, char etc.
• Structure: Way of organizing information, so that it is easier to use
• Data Structure ..
• A data structure is a particular way of organizing data in a computer so that it
can be used efficiently.
• A scheme for organizing related pieces of information.
Lists are a basic example of containers, as they contain other values. If the same
value occurs multiple times, each occurrence is considered a distinct item.
LIST ADT
And if we want to insert a new ID 1005, then to maintain the sorted order, we
have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques
are used. For example, to delete 1010 in id[], everything after 1010 has to be
moved.
• Advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
• Drawbacks:
1) Random access is not allowed. We have to access elements sequentially
starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the
list.
06-06-2018 CS8351 - DATA STRUCTURES 21
Representation in C:
A linked list is represented by a pointer to the first node of the linked
list. The first node is called head. If the linked list is empty, then value
of head is NULL.
CODING
CODING
CODING
CODING
• Lists also form the basis for other abstract data types including the
queue, the stack, and their variations.
• P(x) = 4x3+6x2+7x+9
Representation
struct polynode {
int coef;
int exp;
struct polynode * next; coef exp next
};
• save space (don’t have to worry about sparse polynomials) and easy to
maintain
• don’t need to allocate list size and can declare nodes (terms) only as needed