ds_exp5
ds_exp5
Software Required:
Python 3
Theory:
Linked List may access its storage in a random fashion, because each piece of information
carries with it a link to the next data, item in the chain. A linked list requires complex data
structure, whereas a stack or queue can operate on both simple and complex data item. A linked-
list retrieval operation does not remove and destroy an item from the list; a specific deletion
operation must be added to do this,
Linked lists are used for two main purpose. The First purpose is to create arrays of unknown size
in memory. If you know the amount of storage in advance, you can use an array; but if you do
not know the actual size of a. list, you must use a linked list. The second main usage is for disk-
file storage of databases. The linked list allows you to insert and delete items quickly and easily
without rearranging- the entire disk file. For these reasons, linked lists are used extensively in
database managers.
Linked lists can be either singly linked or doubly linked, A singly linked list contains a link to
the next data item A doubly linked list contains link to both next and the previous element in the
list The type you use depends upon your application.
Arrays are contiguous: In an array, the elements have to be in a contiguous connected and
sequential) portion of memory. Memory immediately next to the array may already be in use for
something else. So programming languages don't generally provide for arrays that can grow and
shrink in place.
Linked lists are not contiguous: In a linked list, the reference in each node says where to find
the next one. So the nodes can be all over memory.
Implications
With an array, we must choose a size once and for all. (This can waste memory, or we could run
out of spaces).
With a linked list, we can add and remove elements at will. (Each one does take up a little more
space for its link field, and it may take time to `get to' the insertion / removal spot).
With an array, we can immediately access the nth element. With a linked list, we cannot. We
have to follow n references
1. Array is the collection of similar types of 1. Linked list is collection of nodes, which
data elements. In array all the elements are are stored at different memory location. Every
stored in sequential memory location starting node consists of two part.
from index from zero to (n-1).
i. Data
ii. Link
1
Link Stores address of next node.
3
Structure of node.
2
Node
4
Data link
5
1001-1002 a[0]
head
1003-1004 a[1]
1005-1006 a[2]
20 9100 30 null
1007-1008 a[3]
3. No shifting is required.
5. Memory immediately next to the array 7. There is no limitation to create the number
may already be in use for something else. So, of nodes. With a linked list, we can add and
programming languages don't generally remove elements at will. (Each one does take
provide for arrays that can grow and shrink in up a little more space for its link field, and it
place. may take time to `get to' the insertion /
removal spot).
6. In advanced array is created with
specified size
PROCEDURE:
Algorithm: add(data)
1. Create a new node with the data
2. If the linked list is empty (head node is not referring to any other node), make the head node
and the tail node refer to the new node
3. Otherwise,
a. Make the tail node’s link refer to new node
b. Call the new node as tail node
Algorithm: delete(data):
1. Find the node with the given data. If found,
a. If the node to be deleted is head node, make the next node as head node
1. If it is also the tail node, make the tail node as None
b. Otherwise,
1. Traverse till the node before the node to be deleted, call it temp
2. Make temp’s link refer to node’s link.
3. If the node to be deleted is the tail node, call the temp as tail node
4. Make the node's link as None
2. If the node to be deleted is not found, display appropriate error message
CODE:
class Node:
Conclusion:
5 × (1/0)
Factor
performin 5 × (1/0)
Technical Prerequisites
Knowledge Skills in
(Preparedness and experiment g
5 × (1/0)
Execution)
Learning
5 × (1/0)
5 × (1/0)
Technical Format
Documentation
5 × (1/0)
Contents as per format
(Developing skills Quality
for journal writing
and maintenance
of
lab
notebook)
5 × (1/0)
5 × (1/0)
Level of interaction Level of understanding
(Developing
5 × (1/0)
Questions and Answers
expression Application
power)
5 × (1/0)
5 × (1/0)
Behaviour Attitude
al toward Regularity
(Attitude s Team work/ Group 5 × (1/0)
learning) activity
×
Practical Learning 10 (1/0.5/0)
of objectives/
10 × (1/0.5/0)
Outcome 1
outcomes)
Practical Learning
10 × (1/0.5/0)
Outcome 2
Practical Learning
Outcome 3
Total 100
Date of Date of Correction Roll No. Faculty
Performance Signature