This document discusses linked lists, including what they are, how they work, their memory representation, basic operations like insertion and deletion, and examples of their use. A linked list is a linear data structure where elements are not stored at contiguous memory locations. They are dynamic, allow easy insertion and deletion by updating addresses only, and use memory efficiently. Common types are singly-linked, doubly-linked, and circular linked lists. While slower to access and traverse than arrays, linked lists see widespread use for dynamic data structures and non-linear data structures like graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
12 views14 pages
Link List
This document discusses linked lists, including what they are, how they work, their memory representation, basic operations like insertion and deletion, and examples of their use. A linked list is a linear data structure where elements are not stored at contiguous memory locations. They are dynamic, allow easy insertion and deletion by updating addresses only, and use memory efficiently. Common types are singly-linked, doubly-linked, and circular linked lists. While slower to access and traverse than arrays, linked lists see widespread use for dynamic data structures and non-linear data structures like graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14
Link List
1. What is link list?
2. How link list works? 3. What are the memory representation of LL? 4. How basic operations such as Insertion, deletion works in LL? 5. Java Implementation of LL A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. Why linked list data structure needed? • Dynamic Data structure: The size of memory can be allocated or de- allocated at run time based on the operation insertion or deletion. • Ease of Insertion/Deletion: The insertion and deletion of elements are simpler than arrays since no elements need to be shifted after insertion and deletion, Just the address needed to be updated. • Efficient Memory Utilization: As we know Linked List is a dynamic data structure the size increases or decreases as per the requirement so this avoids the wastage of memory. • Implementation: Various advanced data structures can be implemented using a linked list like a stack, queue, graph, hash maps, etc. Types of linked lists: class LinkedList { 1. Singly-linked list Node head; // head of list
/* Node Class */ class Node { int data; Node next;
// Constructor to create a new node
Node(int d) { data = d; next = null; } } } public class DLL { 2. Doubly linked list Node head; // head of list
/* Doubly Linked list Node*/
class Node { int data; Node prev; Node next;
// Constructor to create a new node
// next and prev is by default initialized as null Node(int d) { data = d; } } } 3. Circular linked lists Disadvantages of Linked Lists: • Memory usage: The use of pointers is more in linked lists hence, complex and requires more memory. • Accessing a node: Random access is not possible due to dynamic memory allocation. • Search operation costly: Searching for an element is costly and requires O(n) time complexity. • Traversing in reverse order: Traversing is more time-consuming and reverse traversing is not possible in singly linked lists. Applications of Linked List: • Linear data structures such as stack, queue, and non-linear data structures such as hash maps, and graphs can be implemented using linked lists. • Dynamic memory allocation: We use a linked list of free blocks. • Implementation of graphs: Adjacency list representation of graphs is the most popular in that it uses linked lists to store adjacent vertices. • In web browsers and editors, doubly linked lists can be used to build a forwards and backward navigation button. • A circular doubly linked list can also be used for implementing data structures like Fibonacci heaps. Applications of Linked Lists in real world: • The list of songs in the music player is linked to the previous and next songs. • In a web browser, previous and next web page URLs are linked through the previous and next buttons. • In the image viewer, the previous and next images are linked with the help of the previous and next buttons. • Switching between two applications is carried out by using “alt+tab” in windows and “cmd+tab” in mac book. It requires the functionality of a circular linked list. • In mobile phones, we save the contacts of people. The newly entered contact details will be placed at the correct alphabetical order. • This can be achieved by a linked list to set contact at the correct alphabetical position. • The modifications that we made in the documents are actually created as nodes in doubly linked list. We can simply use the undo option by pressing Ctrl+Z to modify the contents. It is done by the functionality of a linked list. Programming Task: Traversing • Implementing a linked list in JAVA Programming Task: Inserting Programming Task: Removing Programming Task: Sorting Programming Task: Merging