1.3.1 Linked List
1.3.1 Linked List
1.3.1 Linked List
LEARNING OUTCOMES
• Students will learn about the linked list data structures, their
advantages over arrays and disadvantages.
• Students can able to do the distinctions between arrays and link
lists.
• Students will learn about Linked lists creations , all types of
insertions and deletions in linked lists.
Linked List
• A Linked List is a linear data structure that consists of two
parts: one is the data part and the other is the address part.
• A list implemented by each item having a link to the next item.
• Linked Lists are used to create trees and graphs.
• Applications Areas
Music and Media Players
Symbol Table Implementation
Task Scheduling in Operating Systems
Browser History
GPS Navigation Systems
REPRESENTATIONS
[1]
Arrays
• have a pre-determined fixed size
• easy access to any element a[i] in constant time
• no space overhead
• Size = n x sizeof(element)
Linked lists
• no fixed size, grow one element at a time.
• space overhead
• each element must store an additional reference
• Size = n x sizeof (element) + n x sizeof(reference)
• no easy access to i-th element wrt the head of the list
• need to hop through all previous elements
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
[1]
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = newData; newNode->data = newData;
newNode->next = head;
newNode->next = header->next;
head = newNode;
header->next = newNode;
return head;
}
}
CONTINUED
INSERT(Info, Link, Start, Avail, Item)
1. Call FINDA(Info, Link, Start, Avail, Item)
2. Call INSLOC(Info, Link, Start, Avail, Item,LOC)
3. Exit
if(position = = 1)
{
temp -> next = head;
return temp;
}
if(curr == NULL)
{
return head;
}
Deletion
• DEL(Info, Link, Start, Avail, LOC, LOCP)
1. If LOCP = NULL, then
Set Start = Link[Start] //Deletes First Node
Else
Set Link[LOCP] = Link[LOC] //Deletes Node N
2. Set Link[LOC] = Avail // Return Deleted
Node to the Avail List
and
Avail = LOC
3. Exit
else
• After moving the head, {
temp = head;
we can free up the head = head->next;
REFERENCES
• https://www.cs.cmu.edu/~adamchik/15-121/lectures/Linked
%20Lists/linked%20lists.html
• https://www.geeksforgeeks.org/data-structures/linked-list/
• https://www.tutorialspoint.com/data_structures_algorithms/lin
ked_list_algorithms.htm
Books Recommended
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series,
Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures
using C and C++”, Prentice Hall of India.
• Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data
Structures and Algorithms”, Addison Wesley.
Thanks