LinkedLists Flashcards

1
Q

what is a linkedlist

A
  • a collection of nodes and data is stored in the Node objectl
  • connections between nodes is done by having each node point to the next node in the list
  • data is NOT stored contiguously like in an arraylist/array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SLL with head & tail pointers
- adding to the front
- adding to the back
- adding to elsewhere
- removing from the front
- removing from the back
- removing from elsewhere

A
  • adding to the front: O(1)
  • adding to the back: O(1)
  • adding to elsewhere: O(n)
  • removing from the front: O(1)
  • removing from the back: O(n)
  • removing from elsewhere: O(n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

DLL with head & tail pointers
- adding to the front
- adding to the back
- adding to elsewhere
- removing from the front
- removing from the back
- removing from elsewhere

A

DLL with head & tail pointers
- adding to the front: O(1)
- adding to the back: O(1)
- adding to elsewhere: O(n)
- removing from the front: O(1)
- removing from the back: O(1)
- removing from elsewhere: O(n)

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

CLL with head (usually doesn’t include a tail pointer)
- adding to the front
- adding to the back
- adding to elsewhere
- removing from the front
- removing from the back
- removing from elsewhere

A
  • adding to the front: O(1)
  • adding to the back: O(1)
  • adding to elsewhere: O(n)
  • removing from the front: O(1)
  • removing from the back:O(n)
  • removing from elsewhere: O(n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to add to the front of a CLL

A
  • create a new node right after the head
  • copy head data over to the new node
  • override head data to the new data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to add to the back of a CLL

A
  • create a new node right after the head
  • copy head data over to the new node
  • override head data to the new data
  • set head to the new node (at index 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how to remove from the front of a CLL

A
  • move the data from head.next into the head
  • remove the second node from the list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to remove from the back of a CLL

A
  • traverse to the node before the last node and perform removal operation like in SLL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly