Linear Data Structures: Doubly Linked Nodes Flashcards

1
Q

What are the components of a doubly linked node chain?

A
  • A data item
  • A reference to the next node
  • A reference to the previous node

The first node has its ‘previous’ node reference set to null

The last node’s ‘next’ reference is set to null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is the structure of a doubly linked list different from a single-linked node chain?

A

A doubly linked list node has a reference to both its previous node and next node. A single-linked node chain only has a reference to the next node.

The overall structure includes a list object that manages the nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Updates to do doubly-linked node insertion at the beginning

A
  • The new node’s “next” reference is set to the current head node
  • The head reference is updated to point to the new node
  • The previous “head” node’s “previous” reference is updated to point to the new node

The new node’s ‘next’ reference is set to the current head node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Updates to do doubly-linked node insertion at the end

A
  • The current last node’s “next” reference is set to the new node
  • The new node’s “previous” reference is set to the current tail node
  • The tail reference in the list object is updated to point to the new node

The new node’s ‘previous’ reference is set to the current tail node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Updates to do doubly-linked node insertion at the middle

A
  • Update the ‘next’ reference of node before insertion point (P)
  • Update the ‘previous’ reference of node after insertion point (Q)
  • Set new node’s ‘next’ reference to Q
  • Set new node’s ‘previous’ reference to P
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is one disadvantage of doubly linked lists?

A

They use more space than singly linked lists, because of the additional node reference

Each node stores an additional reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are two advantages of doubly linked lists?

A
  • Constant time insertion and deletion at both ends
  • Support for cursors and iterators that can move both forwards and backwards
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can a doubly-linked list improve the time complexity for insertion into the middle list?

A

It can reduce from O(n) to O(1) due to the ability to find the previous node in constant time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does extending the LinkedIterator class for doubly linked lists enable?

A

It enables both forward and backward movement

Methods must be added to support backward movement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly