Ch3 - A Bag Implementation That Links Data Exam Prep - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.

Ch3 - A Bag Implementation That Links Data Exam Prep

Chapter 3 - A Bag Implementation That Links Data

True/False (10)

  1. A node does not reference the data in another node.
  2. The outer LinkedBag class can access the data fields of the inner Node class directly without using set and get methods.
  3. A nested class is defined partially within another class definition.
  4. Any method that adds an entry to a collection is typically considered to be a core method.
  5. When using a linked implementation, a bag can never become full.
  6. Security checks are essential to maintain the integrity of the LinkedBag objects.
  7. After the method clear, the programmer does not need to worry about deallocating the nodes that were in the chain.
  8. It is a good programming practice to access a class’s data fields only through accessor and mutator methods.
  9. A chain requires less memory than an array of the same length.
  10. An array potentially wastes more space than a chain.

Short Answer (5)

  1. Should Node be a public class? Explain
  2. Why don’t we need to perform a security check in the Node constructor?
  3. Why do we use a loop counter as an additional check for the loop termination in the toArray method instead of just checking for a null value in currentNode?
  4. Explain how to implement the clear method in a chain.
  5. What happens when you access a reference that is null?

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. What is an advantage of using a chain for a Bag ADT?
    1. It avoids moving data when adding or removing bag entries.
    2. It has a fixed size which is easier to manage.
    3. It can be resized to provide as much space as needed.
    4. All of the above.
  2. Where is a new node added to a linked list?
    1. at the beginning
    2. at the end
    3. in the middle
    4. in a random place
  3. An object you link in Java to form a linked list is called a(n)
    1. node
    2. address
    3. reference
    4. link
  4. In a node object, the next field contains
    1. a reference to another node
    2. the data portion of the node
    3. a reference to the beginning of the list
    4. none of the above
  5. An object of type Node that contains a data type of Node is a
    1. circular reference
    2. improper reference
    3. forward reference
    4. logic error
  6. The next field in a node is also referred to as the
    1. link portion
    2. node
    3. initial address
    4. data portion
  7. Placing the Node class inside the LinkedBag class makes it a(n)
    1. inner class
    2. outer class
    3. dependent class
    4. inherited class
  8. An inner class is
    1. a nested class
    2. not static
    3. both a and b
    4. none of the above
  9. A reference to the first node in a linked list is called the _____ reference.
    1. head
    2. initial
    3. first
    4. default
  10. In the LinkedBag implementation, the numberOfEntries field
    1. records the number of entries in the current bag
    2. records the number of nodes in the chain
    3. is set to zero in a new chain
    4. all of the above
  11. Which code correctly adds the first entry to an empty bag?
    1. Node newNode = new Node(newEntry);
      firstNode = newNode;
    2. Node newNode = new Node();
      newNode = newEntry;
      firstNode = newNode;
    3. both a & b
    4. none of the above
  12. What happens when a bag becomes full in a linked list implementation?
    1. An OutofMemoryError will occur.
    2. The add method will return false.
    3. A MemoryExceededException will be thrown.
    4. This condition is not possible with a linked list implementation.
  13. What happens when you use the new operator in the LinkedBag constructor?
    1. a new node is created
    2. the JRE allocates memory for a node object
    3. a new object is instantiated
    4. all of the above
  14. What happens if an OutOfMemoryError occurs while adding a new node to the chain?
    1. the chain will remain intact
    2. the chain will lose its integrity
    3. a faulty node will be added to the beginning of the chain
    4. access to the chain will be lost
  15. Accessing all of the nodes in a chain beginning with the first one is called a(n)
    1. traversal
    2. visitation
    3. chaining
    4. link crawl
  16. If the following nodes are added in order, what does the resultant chain look like?
    “L”, “A”, “R”, “X”, “J”
    1. “J”, “X”, “R”, “A”, “L”, null
    2. “L”, “A”, “R”, “X”, “J”, null
    3. null, “J”, “X”, “R”, “A”, “L”
    4. null, “L”, “A”, “R”, “X”, “J”
  17. Given the following chain, what does the resultant chain look like after removing the node with the entry “K” in it?
    “J”, “X”, “F”, “K”, “L”, null
    1. “J”, “X”, “F”, “L”, null
    2. “X”, “F”, “J”, “L”, null
    3. “J”, “X”, “F”, “K”, “L”, null
    4. none of the above
  18. Given the following chain, what does the resultant chain look like after removing the node with the entry “L” in it?
    “J”, “X”, “F”, “K”, “L”, null
    1. “J”, “X”, “F”, “K”, null
    2. “X”, “F”, “K”, “J”, null
    3. you cannot remove the last node
    4. none of the above
  19. Given the following chain, what does the resultant chain look like after removing the node with the entry “J” in it?
    “J”, “X”, “F”, “K”, “L”, null
    1. “X”, “F”, “K”, “L”, null
    2. null, “X”, “F”, “K”, “L”, null
    3. you cannot remove the first node in an non-empty chain
    4. none of the above
  20. Given the following chain, what does the resultant chain look like after adding the node with an entry “U” in it?
    “J”, “X”, “F”, “K”, “L”, null
    1. “U”, “J”, “X”, “F”, “K”, “L”, null
    2. “J”, “X”, “F”, “K”, “L”, “U”, null
    3. you cannot determine where the entry will go in a bag chain implementation
    4. none of the above
  21. When removing a node from a chain, what case should we consider?
    1. the node is at the beginning of the chain
    2. the node is at the end of the chain
    3. both a and b
    4. none of the above
  22. When removing a node from a chain, what case should we consider?
    1. the node is not at the beginning of the chain
    2. the node is at the end of the chain
    3. both a and b
    4. none of the above
  23. A call to the remove method with no arguments
    1. removes the first node
    2. removes the last node
    3. removes a random node
    4. asks the user which node to remove
  24. A call to the remove method with no arguments on an empty list
    1. returns null
    2. returns false
    3. throws a ListEmptyException
    4. throws an IllegalOperationException
  25. What happens when you remove a node from a chain with only one node?
    1. the firstNode reference will become null
    2. the firstNode reference will become invalid
    3. an IllegalOperationException is thrown
    4. none of the above
  26. A top-level class
    1. is not nested
    2. is nested in an enclosing class
    3. is always static
    4. is defined entirely within another class definition
  27. The remove method with no arguments returns
    1. the first entry in the chain
    2. true if the method succeeds, false otherwise
    3. a random entry in the chain
    4. none of the above
  28. The remove method for a given entry returns
    1. the first entry in the chain that matches or null of it is not in the chain
    2. the last entry in the chain that matches or null of it is not in the chain
    3. true if the method succeeds, false otherwise
    4. none of the above
  29. Adding a new entry to an empty bag
    1. is a simple task
    2. must be treated as a special case
    3. throws an IllegalOperationException
    4. causes a NullExceptionError
  30. The clear method
    1. sets the firstNode to null
    2. traverses the chain and deallocating each node until it reaches the end
    3. returns true if it succeeds
    4. all of the above

Document Information

Document Type:
DOCX
Chapter Number:
3
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 3 - A Bag Implementation That Links Data
Author:
Frank M. Carrano

Connected Book

Data Structures with Java 5e Complete Test Bank

By Frank M. Carrano

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party