Doubly-LinkedList Flashcards
Is the Doubly LinkedList Random or Sequential Access?
Sequential
What data structure is the Doubly-LinkedList nearly exactly the same as?
The Singly-LinkedList.
What’s the key difference between the Doubly-LinkedList and the Singly-LinkedList? And what benefit does this provide?
It tracks both the next and previous Nodes in the list. This allows you to traverse the list in both directions.
Define the ‘Next’ value of a Node.
That particular Nodes pointer which points to the next object in the list.
Define the ‘Previous’ value of a Node.
That particular Nodes pointer which points to the previous object in the List.
Will the head node have a previous pointer?
No, it will be null.
How do we add to the head of a Doubly-LinkedList? (3)
- Set the new Node’s next to point towards the current head of the list.
- Take the new node that we want to insert, and set it’s previous to null.
- Set the current head’s previous to point towards this new `Node.
How do we REMOVE the head of a Doubly-LinkedList? (2)
- Set the head Node’s next to point towards a null value.
2. Set the second Node’s previous to also point towards a null value.
How do we INSERT into the middle of a Doubly-LinkedList? (3)
- Set the Node’s previous to point to the Node previous to the position you want to insert at.
- Set the new Node’s next to point to the Node after the position you want to insert at.
- Set the next and previous on the Node’s before and after the one you’re inserting to point towards the new Node.
How do we REMOVE from the middle of a Doubly-LinkedList? (3)
- Set the Node before the one we want to remove’s next to point to the Node after the one we want to remove.
- Set the Node after the one we want to remove’s previous to point to the Node before the one we want to remove.
- Set both pointers of the Node we want to remove to point to a null value.
How do we ADD to the tail of a Doubly-LinkedList? (3)
- Set the next pointer of the current tail to point towards the new Node we want to become the tail.
- Set the previous of the new node that we’re adding to be pointing to the current tail of the list.
- Make the new Node’s next point to a null value.
How do we REMOVE from the tail of a Doubly-LinkedList? (2)
- Set the tail Node’s previous to point to null.
2. Set the second to last Node’s next to also point to null.
Are the BigO TimeComplexities of a Doubly-LinkedList the same as those of a Singly-LinkedList?
Yes.
What is the BigO of ACCESSING a Doubly-LinkedList?
O(n) - Linear Search
What is the BigO of SEARCHING a Doubly-LinkedList?
O(n) - Linear Search