Test Questions & Answers Chapter.17 - Sorted Lists - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 17 - Sorted Lists
True/False (14)
- Entries in a sorted list are ordered simply by their positions within the list.
- In a sorted list, you do not specify where in the list the entry belongs.
- The entries in a sorted list must be objects that can be compared to each other.
- The ADT sorted list cannot contain null entries.
- In a sorted list with entries in ascending order, you insert a new entry just after the first entry that is not smaller than the new entry.
- If a sorted list is empty, a call to the getNodeBefore method returns null.
- In the LinkedSortedList implementation, when you try to add an entry that already exists in the list, it is added after the last duplicate occurrence.
- In the LinkedSortedList, a recursive addition to a chain of nodes locates and remembers the nodes prior to the insertion point.
- The linked implementation of the ADT sorted list maintains a tail reference.
- In the ADT sorted list, the worst-case time efficiency of the array implementation and the linked implementation add operation is the same.
- In the ADT sorted list, the worst-case time efficiency of the array implementation and the linked implementation getEntry operation is the same.
- In the SortedList implementation, the add method sets the sign of the integer it returns to indicate whether the entry exists in the list already.
- The ADT sorted list, the time efficiency of the getPosition method depends on the efficiency of the getEntry method.
- The ADT sorted list, the time efficiency of the getEntry is independent of which implementation of the ADT list you use.
Short Answer (5)
- Explain why the client must not be able to specify where a new entry will be placed in a sorted list.
- In the ADT sorted list, why is it not necessary for the remove method to return the object removed from the list?
- In the ADT sorted list, why does the remove(givenPosition) throw an exception if the search fails?
- Why is using recursion to process a chain of linked nodes for the sorted list implementation more complex that the iterative approach?
- Explain when you wouldn’t need to check the sign of the integer returned by the add method in the SortedList implementation.
Multiple Choice (31) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- A list where entries are compared to each other and ordered accordingly is called a
- sorted list
- ordered list
- comparative list
- stream lined list
- Which operation(s) behave(s) the same for both the ADT list and the ADT sorted list?
- getEntry(givenPosition)
- contains(anEntry)
- clear()
- all of the above
- Which operation(s) behave(s) the same for both the ADT list and the ADT sorted list?
- remove(givenPosition)
- getPosition(anEntry)
- add(newEntry)
- all of the above
- In the ADT sorted list, what does the getPosition method do when the entry being searched for is not in the list?
- return a negative number
- return 0
- return false
- throw an UnfoundElementException
- In the ADT sorted list, what does the getPosition method do?
- searches for an entry in the list
- returns the position number if the entry is found in the list
- returns a negative number where the entry belongs in the list if it is not found
- all of the above
- In the ADT sorted list, if an entry being searched for is not found but belongs at position 7, what does the getPosition method do?
- return -7
- return 7
- return 0
- throws an UnfoundElementException
- In the ADT sorted list, what does the getPosition method do when the list is empty?
- return -1
- return 1
- return 0
- throw an UnfoundElementException
- In the ADT sorted list, why is there no functionality to add an entry at a given position?
- the client could destroy the order of the list
- the client would have too much information about the underlying code
- the client would be able to access the list illegally
- none of the above
- Which method that is part of the ADT list is not supported in the ADT sorted list?
- replace
- remove
- add
- getEntry
- Which functionality is part of the ADT sorted list given the entry as an argument?
- add
- remove
- locate
- all of the above
- In the ADT sorted list, what happens when the remove(anEntry) is called?
- it removes the given entry
- it returns true if it succeeded
- it returns false if it failed
- all of the above
- In the ADT sorted list, what happens when the remove(anEntry) does not find the entry in the sorted list?
- it returns false
- it returns null
- it returns a negative number
- it throws an exception
- In the ADT sorted list, what happens when the remove(givenPosition) does not find the entry in the sorted list?
- it throws an exception
- it returns a negative number
- it returns false
- it returns null
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the list look like after the following operations?
amphibianList.add(“iguana”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.add(“lizard”);- gecko, iguana, lizard, toad
- iguana, gecko, toad, lizard
- lizard, toad, gecko, iguana
- none of the above
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the statement
amphibianList.getPosition(“iguana”)
produce after the following operations?
amphibianList.add(“iguana”);
amphibianList.add(“salamander”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.add(“lizard”);- 2
- 1
- 3
- 4
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the statement
amphibianList .contains(“frog”)
return after the following operations?
amphibianList.add(“iguana”);
amphibianList.add(“salamander”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList .add(“lizard”);- false
- 0
- null
- throws an exception
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the list look like after the following operations?
amphibianList.add(“salamander”);
amphibianList.add(“iguana”);
amphibianList.add(“lizard”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.remove(“iguana”);- gecko, lizard, salamander, toad
- salamander, lizard, gecko, toad
- toad, gecko, lizard, salamander
- none of the above
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the list look like after the following operations?
amphibianList.add(“salamander”);
amphibianList.add(“iguana”);
amphibianList.add(“lizard”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.remove(4);- gecko, iguana, lizard, toad
- toad, salamander, lizard, gecko
- salamander, iguana lizard, toad
- none of the above
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what does the list look like after the following operations?
amphibianList.add(“salamander”);
amphibianList.add(“iguana”);
amphibianList.add(“lizard”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.remove(6);- throws an exception
- salamander
- 0
- null
- Given the following definition,
SortedListInterface<String> amphibianList = new SortedList<>();
what happens after the following operations?
amphibianList.add(“salamander”);
amphibianList.add(“iguana”);
amphibianList.add(“lizard”);
amphibianList.add(“gecko”);
amphibianList.add(“toad”);
amphibianList.remove(“snake”);- false
- throws an exception
- -1
- null
- You can implement a sorted list with
- an array
- a chain of linked nodes
- an instance of a vector
- all of the above
- In the LinkedSortedList implementation, how many references do you need to traverse the list?
- two
- three
- one
- none
- What happens when a call to the getNodeBefore method is made on an empty list?
- null
- 0
- -1
- throws an exception
- What happens when the add method is called with an entry that is already on the list?
- it inserts the entry before the first occurrence
- it inserts the entry after the last occurrence
- it throws a NodeConflictException
- it ignores the entry and returns true
- If a list contains seven duplicate objects on a list and you remove one of them, which one is removed?
- the first one
- the second one
- the seventh one
- it is nondeterministic
- In the link-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the add(newEntry) method?
- O(n2)
- O(n)
- O(log n)
- O(1)
- In the array-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the add(newEntry) method?
- O(n)
- O(n2)
- O(log n)
- O(1)
- In the link-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the remove(givenPosition) method?
- O(n)
- O(n2)
- O(log n)
- O(1)
- In the array-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the remove(givenPosition) method?
- O(n)
- O(n2)
- O(log n)
- O(1)
- In the link-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the getEntry(givenPosition) method?
- O(n)
- O(n2)
- O(log n)
- O(1)
- In the array-based list implementation of the ADT sorted list, what is the worst-case time efficiency of the getEntry (givenPosition) method?
- O(1)
- O(n2)
- O(log n)
- O(n)
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano
Test Bank
General
View Product →
Explore recommendations drawn directly from what you're reading
Quick Navigation
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