Ch10 - Lists Test Bank Docx - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 10 - Lists
True/False (10)
- The ADT list only works for entries that are strings.
- The ADT list is more general than common lists and has entries that are objects of the same type.
- Adding entries to the end of a list does not change the positions of entries already in the list.
- The first entry is a list is at position 0.
- The entries of a list are numbered from 0 to n.
- When a programmer implements an ADT list, clients can use the ADT’s operations in a program without knowing how the programmer implemented the list to be able to use it.
- The Java Class Library contains an implementation of the ADT list that uses a resizable array instead of a linked chain.
- A list is an object whose data consists of unordered entries.
- Each entry is a list ADT is uniquely identified by its position within the list.
- You may replace an entry at any given position in a list.
Short Answer (7)
- If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code?
myList.add(“Tom”)
myList.add(“Hank”)
myList.add(3, “Ryan”)
myList.add(1, “Sally”)
myList.add(“Helen”) - If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code.
myList.add(“Tom”)
myList.add(“1, Hank”)
myList.add(2, “Ryan”)
myList.add(“Sally”)
myList.add(3, “Helen”) - Make a case for the designer of an interface to determine what behavior is appropriate when a collection such as a list is empty.
- If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code.
myList.add(“horse”)
myList.add(“goat”)
myList.add(1, “fish”)
myList.add(“cat”)
myList.remove(1)
myList.add(2, “dog”)
- If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code.
myList.add(“horse”)
myList.add(“goat”)
myList.add(1, “fish”)
myList.add(“cat”)
myList.remove(2)
myList.add(3, “dog”)
myList.replace(2, “frog”)
- Given treeList is a declared ADT list that is initially empty, write a serious of list operations to generate the following list step by step.
- maple
- maple, oak
- maple, elm, oak
- palm, elm, oak
treeList.add(maple)
treeList.add(oak)
treeList.add(2, elm)
treeList.replace(1, palm)
- Given treeList is a declared ADT list that is initially empty, write a serious of list operations to generate the following list step by step.
- maple
- oak, maple
- oak, elm, maple
- elm, maple
treeList.add(maple)
treeList.add(1, oak)
treeList.add(2, elm)
treeList.remove(1)
Multiple Choice (17) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- In the ADT list, new entries are typically added
- at the end of the list
- at the beginning of the list in the list
- at a computed place in the list depending on the number of elements
- You can add a new entry in a list
- at the beginning
- at the end
- in between items
- all of the above
- If myList is a declared ADT list and the front of the list is on the left, what does the list look like after applying the following pseudo code?
myList.add(“cat”)
myList.add(“dog”)
mylist.add(“fish”)- cat, dog, fish
- fish, dog, cat
- cat, fish, dog
- dog, fish, cat
- If myList is a declared ADT list and the front of the list is on the left, what does the list look like after applying the following pseudo code?
myList.add(“horse”)
myList.add(“goat”)
myList.add(3, “fish”)
myList.add(1, “dog”)
myList.add(“cat”)- dog, horse, goat, fish, cat
- horse, goat, fish, dog, cat
- cat, horse, goat, fish, dog
- cat, fish, goat, dog, horse
- Given an ADT list called myList that contains 4 items entries in it, which statement will remove the first item on the list?
- myList.remove(1)
- myList.remove()
- myList.removeFront()
- myList.removeFirst()
- Given an ADT list called myList that contains 4 items entries in it, which statement will add a new item called x on the front of the list?
- myList.add(1, x)
- myList.add(x)
- myList.addFirst(x)
- myList.addFront(x)
- Which method is not meaningful for use on an empty list?
- remove
- replace
- getEntry
- all of the above
- Which method is well behaved when the given position is valid for the current list?
- add
- remove
- replace
- all of the above
- In the interface ListInterface, the method
public void add(T newEntry);
describes which of the following behaviors?- adds a new entry to the end of the list
- increases the list size by 1
- does not affect any other entries on the list
- all of the above
- In the interface ListInterface, the method
public void add(int newPosition, T newEntry);
describes which of the following behaviors?- adds a new entry at the specified position in the list
- increases the list size by 1
- moves entries originally at or above the specified position one position higher
- all of the above
- In the interface ListInterface, the method
public void remove(int givenPosition);
describes which of the following behaviors?- remove the entry at a given position from the list
- increases the list size by 1
- does not affect any other entries on the list
- all of the above
- If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code?
myList.add(“horse”)
myList.add(“goat”)
myList.add(3, “fish”)
myList.add(1, “dog”)
myList.add(“cat”)- fish
- goat
- cat
- horse
- If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code?
myList.add(“horse”)
myList.add(“goat”)
myList.add(1, “fish”)
myList.add(“cat”)
myList.add(2, “dog”)
myList.remove(4)- horse
- goat
- dog
- cat
- If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(4) return after applying the following pseudo code?
myList.add(“horse”)
myList.add(“goat”)
myList.add(1, “fish”)
myList.add(“cat”)
myList.remove(1)
myList.add(2, “dog”)
- cat
- dog
- goat
- fish
- The public ArrayList() constructor in the Java Class Library ArrayList creates an empty list with an initial capacity of
- 10
- 0
- 100
- 1
- What does the Java Class Library implementation of the interface list do when an index is out of range?
- throw an exception
- return null
- return false
- crash the program
- If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code?
myList.add(“horse”)
myList.add(“goat”)
myList.add(1, “fish”)
myList.replace(3, “sheep”)
myList.add(“cat”)
myList.remove(1)
myList.add(2, “dog”)- sheep
- dog
- horse
- cat
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano