Chapter 8 Questions
Multiple Choice Questions
1. How is the order of the entries of an ADT list determined?
a) by the list itself
b) by the client
c) by the operating system
d) the order doesn’t matter
2. Which element of the list does not have a unique predecessor?
a) the head of the list
b) the tail of the list
c) the middle element of the list
d) all have unique predecessors
3. Changing the value of an entry at a given position on the list would probably be the task of which of these
methods?
a) replace
b) get
c) push
d) insert
e) What type would the getLength method for a list return?
f) boolean
g) ItemType
h) integer
i) void
4. Which of the following list methods would have only one parameter?
a) isEmpty
b) setEntry
c) insert
d) remove
5. Which of the following methods from list would have no parameters and void for the return type?
a) setEntry
b) getEntry
c) insert
d) clear
6. Given bList: snibble, nibble, tribble, wibble, quibble. The command
bList.insert(3, Bob) is executed. What is the appearance of the list?
a) snibble, nibble, tribble, Bob, wibble, quibble
b) snibble, nibble, Bob, tribble, wibble, quibble
c) snibble, nibble, tribble, wibble, quibble, Bob, Bob, Bob
d) Bob, Bob, Bob, snibble, nibble, tribble, wibble, quibble
7. Given bList: bob, slob, snob, cob, hob, rob and the operation bList.remove(4) is
executed. What does the list become?
a) bob, slob, snob, hob, rob
b) bob, slob, snob, cob, rob
c) bob, slob
d) hob, rob
8. Given cList: bip, snip, pip, rip, dip, clip. What value would be returned by the call to
method cList.getEntry(3)?
a) bip
b) snip
c) pip
d) rip
9. Given cList: bip, snip, pip, rip, dip, clip. What value would be returned by the call to
method cList.insert(9, sip)?
a) true
b) false
c) it throws an exception
d) sip
10. What should be returned by the list operation (aList.insert(2,x)).getEntry(2) ?
a) false
b) 2
c) x
d) an exception is thrown
11. What would be returned by the list operation (bList.insert(3,x)).remove(3)?
a) 2
b) x
c) false
d) bList
12. Consider nameList of size 12. For the operation nameList.insert(Clyde,x), which of the
following would be an invalid value for x?
a) 0
b) 1
c) 3
d) 12
13. Given the commands below, what do they do?
n = 0
for (position = 1 through intList.getLength())
n+= intList.getEntry(position)
a) insert integers into the list
b) sum the values found in list
c) sum the numbers 0 through n
d) calculate n!
Chapter 8 Questions
14. Given the commands below, what do they do?
for (position = 1 through aList.getLength()/2)
{
a = aList.getEntry(aList.getLength()-position+1)
aList.setEntry(aList.getEntry(aList.getLength()-position+1))
aList.setEntry(a,position)
}
a) randomize the entries
b) sort the entries
c) reverse the order of the entries
d) count how many entries there are
Chapter 8 Questions
True/False Questions
1. The ADT list can have an arbitrary length.
2. Insertion at the end of a linear linked list is a special case.
3. Lists contain items of the same type.
4. Items in a list may be referenced by number.
5. When you specify the behavior of list operations, always take into consideration how you might implement
them.
6. An axiom that describes the behavior of our ADT list is that a newly created list is empty.
7. (newList()).isEmpty()
8. The task of displaying all the items in a list is not an ADT list operation.
9. In the ADT list, each entry in the list is identified by its position which is an integer beginning with 0.
10. Inserting a new entry into a list renumbers any existing entries that follow the new one in the list.
Chapter 8 Questions
Short Answer Questions
1. What two characteristics are important for the entries in an ADT list?
2. Describe what happens when we insert a new item into the middle of the list.
3. Give the definition of the ADT List
4. What is needed besides a set of axioms in order to define the behavior of an ADT’s operations completely?
5. What would we expect this for loop to do?
for (position = 1 through aList.getLength())
{
dataItem = aList.getEntry(position)
print(dataItem)
}
6. What is the range of entry numbers for which it is legal to insert a new entry?
7. When an entry is removed from a list, what is an additional consequence of that removal?