Linked List vs List Big O Flashcards

1
Q

Append - Linked List

A

O(1) - same

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

Append - List

A

0(1) - same

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

Pop - Linked List

A

O(n) - worst

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

Pop - List

A

O(1) - better

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

Prepend - Linked List

A

O(1) - better

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

Prepend - List

A

O(n) = worst

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

Pop First - Linked List

A

O(1) - better

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

Pop First - List

A

O(n) - worst

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

Insert - Linked List

A

O(n) - same

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

Insert - List

A

O(n) - same

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

Remove - Linked List

A

O(n) - same

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

Remove - List

A

O(n) - same

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

Lookup by Index - Linked List

A

O(n) - worst

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

Lookup by Index - List

A

O(1) - better

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

Lookup by Value - Linked List

A

O(n) - same

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

Lookup by Value - List

A

O(n) - same

17
Q

Append Order

A

1) Create new node
2) Check if there is already a node
3) IF NOT, set head & tail to new node
4) ELSE, set tail.next = new & tail = new
5) Add length += 1
6) return True

18
Q

Pop Order

A

1) Check if there is a node
2) self temp & pre variable to head
3) Loop until temp.next is not None
4) In loop set pre to temp (moves pre over)
5) In loop set temp = temp.next to move temp
6) Move tail back to pre
7) Set tail.next = None
8) Decrease length by 1
9) Re-check length
10) set head & tail to None
11) return temp

19
Q

Prepend Order

A

1) Create new Node
2) Check if there is a node
3) IF NOT set head & tail to new node
4) ELSE set the new node’s next to head
5) Set head to the new node
6) Increase the length by 1
7) Return True

20
Q

Pop-First Order

A

1) Check if there is a node
2) Create temp variable and set to Head
3) Set head to head.next
4) Set the new temp.next to None
5) Decrease by 1
6) Check length again & set tail to none
7) Return temp

21
Q

Get Order

A

1) Make sure index is in the range
2) Create temp variable & set to head
3) Create for loop for range of index
4) Set temp to temp.next to move to next node
5) Return Temp

22
Q

Set order

A

1) Set temp to get(index)
2) Loop temp through
3) Set temp.value to value
4) Return True in the Loop
5) Return False out the Loop