Arrays VS Linked List Flashcards

(25 cards)

1
Q

Access/delete time for Arrays

A

For the last element, O(1)
For any element at index i (i < n), O(n)

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

Access/delete time for Linked List

A

If a predecessor is located, O(1)

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

Locate time for an Array

A

For an unsorted list, O(n)
For a sorted list, O(log n)

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

Locate time for a Linked List

A

O(n)

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

When should you use an Array?

A

When size doesn’t change substantially. Arrays have a fixed size upon initialisation

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

When should you use a linked list?

A

When the list will grow and shrink. Linked lists have no fixed size

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

How can you access an element in an Array?

A

Element at index i can be accessed directly

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

How can you access a node in a linked list?

A

When accessing the i-th item, it requires a list traversal from the beginning

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

How does an array use memory?

A

It uses an implicit ordering scheme, with items following A[i] being stored as A[i+1]

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

How does a linked list use memory?

A

It requires additional memory for references

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

What is an array efficient for?

A

Insertion and deletion at the end of the array

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

What is a linked list efficient for?

A

Insertion and deletion at the front of the array (locate operation not needed)

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

What is an issue with implementing a Stack using an array?

A

Limited size, so there may be problems with pushing an item onto a full stack.

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

What is an advantage and disadvantage of implementing a Stack using a linked list?

A

Advantage: ‘unlimited’ size
Disadvantage: extra-memory references

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

What is the time complexity of the Push and Pop operations of a stack?

A

Constant time O(1)

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

When would you use a Stack?

A
  • To reverse or parse data
  • Perform backtracking
  • Imitate recursion
17
Q

What happens if the maxLength has been reached on a queue?

A

The queue is ‘wrapped around’, meaning the location at index 0 is used for enqueue

18
Q

What is the issue with implementing a Queue as an array?

A

It will have a limited size, meaning there may be problems with Enqueue if the queue becomes full

19
Q

What is an advantage and disadvantage of implementing a Queue using a linked list?

A

Advantage: ‘unlimited size’
Disadvantage: uses extra-memory references

20
Q

What is the time complexity for the enqueue and dequeue operation for a Queue?

21
Q

What is different about the Priority Queue’s dequeue?

A

It removes the element with the largest key, which will have been placed first in the queue

22
Q

What is the time complexity for inserting a new element to an unsorted sequence implemented as an array and linked list?

23
Q

What is the time complexity for inserting a new element to a sorted sequence implemented as an array and linked list?

24
Q

What is the time complexity for deleting an element from an unsorted sequence implemented as an array and linked list?

25
What is the time complexity for deleting an element from a sorted sequence implemented as an array and linked list?
O(1)