Docsity

Linked Lists: Advantages, Disadvantages, and Operations, Slides of Data Structures and Algorithms

Partial preview of the text

Download Linked Lists: Advantages, Disadvantages, and Operations and more Slides Data Structures and Algorithms in PDF only on Docsity!

List Operations

Advantages of Linked Lists

  • The advantages of linked lists include:
    • Overflow can never occur unless the memory

is actually full.

  • Insertions and deletions are

easier

than for

contiguous (array) lists.

  • With large records, moving pointers is easier

and faster than moving the items themselves.

Linked List Operations

List Operations

  • Basic Operations on a Linked List are
    • Insertion– Deletion
      • Other operations include
        • build list– Append and prepend (special cases of insert)– empty– length– toString– traversing

Insertion

  • Two cases to consider
    • List is empty
      • Insert to the beginning of the list
        • List is non-empty
          • Locate the place to insert• Manipulate the references to make new links

head

Insert Operation

P

New node

Other Operations

Prepend

head

New node

Insert to the beginning of the list

null

Length

head

Insert to the end of the list

null

List Types

Inserting into a Doubly Linked List

  • We have to manipulate both next and previous pointers. Insert new node Nbetween P and Q Node P Node Q Node R
Node
N

Deleting from a Doubly Linked List

  • Write the code to delete Node Q Node P Node Q Node R

Make it a Circular Doubly Linked List

  • Write the code to create a circular doubly linked list.

Multi Linked List - An

Example