LinkedList Flashcards

1
Q

Is a Linked List Random or Sequential Access?

A

Sequential

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

Is a LinkedList a linear data structure?

A

Yes

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

Each element is created as a separate…

A

Object

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

What is each individual element called?

A

Node

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

A Node is made up of two parts. What are they?

A
  1. The data (could be complex objects)

2. The reference (or pointer) the the next Node in the List.

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

What is a real-world analogy for a ACCESSING an element in a LinkedList?

A

A tape measure. To get to inch 72 you first have to traverse inches 1 through 71.

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

How do we know when we have reached the end of a LinkedList?

A

The reference to the next Node will be null.

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

What is the term for the first Node in a LinkedList?

A

The HEAD Node.

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

What is the term for the last Node in a LinkedList?

A

The TAIL Node.

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

Data can flow in and out of …. point of a LinkedList.

A

Any

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

What are the three places in a LinkedList that we can ADD or REMOVE data?

A

HEAD, MIDDLE, TAIL.

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

How do we ADD a Node to the Head of LinkedList?

A

We make the new head Node point to the old head Node and update what Node we consider to be the head node in our implementation.

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

How do we DELETE a Node from the Head of LinkedList?

A

We make the 2nd Node in the list our new head Node and make the old head Node point to null.

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

How do we ADD a Node somewhere in the middle of a LinkedList? (2 steps)

A
  1. Make the pointer of the new Node point to the Node after the location we want to insert at.
  2. Set the Node before the location we want to insert at to point towards the new Node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do we REMOVE a Node somewhere in the middle of a LinkedList? (1 step)

A

Make the pointer of the Node previous to the one we’re removing, to now point to the Node after the one we’re removing.

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

How do we REMOVE a Node at the tail of a LinkedList?

A

Set the previous tail to point to a null value instead of the current tail.

17
Q

What is the BigO of ACCESSING an element in a LinkedList?

A

O(n). Sequential data structure, worst-case you have to go via every element in the list.

18
Q

What is a pirate themed analogy of a LinkedList?

A

It’s like a treasure map. You follow the directions to one place and then it tells you the where to go to find the next place and so forth.

19
Q

What is the BigO of SEARCHING for an element in a LinkedList?

A

O(n). Must do Linear Search.

20
Q

What is the BigO of INSERTING an element in a LinkedList? (2 depending on location)

A
  1. If inserting at the head of the list then O(1)

2. Anywhere else then it’s O(n)

21
Q

What is the BigO of DELETING an element in a LinkedList? (2 depending on location)

A
  1. If deleting at head of the list then O(1)

2. Anywhere else then it’s O(n)

22
Q

Examples of uses for LinkedLists?

A

Music playlists. The track info is the data and it points to the next song in the playlist.
PhotoViewing app, the ‘next’ button links to the next image in the list.
As the ‘backing’ data structure for other data structures like Queues and Stacks

23
Q

What is a Singly-LinkedList? What is its main drawback? And what data structure gets around this drawback?

A

The pointers/references only point to the next Node in the list. You can’t navigate back towards the head node. With a Doubly-LinkedList you can traverse the list in either direction.