Doubly Linked Lists Flashcards
There are 3 attributes of a DLL node, what are they
T item
DLLNode next
DLLNode prev
If there is only one element in the DLL what will the node look like
Data space is filled
Next is null
Prev is null
What does the first node (head) of a DLL look like
Data
Next points to next node in DLL
Prev is null
What does the last node in a DLL look like
Data
Next is null
Prev points to previous node in the DLL
What does a middle node in a DLL look like
Data
Next points to the next node in the DLL
Prev points to the previous node in the DLL
Steps to insert a node at the end of a DLL
Make a temp node, with data and null prev and next
Connect prev to what used to be tail
Assign tail to new temp node
Steps to insert a node in the middle of a DLL
Find position we want to add at
Make a temp node with data and null prev and next
Change next of previous node to point to temp
Change prev of temp node to point to previous node
Change prev of next node to point to temp node
Change next of temp node to point to next node
Now it is part of the list
benefits of doubly linked lists
can iterate in reverse
can be extended - do not need to know the exact amount of elements needed beforehand
order of growth for searching a doubly linked list
big O (N)
how should nodes be updated to prevent losing access to them
one side at a time
disadvantage of a linked list
must search through entire list before accessing
if searching, it’ll take iterating through the entire list before discovering that an element doesn’t exist in the list
benefits of a linked list
easy to insert anywhere into the list