Linked Data Structures Flashcards

1
Q

What is a Linked List?

A

A linked list consists of a single chain of nodes each connected to the next by a link.

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

What is the first node in a linked list

A

The first node, or start node in a linked list is called the head node.
The entire linked list can be traversed by starting at the head node.

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

Does a linked list object contain all the nodes in the linked list directly?

A

It does not. Rather, it uses the instance variable head to locate the head node of the list. Therefore, once the head node can be reached, then every other node in the list can be reached.

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

How is an empty linked list indicated?

A
  1. The head instance variable contains a reference to the first node in the linked list. If the list is empty, this instance variable is set to null.
  2. The linked list constructor sets the head instance variable to null. This indicates that the newly created linked list is empty.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you indicate the end of a linked list?

A

The last node in a linked list should have its link instance variable set to null. That way the code can test whether or not a node is the last node.

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

How do you traverse a linked list?

A

If a linked list already contains nodes, it can be traversed as follows:

  1. set a local variable equal to the value stored by the head node (its reference)
  2. This will provide the location of the first node.
  3. After accessing the first node, the accessor method for the link instance variable will provide the location of the next node.
  4. Repeat this until the location of the next node is equal to null.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a stack data structure?

A

A stack data structure is not necessarily a linked data structure, but can be implemented as one. A stack removes items in the reverse order of which they were inserted. (LIFO: Last in First Out)

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