True/False (10)
- An abstract data type is not necessarily a collection.
Answer: true
- A collection is not necessarily an abstract data type.
Answer: false
- Entries of a bag can belong to classes related by inheritance.
Answer: true
- Entries of a bag may belong to different classes because items are unordered.
Answer: false
- All entries of a bag must have the same data type or a subtype of that data type.
Answer: true
- By declaring a data type to be a BagInterface, we can replace the bag class with another class
that implements the BagInterface.
Answer: true
- A method can change the state of an object passed to it as an argument.
Answer: true
- A set is a special kind of bag.
Answer: true
- You cannot determine the exact number of times a particular item appears in a bag because it is
unordered.
Answer: false
- Code written with respect to an interface makes it difficult to replace one implementation of a
bag with another.
Answer: false
(Data Structures and Abstractions with Java, 5e Frank Carrano, Timothy Henry) (Test Bank all Chapters) 1 / 4
Short Answer (5)
- Explain the rationale for returning a Boolean value from the add bag operation.
- Explain why writing a test program before implementing a class is a good idea.
- Explain why the set ADT does not need a getFrequencyOf operation.
- What is the design rationale for providing a toArray method instead of a displayBag method?
- Explain why null is a potential return value for the remove operation.
Answer: A client should know what happened. A Boolean value indicates true for success or false for a failed operation.
Answer: It helps you understand the specifications before committing to your design and implementation.
Answer: Because sets do not contain duplicate items, only a 0 for absence or 1 for presence of an item would be returned. Using a contains method is a better design.
Answer: The user/client is free to display any or all of the items in any way desired.
Answer: It is a value that cannot be in the bag and therefore signals a problem if, for example, a client tries to remove an entry from an empty bag.
Multiple Choice (30) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED
WITH **. YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- A language-independent specification for a group of values and operations on those values is
called a/an:
- abstract data type **
- data structure
- collection
- primitive
2. An implementation of an ADT with a programming language is called a/an:
- data structure **
- abstract data type
- collection
- primitive
- An object that groups other objects and provides services to its clients is called a/an:
- collection ** 2 / 4
- abstract data type
- data structure
- primitive
- Which of the following is not true with regard to bags?
- objects are in a specific order **
- can contain duplicate items
- is an abstract data type
- is a kind of collection in Java
- Which behavior is not represented in a bag?
- reorder the bag **
- report the number of items in the bag
- report if the bag is empty
- add an item to the bag
- Which method returns a count of the current number of items in a bag?
- getCurrentSize() **
- getSize()
- size()
- currentSize()
- Why would the add method return false?
- when the addition of a new item was not successful **
- when there was a duplicate of the entry already in the bag
- when there was not a duplicate of the entry already in the bag
- when addition of a new item was successful
- Which method removes all entries of a bag?
- clear() **
- remove()
- delete()
- empty()
- Which method removes one unspecified entry from a bag if possible?
- remove() **
- clear ()
- delete()
- empty()
- Which method removes one occurrence of a particular entry from a bag if possible?
- remove(anItem) ** 3 / 4
- clear (anItem)
- delete(anItem)
- empty(anItem)
- Which behaviors do not change the contents of a bag?
- add()
- clear()
- remove()
- none of the above **
- Which behaviors change the contents of a bag?
- clear()
- remove()
- add()
- all of the above **
- Which method can be used to retrieve all of the elements of a bag?
- toArray() **
- printBag()
- displayBag()
- getAllItems()
14. When using abstraction as a design principle you should focus on:
- what you want to do with the data **
- how the data is stored
- how the data is manipulated
- all of the above
- Which of the following is a special kind of bag that does not allow duplicate entries?
- set **
- collection
- extended bag
- super bag
- Which of the following are properties of a set?
- duplicates are permitted **
- elements are stored in order
- elements may not be removed
- none of the above
- When adding an item to a bag, which of the following statements are true?
- You cannot specify the position of the item in the bag. **
- / 4