linkedLists Flashcards

1
Q

What’s the time complexity for traversing arrays?

A

Time: 0(1), because arrays occupy contiguous (adjacent) blocks of memory

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

What’s the time complexity for traversing linked lists?

A

Time: 0(n), because linked list nodes can exist anywhere in memory

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

What’s the time and space complexity for linked lists?

A

Time: 0(n), because linked list nodes can exist anywhere in memory

Space: 0(n), because it requires n nodes to store n values. Linked lists hold two main pieces of information (the value and pointer) per node. This means that the amount of data stored increases linearly with the number of nodes in the list.

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

Whats the time and space complexity for doubly linked lists?

A

Time: 0(1), because of the two addresses in a node (next and previous), this makes it efficient.

space: 0(n), because it holds two addresses in a node, one is of the next node and the other one is of the previous node, this takes more memory

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

What’s the time complexity for addToHead()?

A

Time: 0(1), addToHead() is O(1) since each of its steps operate in constant time, regardless of the size of the list

Because linked lists have a time complexity of 0(n) and addToHead() has a time complexity of 0(1), to add to head on a linked list would take 0(n) time.

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

What’s the time complexity for print() or search()?

A

Time: 0(n), because it requires visiting n nodes

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

What’s the time complexity for addToTail()?

A

Time: 0(n), because it requires visiting n nodes

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

What’s the time complexity for removeFromHead() and removeFromTail() for linked lists?

A

Time: 0(n)

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