Part 1 Flashcards

1
Q

What is a recursive data structure?

A

A data structure that contains a reference or pointer to another object of the same type

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

A linked list is a _______ data structure

A

Recursive

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

What does the cons operation do with a linked list?

A

Take a list and a data item and construct a new list by adding the specified data item to the front of the list

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

What does the head operation do with a linked list?

A

Returns the first item (the front item) of the list

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

What does the tail operation do to a linked list?

A

Return the whole list, except the head

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

How is an empty reference represented in java?

A

null

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

What is the difference between a doubly linked list and a linked list?

A

Doubly linked list cells have a reference to the previous cell as well as the next one

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

for a generic class, do you need <t> in the constructor method name?</t>

A

No

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

What are the advantages of using doubly linked lists over singly linked lists?

A

More efficient traversal in both directions, can add and remove at both ends

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

What is the disadvantage of using doubly linked lists over singly linked lists?

Why is this often not a concern?

A

More memory space

Not usually a concern because it will only use an extra int (4 bytes) per item which is usually insignificant next to the data structures the list is referencing.

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

What is the disadvantage of using Object to allow generic classes, rather than <t>?</t>

A

Using object you have to downcast whenever you want to use the object, also allows objects to be mixed types which is probably not good

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

When writing generic static methods, it is necessary to

A

include < T > in the signature after the word static

e.g. public static < T > void addCopies(T s, LList< T > ll, int numcopies)

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