LinkedList Flashcards
1
Q
What is a linked list?
A
Linked List is a linear data type whose each element is a separate object.
Each element comprises of data, and reference to the next node.
A linked list is of variable size compared to Array being fixed size
2
Q
Components of LL?
A
head: Reference to the first node of the list (to know where to start the LL)
node: contains data and reference to the next, or previous node
tail: reference to the last node (to improve the time complexity to add new node)
3
Q
Types of LL?
A
- Single LL: LL with nodes that contain data and reference to the next node, it does not have a ref to prev node. Also, the last node’s ref is null
- Circular single LL: LL that contains data and reference to the next node, it does not have a ref to prev node. Also, the last node’s ref is pointing to the first node (not the root)
e. g. multiplayer game where the turn of players rotate - double LL: LL that contains data and reference to the next node, and prev node. Also, the last node’s ref is null
e. g. music player with prev, next buttons - circular double LL: LL that contains data and reference to the next node, and prev node. Also, the last node’s ref is pointing to the first node (not the root)
e. g. Alt + tab button
4
Q
How is LL stored in memory?
A
LL is stored as each node in a random memory cell location which is not continuous like an array.
Thus you cannot access the nth element directly from the first element’s address