Unit 4
Unit 4
150
Theory – 70 ESE + 30 PA
TOTAL MARKS
Practical – 25# ESE + 25
PA
# - External Assessment
3
Course Outcomes:
Syllabus 4
Unit - 01
Introduction to Data Structure
Concept & Need of DS, Abstract Data
1
Type
Types of Data Structure: Linear, Non
2
Linear DS
3 Algorithm Complexity: Time, Space
Operations on DS: Traversing,
4
searching, insertion, deletion, sorting
Syllabus 5
Unit - 02
struct node
{
int data;
A linked list is a series of connected nodes struct node *next;
}
Each node contains at least
A piece of data (any type) node
Array is a collection of elements of similar data Linked List is an ordered collection of elements of
type. same type, which are connected to each other
using pointers.
Size of the array must be specified at time of Size of a Linked list is variable. It grows at runtime,
array declaration as more nodes are added to it.
Array supportsRandom Access, which means Linked List supports Sequential Access, which
elements can be accessed directly using their means to access any element/node in a linked
index, likearr[0]for 1st element,arr[6]for 7th list;we have to sequentially traverse the
element etc. complete linked list, up to that element.
Create a singly linked list using data fields 90, 25, 46, 39,56.
Search a node 40 from the SLL and show procedure step-by-step
with the help of diagram from start to end
SEARCHING A NODE
STEP 1: Compare 40 with 90
40!=90
Inserting a new node in a list 22
In the first case, we make a new node and points its next to
the head of the existing list and then change the head to the
newly added node. It is similar to picture given below.
So, the steps to be followed are as follows:
1) Make a new node
2) Point the ‘next’ of the new node to the ‘head’
of the linked list.
3) Mark new node as ‘head’.
Insertion at the end of the list. 24
The second case is the simplest one. We just add a new node
at the end of the existing list.
It is shown in the picture given below:
So, the steps to add the end if a linked list are:
1) Make a new node
2) Point the last node of the linked list to the new
node
Insertion at the specific location of the list.
25
To insert a node in between a linked list, we need to
first break the existing link and then create two new links.
It will be clear from the picture given below.
The steps for inserting a node after node ‘a’ are:
1) Make a new node
2) Point the ‘next’ of the new node to the node
‘b’ (the node after which we have to insert the
new node). Till now, two nodes are pointing
the same node ‘b’, the node ‘a’ and the new node.
3) Point the ‘next’ of ‘a’ to the new node.
Deleting a node from a linked list 26