Data Structures-Linked list memory allocation and its types
Note: if you have downloaded it in .pdf, convert it to .pptx and press F5 for animation.
Size: 1.17 MB
Language: en
Added: Sep 23, 2022
Slides: 21 pages
Slide Content
1.Memory allocation of Array and Linked list 2.Types of Linked list Data Structures- 1.Introduction to Linked List Santhiya S Assistant Professor Department of AI Kongu Engineering College
How Variable X gets stored in memory location? How array gets stored in same memory location?
If user want to extend the size of array to 50. There is no space after address 111 So memory manager has to allocate new 200 bytes for array of size 50. Memory manager may allocate new 200 bytes from 120 to 319 Already created 12 bytes get wasted . This is said to be wastage of space in array Element can be accessed randomly in array if base address is known Access data=base address+ index*(size of data type) Access at data, i =2, 100+(2*4)=108 Array
How will you access the value 4 in linked list? Linked list store element in random location . Wherever it has sufficient space it allocate memory. No wastage of space occurred in Linked list Store one element in array requires 4 bytes if it is integer type But to Store one element in Linked list requires 8 bytes 4 bytes to store data 4 bytes to stores address of next element Random access is not possible in linked list. Only sequential access is possible in linked list Linked List Data Address Data Address Data Address
Memory representation and linked list null 108 116 104 100 112 120 Data Address Data Address Data Address Data Address Data Address Data Address
100 108 116 100 108 116
add element 10 in linked list null 124 116 100
head pointer
Types of linked list Singly Linked List Doubly Linked List Circular Linked List Doubly Circular Linked List
Singly Linked List Singly list contain two parts Data part Address of next node
Doubly Linked List It has double pointer Doubly list contain three parts Data part 2-address part (Address of next node and previous node) (Pointer to previous node and pointer to next node)
Circular Linked List Variation of singly linked list Singly linked list 1000 2000 3000
Circular Linked List Each element having link to next element and last element is having link to first element in the list
Doubly circular linked list Variation of doubly linked list
void pointer The void pointer in C isĀ a pointer that is not associated with any data types . It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer. In C, malloc () and calloc () functions return void * or generic pointers.