Ch 2Free

Basics of Linked list 17-22

🎓 Vardhman Mahaveer Open University📖 SLM - Data Structures and Algorithms📖 6 notes⏱️ ~9 min

Basics of Linked list 17-22Study Notes

NCERT-aligned · 6 notes · 3 shown free

17. Introduction to Linked Lists

Explanation

17. Introduction to Linked Lists

Linked lists are a fundamental data structure in computer science, used to store collections of elements. Unlike arrays, linked lists do not require contiguous memory allocation. Each element in a linked list is called a node, and each node contains two parts: the data and a reference (or pointer) to the next node in the sequence. This structure allows for efficient insertion and deletion of elements, especially when compared to arrays, where shifting elements may be necessary. Linked lists are dynamic, meaning their size can change during program execution. They are widely used in situations where the number of elements is unpredictable or when frequent modifications to the collection are required. The basic types of linked lists include singly linked lists, doubly linked lists, and circular linked lists. In this section, we introduce the concept of linked lists, their structure, and their advantages over other data structures.

  • Linked lists store elements in nodes with data and next pointers.
  • They allow dynamic memory allocation and efficient modifications.
  • Nodes are not stored in contiguous memory locations.
  • Linked lists are used when frequent insertions and deletions are needed.
  • Types include singly, doubly, and circular linked lists.
  • Linked lists overcome limitations of arrays regarding size and memory.
  • 📌 Node: Basic unit of a linked list containing data and a pointer.
  • 📌 Pointer: Reference to the next node in the list.
  • 📌 Dynamic memory allocation: Allocation of memory at runtime.

18. Types of Linked Lists

Concept

18. Types of Linked Lists

Linked lists come in various forms, each suited to specific applications. The main types are singly linked lists, doubly linked lists, and circular linked lists. In a singly linked list, each node contains data and a pointer to the next node. This allows traversal in one direction. In a doubly linked list, each node has two pointers: one to the next node and one to the previous node, enabling bidirectional traversal. Circular linked lists are variations where the last node points back to the first node, forming a loop. These types offer different advantages and limitations. For example, doubly linked lists facilitate easier deletion of nodes, while circular linked lists are useful in applications requiring repeated traversal, such as round-robin scheduling. Understanding the types of linked lists is crucial for selecting the appropriate structure for a given problem.

  • Singly linked lists allow traversal in one direction.
  • Doubly linked lists support bidirectional traversal.
  • Circular linked lists form a loop by connecting the last node to the first.
  • Each type has unique advantages and use cases.
  • Doubly linked lists simplify node deletion.
  • Circular linked lists are used in applications like scheduling.
  • 📌 Singly linked list: Linked list with nodes pointing to the next node only.
  • 📌 Doubly linked list: Linked list with nodes pointing to both next and previous nodes.
  • 📌 Circular linked list: Linked list where the last node points to the first node.

19. Basic Operations on Linked Lists

Explanation

19. Basic Operations on Linked Lists

Linked lists support several fundamental operations, including insertion, deletion, traversal, searching, and updating. Insertion involves adding a new node at the beginning, end, or a specific position in the list. Deletion removes a node from the l