Introduction of the list

  • A list of multiple elements
  • The elements are stored discontiguously, connected by the next pointer

Two-way linked list

  • Append (push) -o (1)
  • Index access/modify (A[idx]=…) – O(n)
  • Insert -o (1)
  • Delete (delete/remove) -o (1)
  • Merge – O (1)

One-way linked lists (a brief explanation)

  • Header pointer – points to the first node of the list
  • List nodes include key and next Pointers
    • Key can be the address of data or satellite data
    • The next pointer points to the next linked list node

Internal nodes

The program said

Inserts elements into an empty list

  1. Create an empty linked list with HEAD pointing to null

const list = new LinkedList()

Const node = new ListNode(1) const node = new ListNode(1)

3. Run the HEAD pointer to the node list. HEAD = node

4. Insert data node 2 to data node 1

  • Create a node that contains data 2

const node2 = new ListNode(2)

  • Place the next pointer on node 2 to node 1

node2.next = node

  • Adjust the HEAD pointer to node 2

list.head = node2

Insert method

Find node O(n) in the linked list

If node 2 is known, delete node 2

Two-way linked list

The program said

The bidirectional list removes element 2

Other problems

  • Insertion of bidirectional linked lists -o (1)
  • Index of bidirectional linked list – O(n)
  • Combination of bidirectional lists -o (m + n)