Test Bank Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano A+

$45.00
Test Bank Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano A+

Test Bank Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano A+

$45.00
Test Bank Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano A+

True/False (10)

  1. An abstract data type is not necessarily a collection.

Answer: true

  1. A collection is not necessarily an abstract data type.

Answer: false

  1. Entries of a bag can belong to classes related by inheritance.

Answer: true

  1. Entries of a bag may belong to different classes because items are unordered.

Answer: false

  1. All entries of a bag must have the same data type or a subtype of that data type.

Answer: true

  1. By declaring a data type to be a BagInterface, we can replace the bag class with another class that implements the BagInterface.

Answer: true

  1. A method can change the state of an object passed to it as an argument.

Answer: true

  1. A set is a special kind of bag.

Answer: true

  1. You cannot determine the exact number of times a particular item appears in a bag because it is unordered.

Answer: false

  1. Code written with respect to an interface makes it difficult to replace one implementation of a bag with another.

Answer: false

Short Answer (5)

  1. Explain the rationale for returning a Boolean value from the add bag operation.

Answer: A client should know what happened. A Boolean value indicates true for success or false for a failed operation.

  1. Explain why writing a test program before implementing a class is a good idea.

Answer: It helps you understand the specifications before committing to your design and implementation.

  1. Explain why the set ADT does not need a getFrequencyOf

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.

  1. What is the design rationale for providing a toArray method instead of a displayBag method?

Answer: The user/client is free to display any or all of the items in any way desired.

  1. Explain why null is a potential return value for the remove operation.

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.

  1. A language-independent specification for a group of values and operations on those values is called a/an:
    1. abstract data type **
    2. data structure
    3. collection
    4. primitive

  2. An implementation of an ADT with a programming language is called a/an:
    1. data structure **
    2. abstract data type
    3. collection
    4. primitive

  3. An object that groups other objects and provides services to its clients is called a/an:
    1. collection **
    2. abstract data type
    3. data structure
    4. primitive

  4. Which of the following is not true with regard to bags?
    1. objects are in a specific order **
    2. can contain duplicate items
    3. is an abstract data type
    4. is a kind of collection in Java

  5. Which behavior is not represented in a bag?
    1. reorder the bag **
    2. report the number of items in the bag
    3. report if the bag is empty
    4. add an item to the bag

  6. Which method returns a count of the current number of items in a bag?
    1. getCurrentSize() **
    2. getSize()
    3. size()
    4. currentSize()

  7. Why would the add method return false?
    1. when the addition of a new item was not successful **
    2. when there was a duplicate of the entry already in the bag
    3. when there was not a duplicate of the entry already in the bag
    4. when addition of a new item was successful

  8. Which method removes all entries of a bag?
    1. clear() **
    2. remove()
    3. delete()
    4. empty()

  9. Which method removes one unspecified entry from a bag if possible?
    1. remove() **
    2. clear ()
    3. delete()
    4. empty()

  10. Which method removes one occurrence of a particular entry from a bag if possible?
    1. remove(anItem) **
    2. clear (anItem)
    3. delete(anItem)
    4. empty(anItem)

  11. Which behaviors do not change the contents of a bag?
    1. add()
    2. clear()
    3. remove()
    4. none of the above **

  12. Which behaviors change the contents of a bag?
    1. clear()
    2. remove()
    3. add()
    4. all of the above **

  13. Which method can be used to retrieve all of the elements of a bag?
    1. toArray() **
    2. printBag()
    3. displayBag()
    4. getAllItems()

  14. When using abstraction as a design principle you should focus on:
    1. what you want to do with the data **
    2. how the data is stored
    3. how the data is manipulated
    4. all of the above

  15. Which of the following is a special kind of bag that does not allow duplicate entries?
    1. set **
    2. collection
    3. extended bag
    4. super bag

  16. Which of the following are properties of a set?
    1. duplicates are permitted **
    2. elements are stored in order
    3. elements may not be removed
    4. none of the above

  17. When adding an item to a bag, which of the following statements are true?
    1. You cannot specify the position of the item in the bag. **
    2. You can specify the item will be placed as the first in the bag.
    3. You can specify the item will be placed as the last in the bag.
    4. None of the above.

  18. To accommodate entries of any class, the bag methods use ______ .
    1. a generic type **
    2. an inherited type
    3. a sub class
    4. all of the above

  19. Which behavior(s) change the contents of a bag?
    1. remove() **
    2. getCurrentSize()
    3. isEmpty()
    4. getFrequencyOf()

  20. Which behavior(s) change the contents of a bag?
    1. add() **
    2. getFrequencyOf()
    3. contains()
    4. toArray()

  21. Which behaviors leave the contents of a bag unaltered?
    1. contains() **
    2. remove()
    3. clear()
    4. add()

  22. Which behavior(s) leave the contents of a bag unaltered?
    1. toArray()
    2. getFrequencyOf()
    3. isEmpty()
    4. all of the above **

  23. Which of the following are good reasons to write Java statements that use your bag ADT before the implementation is done?
    1. it helps confirm the design
    2. it helps check the suitability of the specification
    3. it helps check your understanding of the specification
    4. all of the above **

  24. Which of the following would be suitable items to store in a bag?
    1. marbles **
    2. coins **
    3. student roster
    4. all of the above

  25. You wish to keep track of the distribution of words in a document, for example, how many times the word “apple” appears. You store each word in the document in a bag. Why is a bag a potentially good solution?
    1. the order of the words is unimportant
    2. the words in the document are not unique
    3. getFrequencyOf() is a useful behavior for determining the word distribution
    4. all of the above **

  26. For which of the following would a bag implementation be suitable?
    1. a shopping cart
    2. a vending machine
    3. a postage stamp collection
    4. all of the above **

  27. Which behavior is not specified in the bag ADT?
    1. sort() **
    2. contains()
    3. clear()
    4. remove()

  28. Which bag behavior is not useful or relevant for a set?
    1. getFrequencyOf() **
    2. add()
    3. remove()
    4. contains()

  29. Which bag behaviors would need to be modified when implementing a set?
    1. add() **
    2. clear()
    3. contains()
    4. toArray()

  30. Sets that adhere to the standard interface in the Java Class library
    1. do not contain a pair of objects x and y such that x.equals(y) is true **
    2. are completely compatible with the bag interface
    3. allow duplicate entries
    4. order the objects contained in the set
+
-
Only 0 units of this product remain

You might also be interested in