This document discusses lists and their implementation. It describes static and dynamic lists, with static lists having fixed size and storing elements in an array, while dynamic lists can grow and shrink as nodes are linked together. It also covers array implementation of lists, including how to insert and delete nodes at a given position. Operations on static lists have complexity related to list size, while dynamic lists can grow and shrink as needed. The document also discusses using a list to implement a linear queue, with insertion only at the rear and deletion only at the front.
Call Girls Delhi {Jodhpur} 9711199012 high profile service
List Data Structure: Static, Dynamic, Array Implementation
1. Chapter 3
List
2.1 Introduction to List
List is a sequential data structure in which addition and removal
of data items can be done from any position. List is a collection
of nodes.
2.2 Static and Dynamic List
Static implementation of list stores the items in an array. The
position of element is given by an index starting with 0 to n-1,
where n is the number of elements. Static list is of fixed size.
The different operations within the static list and their
complexities are as follows:
1. Given an index, the element at that position can be
accessed at constant time, without any relation with the size
of list.
2. To add an element at the end of the list, it can also be done
at constant time. To add an element at any other position
involves shifting up one position of all the subsequent
elements, so the time complexity depends on the size of the
list.
3. To remove an element from the list, all the subsequent
elements should be shifted down one position, so the time
complexity depends on the size of the list.
2. Dynamic implementation of list is stored as a sequence of linked
nodes. Each node in the linked list contains data and reference to
the next node. This type of list can grow and shrink as needed.
2.3 Array Implementation of List
Suppose a list of fixed size N i.e index ranges from 0 to N-1.
2.3.1 Insertion of Node at kth
position
1. If (k >= N) :
a) Display “List index out of range”
2. Else :
a) Initialize i = N-1
b) list[i] = list[i-1]
c) Decrement i by 1
d) If (i == k) :
i) list[i] = item
e) Else :
i) Repeat from step 2(b)
3. Stop
2.3.2 Deletion of Node at kth
position
1. If (k >= N):
a) Display “List index out of range”
2. Else :
a) Initialize i = k
b) list[i] = list[i+1]
c) Increment i by 1
d) Repeat until i >= N-1
3. Stop
2.3.3 Advantages of Array Implementation
1. Variables are stored in contiguous memory.
2. Easy to handle data
3. 2.3.4 Limitations of Array Implementation
1. Hard to add/remove elements
2. Can not be dynamically resized
3. Memory loss
2.4 Implementation of Linear Queue as a List
Consider a list of size N. To implement a linear queue using this
list, we need to establish two variables : front and rear.
The insertion of node to list is restricted from rear end only. So,
during insertion, the given element is inserted at the position that
is one step up of rear.
The algorithm is given as :
1. If (rear == N-1) :
a) Display “Queue is full”
2. Else :
a) If (front == rear == -1) :
i) front = 0
ii) rear = 0
iii) queue_list[rear] = item
b) Else :
i) rear = rear + 1
ii) queue_list[rear] = item
3. Stop
The deletion of node to list is restricted from front end only. So,
during deletion, the element at front position is removed and all
the subsequent elements are shifted down one position.
The algorithm is given as :
1. If (front == -1) :
a) Display “Queue is empty”
4. 2. Else :
a) Item = queue_list[front]
b) If (front == rear) :
i) front = -1
ii) rear = -1
c) Else :
i) Initialize i = rear
ii) queue_list[i-1] = queue_list[i]
iii) Decrement i
iv) Repeat from step 2(c) (ii) until i = front
3. Stop