0% found this document useful (0 votes)
30 views11 pages

Unit 3 Dsa Notes

Uploaded by

renukabhasme03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

Unit 3 Dsa Notes

Uploaded by

renukabhasme03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

UNIT 3: LINKED LIST

Static Memory Allocation:


Static memory allocates at the time of compilation of program and it
can’t be modified after the allocation.
It is sequential, it is assigned as continuous block of memory.
It terminates when the program end.

Dynamic Memory Allocation:


Dynamic memory allocates at the time of running the program and it
can be modified i.e. it can be allocated as well as deallocate.
It is not sequential, it is not assigned as continuous memory location.
It flexible and efficient.

LINKED LIST:

1.Node:
A node is the fundamental building block of a linked list. Each
node contains
●Information field / Data field – it contains data part.
●Next Pointer: - It is self-referencing structure which
contains the Address of next Node to achieve the
behaviour of sequential Ness.
2.Pointer:
Pointer is a variable which contains the address of another
variable.

3.Null Pointer: It is special type of pointer which does not point


to any address that also indicates the end of linked list.

4.Empty List:
It is linked list which does not contains any node.

Types Of Linked List:

● Singly Linked List:

It is liked list which contains the “Information part & the next pointer”.
The list starts from the head node and moves forward sequentially
until the next pointer of a node is NULL, indicating the end of the list.
It only travels in the one direction.

● Doubly Linked List:

It is also type of linked list which contains the “Information part,


Next Pointer & previous pointer”.
It can travel along both directions.

● Circular Linked List


It is type of linked list which contains the next pointer and at the last
node’s next pointer contains the address of first node.

OPERATION BASED ON LINKED LIST:

Traversing a Singly Linked List:

Visiting every node at list once is called as traversing the list.

TRAVERSING (LIST, START, LINK)


STEP 1: SET PTR = START
STEP 2: REPEAT WHILE PTR != NULL
STEP 3: PTR = LINK[PTR]
STEP 4: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
Searching In Singly Linked list:

SEARCHING (LIST, START, PTR, TEMP, INFO, LINK, INFO)


STEP 1: SET PTR=START
STEP 2: REPEAT WHILE PTR != NULL
STEP 3: CHECK IF INFO[PTR]=KEY
PRINT DATA IS FOUND GOTO STEP 5
STEP 4: SET PTR=LINK[PTR]
STEP 5: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
Insertion At Beginning Of The List:

INSERT_AT_BEG (LISR, PTR, KEY, LINK)


STEP 1: IF AVAIL=NULL
PRINT OVERFLOW OF LIST & EXIT
STEP 2: SET NEW =AVAIL AND
AVAIL=LINK[AVAIL]
STEP 3: SET PTR=START
STEP 4: SET INFO[NEW]=KEY
STEP 5: SET LINK[NEW]=PTR
STEP 6: SET PTR =NEW
STEP 7: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
LOC- IT CONTAINS THE ADDRESS OF DESIRED DATA
INFO- IT CONTAINS DATA PART OF NODE
Insertion At Location:

INSERT_AT_LOC (LIST, LOC, AVAIL, LINK, START)


STEP 1: IF AVAIL=NULL
PRINT OVERFLOW OF AVAIL & EXIT
STEP 2: SET NEW =AVAIL
SET AVAIL=LINK[AVAIL]
STEP 3: SET PTR =START
STEP 4: SET LINK[NEW]=LINK[LOC]
STEP 5: SET LINK[LOC]=NEW
STEP 6: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
LOC- IT CONTAINS THE ADDRESS OF DESIRED DATA
Insertion At End:

INSERT_AT_END (LIST, TEMP, PTR, NEW, LINK)


STEP 1: IF AVAIL=NULL
PRINT OVERFLOW AND EXIT
STEP 2: SET NEW = AVAIL
SET AVAIL=LINK[AVAIL]
STEP 3: SET PTR=START
STEP 4: REPEAT WHILE LINK[PTR]=NULL
STEP 5: SET PTR=LINK[PTR]
STEP 6: LINK[PTR]=NEW
STEP 7: LINK[NEW]=NULL
STEP 8: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
TEMP-IT IS ALSO POINTER
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
Deletion At Beginning:

DELETION_AT_BEG (PTR, LIST, TEMP, LINK, STARTS)


STEP 1: SET PTR =START
STEP 2: SET TEMP= PTR
STEP 3: PTR=LINK[PTR]
STEP 4: FREE THE TEMP
STEP 5: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
TEMP-IT IS ALSO POINTER
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
Deletion At Location:

DELETION_AT-LOC (LIST, PTR, LINK, START, LOC)


STEP 1: SET PTR =START
STEP 2: REPEAT WHILE LINK[PTR]= LOC
STEP 3: SET PTR=LINK[PTR] //END OF LOOP
STEP 4: SET TEMP= PTR
STEP 5: SET PTR=LINK[PTR]
STEP 6: FREE TEMP
STEP 7: EXIT

//DESRICPTION
PTR- IT IS A POINTER VARIBLE
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
LOC- IT CONTAINS THE ADDRESS OF DESIRED DATA
Deletion At End:

DELETION_AT_END (LIST, LINK, PTR, START)


STEP 1: SET PTR =START
STEP 2: REPEAT WHILE LINK[PTR]!=NULL
STEP 3: PTR = LINK[PTR] // END OF LOOP
STEP 4: LINK [PTR] = NULL
STEP 5: EXIT

//DESRICPTION
LIST- IT IS LINKED LIST WHICH CONTAINS NODE
START- IT IS A POINTER WHICH CONTAINS THE FIRST NODE
LINK- IT CONTAINS THE NEXT POINTER
PTR- IT IS A POINTER VARIBLE
APLICATIONS OF LINKED LIST:

1. Dynamic Memory Allocation


2. Implementing Stacks and Queues
3. Graphs
4. Handling Polynomial Arithmetic
5. Implementation of Hash Tables
6. Undo Functionality in Software
7. Music or Image Viewer Applications
8. Music or Image Viewer Applications

You might also like