Questions Chapter 5 Flashcards

1
Q

Which of the following is NOT true? A reference to a class object:

a. can be used to access public methods in the object
b. has a size dependant on class.
c. has the data type of the class
d. does not hold the object itself.

A

b. has a size dependant on its class.

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

Access to the links in a linked list is usually through the _______ link.

A

first

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

When you create a reference to a link in a linked list, it:

a. must refer to the first link
b. must refer to the link pointed to by current
c. must refer to the link pointed to by next.
d. can refer to any link you want

A

d. can refer to any link you want.

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

How many references must you change to insert a link in the middle of a singly linked list?

A

2.

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

How many references must you change to insert a link at the end of a singly linked list?

A

1

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

In the insertFirst( ) method in the LinkList.java program (Listing 5.1), the statement newLink.next = first; means that:

a. the next new link to be inserted will refer to first
b. first will refer to the new link
c. the “next” field fo the new link will refer to the old first link
d. newLink.next will refer to the new first link in the list

A

c. the “next” field of the new link will refer to the old first link.

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

Assuming current points to the next-to-last link in a singly linked list, what statement will delete the last link from the list?

A

current.next = null;

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

When all references to a link are changed to refer to something else, what happens to the link?

A

garbage collection

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

A double-ended list:

a. can be accessed from either end
b. is a different name for a doubly linked list
c. has pointers running both forward and backward between links
d. has its first link connected to its last link

A

a. can be accessed from either end.

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

A special case often occurs for insertion and deletion routines when a list is ________.

A

empty

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

Assuming a copy takes longer than a comparison, is it faster to delete an item with a certain key from a linked list or from an unsorted array?

A

linked list

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

How many times would you need to traverse a singly linked list to delete the item with the largest key?

A

1

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

Of the lists: simple linked list, double-ended list, sorted list, doubly linked list, which one would be best for implementing a queue?

A

double-ended

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

Which of the following is NOT true? Iterators would be useful if you wanted to:

a. do an insertion sort on a linked list
b. insert a new link at the beginning of a list
c. swap two links at arbitrary locations
d. delete all links with a certain key value

A

b. insert a new link at the beginning of a list

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

Which do you think would be a better choice to implement a stack: a singly linked list or an array?

A

the list. The both do push( ) and pop ( ) in O(1) time, but the list uses memory more efficiently .

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

Deleting an item at the beginning of a list involves setting first to point to ____________.

A

first.next

17
Q

To traverse a linked list, you start at _________ and then go from link to link, using each link’s ________ field.

A

start at first, use each link’s next field.

18
Q

A double-ended list maintains a reference to the ________ _________ in the list, as well as the _________ _________.

A

maintains reference to the last link and first link.

19
Q

A _________ list allows insertion at the end of the list.

A

double-ended list

20
Q

A(n) _________ is a data storage class considered without reference to its implementation.

A

ADT

21
Q

Insertion in a sorted list takes ________ time. Deletion of the smallest link takes _______ time.

A

Insertion: O(N). Deletion O(1).

22
Q

In a __________ list, each link contains a reference to the previous link as well as the next link.

A

doubly-linked list.

23
Q

A ________ list permits backward traversal and deletion from the end of the list

A

doubly-linked list.

24
Q

A(n) ________ is a reference, encapsulated in a class object, that refers to a link in an associated list.

A

iterator

25
Q

Iterator methods allow the user to move the iterator along the list and acces the _______ currently referred to.

A

link