CS 2114: weeks 10-14

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

root

In a tree, topmost node of the tree

leaf

a node that has no children

Compare the Interface specifications for the List and Sorted List Abstract Data Types then answer the following questions. The relevant interface files are provided via the first page of the module - Introduction to sorted lists. Which of the following are true? (Select all of that apply) a.) ListInterface includes the method definition, add(int newPosition, T newEntry), while SortedListInterface does not b.) ListInterface includes the method definition, T replace(int givenPosition, T newEntry), while SortedListInterface does not. c.) SortedListInterface includes an additional remove method definition, boolean remove(T anEntry). d.) The SortedListInterface includes a new method, int getPosition(T anEntry). PreviousNext

a.) ListInterface includes the method definition, add(int newPosition, T newEntry), while SortedListInterface does not b.) ListInterface includes the method definition, T replace(int givenPosition, T newEntry), while SortedListInterface does not. c.) SortedListInterface includes an additional remove method definition, boolean remove(T anEntry). d.) The SortedListInterface includes a new method, int getPosition(T anEntry). PreviousNext

Locating a new node's insertion point in a binary search tree stops when a.) we reach a null child b.) we find a node greater than the node to be inserted c.) we reach the tree's maximum level d.) we find a node lesser than the node to be inserted e.) we find a node without any children

a.) we reach a null child

Which of the following is a possible sequence of calls to get from: barbells, step, weights, mat with an iterator before barbells to: barbells, weights, mat with an iterator between barbells and weights a.) next() b.) next(), remove(), next() c.) next(), next(), remove() d.) next(), remove(), next(), next() e.) next(), next(), remove(), next()

c.) next(), next(), remove()

Based on the insertion sort code traced in the demo. Given an array {15, 2, 46, 3, 10, 9}. What is the state of the array when i = 3 and the call to insertInOrder is complete? a.) {15, 2, 46, 3, 10, 9} b.) {2, 3, 46, 15, 10, 9} c.) {2, 3, 15, 46, 10, 9} d.) {2, 3, 10, 15, 46, 9} e.) {2, 3, 9, 10, 46, 15}

c.) {2, 3, 15, 46, 10, 9}

Given array: private int[] counts = {74, 55, 34, 99, 22} Trace selection sort from the video demo. What does the array look like at the end of the for loop when lh = 2? a.) {74, 55, 34, 99, 22} b.) {22, 55, 34, 99, 74} c.) {22, 34, 55, 99, 74} d.) {74, 34, 55, 99, 22}

c.) {22, 34, 55, 99, 74}

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would a call to next() return? a.) null b.) bicep curls c.) burpees d.) push-ups e.) sit-ups f.) NoSuchElement Exception

d.) push-ups

If an inorder traversal of a complete binary tree visits the nodes in the order ABCDEF (where each letter is the value of a node), which order are the nodes visited during an postorder traversal? Recall that OpenDSA defines a complete binary tree as follows: "A complete binary tree has a restricted shape obtained by starting at the root and filling the tree by levels from left to right. In the complete binary tree of height d, all levels except possibly level d are completely full." a.) ABDECF b.) DEBFCA c.) DBFACE d.) DBACFE e.) ACBEFD

e.) ACBEFD

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would the state of the iterator be after a call to next() ? a.) before bicep curls b.) between bicep curls and burpees c.) between burpees and push-ups d.) between burpees and sit-ups e.) between push-ups and sit-ups

e.) between push-ups and sit-ups

Based on the insertion sort code traced in the demo. Given an array {15, 2, 46, 3, 10, 9}. What is the state of the array when i = 4 and the call to insertInOrder is complete? a.) {2, 3, 9, 46, 15, 10} b.) {2, 3, 15, 46, 10, 9} c.) {2, 3, 10, 46, 15, 9} d.) {2, 3, 9, 10, 46, 15} e.) {2, 3, 10, 15, 46, 9}

e.) {2, 3, 10, 15, 46, 9}

child node

node referenced by another node in a tree

siblings

nodes that have the same parent node

To deep clone an array-based collection, you need to perform 3 levels of cloning: Shallow copy, clone the array object, and deep clone the items stored in the array. a.) true b.) false

a.) true

Both ListInterface and SortedListInterface include the method definition, contains(anEntry). Consider the example implementation of the List contains(anEntry) method presented below. public boolean contains(T anEntry) { boolean found = false ;int index = 0; while (!found && (index < numberOfEntries)) { if (anEntry.equals(list[index])){ found = true; } index++; } // end while return found; } // end contains How could the contains(anEntry) method implementation used for List be improved upon when implementing the contains(anEntry) method for a SortedList? a.) The contains method could be written so that it stops searching the List for anEntry when it passes the location where anEntry should be found if stored within a SortedList. b.) The contains method implementation could start searching through the List from index list.getLength() - 1 instead of 0. c.) The contains method implementation could start searching through the List from index 1 instead of 0. d.) The contains method implementation could start searching through the List from index list.getLength() instead of 0.

a.) The contains method could be written so that it stops searching the List for anEntry when it passes the location where anEntry should be found if stored within a SortedList.

Which of the following are valid approaches to implementing a SortedList? (select all that apply) a.) Write it from scratch, most of the methods implemented similarly to the List implementation, some methods removed, added, or updated to ensure that the List remains in sorted order b.) Use composition, where a SortedList uses a List as a field, with other attributes and methods to supported the SortedList features c.)Use inheritance, where a SortedList is a child (subclass) of a List (superclass). Attributes and methods are inherited, methods overridden and updated to ensure that the List remains in sorted order. Methods which do not suit the sorted requirement are be overridden with code which throws an Exception if called

a.) Write it from scratch, most of the methods implemented similarly to the List implementation, some methods removed, added, or updated to ensure that the List remains in sorted order b.)Use composition, where a SortedList uses a List as a field, with other attributes and methods to supported the SortedList features c.) Use inheritance, where a SortedList is a child (subclass) of a List (superclass). Attributes and methods are inherited, methods overridden and updated to ensure that the List remains in sorted order. Methods which do not suit the sorted requirement are be overridden with code which throws an Exception if called

The clone() method defined in the Object class performs: a.) a shallow copy b.) a deep copy c.) both d.) none of the above

a.) a shallow copy

One approach to implementing a SortedList is through inheritance, creating a subclass of the List class then overriding the relevant methods to ensure that the List remains in sorted order. Which of the following inherited List methods MUST be overridden to ensure that sorted order is preserved? (select all that apply) a.) add(newEntry) b.) add(newPosition, newEntry) c.) clear() d.) remove(givenPosition) e.) replace(givenPosition, newEntry) f.) contains(anEntry)

a.) add(newEntry) b.) add(newPosition, newEntry) e.) replace(givenPosition, newEntry)

The fact that an iterator keeps its place within a list is a a.) benefit because it saves work and improve efficiency b.) risk because the data flow may change direction c.) benefit because the last item always stays the same d.) risk because the next item may not be needed

a.) benefit because it saves work and improve efficiency

Suppose you have a binary search tree with no left children. Duplicate keys are not allowed. Which of the following explains how this tree may have ended up this way? a.) it was filled in ascending order b.) the root value was the maximum c.) all keys were identical d.) the tree is a preorder tree e.) it was filled in descending order

a.) it was filled in ascending order

What does the compare method of a comparator object return when the first parameter is less than the second? a.) less than 0 b.) greater than 0 c.) 0 d.) true e.) false

a.) less than 0

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node:If a binary tree n nodes that either have 0 or 2 children and all leaves on the same level, what is the height of the tree? a.) log2(n+1) b.) log2(n-1) c.) 2^n d.) 2^(n+1) e.) 2^(n-1)

a.) log2(n+1)

A risk of multiple iterators a.) one iterator makes a change that another doesn't know about b.) they run into each other c.) one removes another inadvertently d.) they may both return the same value when next() is called

a.) one iterator makes a change that another doesn't know about

This sorting algorithm starts by finding the smallest value in the entire array. Then it finds the second smallest value, which is the smallest value among the remaining elements. Then it finds the third smallest value, the fourth, and so on. a.) selection sort b.) insertion sort c.) bubble sort d.) quick sort e.) merge sort

a.) selection sort

A ListIterator provides a superset of the functionality that an Iterator provides. a.) true b.) false

a.) true

An enhanced for statement can be programmed manually using a call to the iterator() method and calling the hasNext() and next() methods of the returned iterator. a.) true b.) false

a.) true

Based on the find method traced in the video, it depends on T extending Comparable. a.) true b.) false

a.) true

Based on the find method traced in the video, it is a recursive method. a.) true b.) false

a.) true

Binary search trees with no duplicate entries have nodes with 0,1, or 2 children . a.) true b.) false

a.) true

Deep copy for an object means performing a shallow copy plus copying all of the mutable objects inside the object. a.) true b.) false

a.) true

For binary search trees with no duplicate entries, entries in the left subtree of a node are less than the entry in the node. a.) true b.) false

a.) true

For binary search trees with no duplicate entries, entries in the right subtree of a node are greater than the entry in the node. a.) true b.) false

a.) true

The next method needs to be called for each time the remove method is called in order to avoid an exception being thrown. a.) true b.) false

a.) true

Select the best choice below to fill in the blanks: When a __________ implements Comparable, the __________ named ____________ must be implemented. a.) method, class, compareTo b.) class, method, compareTo c.) generic, object, compareTo d.) generic, type, compareTo

b.) class, method, compareTo

A class that implements Iterator will have a compile time error if it does not implement a remove method a.) true b.) false

b.) false

Based on the find method traced in the video, it depends on data extending Comparator. a.) true b.) false

b.) false

Based on the find method traced in the video, it is an equals method for binary search trees. a.) true b.) false

b.) false

Based on the find method traced in the video, it throws an exception when data is not found. a.) true b.) false

b.) false

Binary search trees with no duplicate entries have all leaves on the second level. a.) true b.) false

b.) false

Binary search trees with no duplicate entries have nodes with exactly two children . a.) true b.) false

b.) false

For binary search trees with no duplicate entries, entries in the left subtree of a node are greater than the entry in the node. a.) true b.) false

b.) false

For binary search trees with no duplicate entries, entries in the right subtree of a node are less than the entry in the node. a.) true b.) false

b.) false

Shallow copy for an object means creating a new instance of the object containing a copy of all of its instance variables references. a.) true b.) false

b.) false

What is not true about a binary search tree? a.) it is a binary tree b.) if there are n nodes, then its height is n/2 c.) the leftmost node is the smallest node in the tree d.) when printed with inorder traversal, it will be sorted

b.) if there are n nodes, then its height is n/2

Which of the following BEST completes the statement An iterator ______________ a.) is loop variable b.) is an object that traverses a collection c.) can be used to consider each data item in a collection once d.) can be used to insert an item into a collection

b.) is an object that traverses a collection

Based on the insertion sort code traced in the demo for a linked chain. Given a linked chain containing 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128, what is the state of the linked chain at the end of the second time through the while loop in insertionSort? a.) 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128 b.) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128 c.) 4 -> 8 -> 16 -> 32 -> 256 -> 64 -> 128 d.) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128 e.) 4 -> 8 -> 16 -> 32 -> 64 -> 128 -> 256

b.) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128

If you attempt to call the clone method on an object that doesn't implement the Cloneable interface a.) nothing will happen b.) A CloneNotSupportedException will be thrown c.) the clone() method will only preform a shallow copy

b.) A CloneNotSupportedException will be thrown

Insertion sort on an array is requires (select all that apply): a.) Comparison of each unsorted item to all the currently sorted items b.) Comparison of each unsorted item to enough currently sorted items to find its insertion point c.) Comparison of each unsorted item to its neighbor until finding its insertion point d.) Shifting of all sorted items to make room for subsequent unsorted items e.) Shifting of sorted items above each unsorted item's insertion point

b.) Comparison of each unsorted item to enough currently sorted items to find its insertion point e.) Shifting of sorted items above each unsorted item's insertion point

When using the runner technique on a singly linked chain to insert an item in order, both prev and curr nodes are used in order to (select all that apply): a.) Reverse the order of the items b.) Insert an item before the node that curr references c.) Loop through the items in the chain to find the insertion location d.) Have access to multiple nodes in order to swap them

b.) Insert an item before the node that curr references c.) Loop through the items in the chain to find the insertion location

Suppose you have a sorted list of numbers stored in a Java array of ints. What is the worst-case time complexity of searching for a given number in the list using binary search? a.) O(1) b.) O(log n) c.) O(n) d.) O(n log n) e.) O(n^2)

b.) O(log n)

Which of the following possible reasons BEST explains why a SortedList implementation would not need the method, add(int newPosition, T newEntry)? a.) The contains method could be used instead. b.) The SortedList add(newEntry) method has the responsibility of adding new entries in sorted order, as a result Client code would no longer be required to, or be allowed to, specify the location of the new entries by using add(int newPosition, T newEntry). c.) The behavior achieved through the add(int newPosition, T newEntry) could also be achieved by combining other SortedList methods. d.) To reduce the number of lines of code required

b.) The SortedList add(newEntry) method has the responsibility of adding new entries in sorted order, as a result Client code would no longer be required to, or be allowed to, specify the location of the new entries by using add(int newPosition, T newEntry).

What is the main benefit of implementing a SortedList by inheriting from a revised List Base class instead of inheriting from the standard List Base class? a.) The revised List Base class can be set up so that inefficient methods - like contains(newEntry) and getPosition(newEntry) - cannot be inherited by subclasses b.) The revised List Base class can be set up so that unwanted methods - like add(newPosition, newEntry) and replace(givenPosition, newEntry) - cannot be inherited by subclasses c.) Methods like add(newPosition, newEntry) and replace(givenPosition, newEntry) would be inherited, client code can use these methods in a manner that affects the sorted order d.) The contains(newEntry) and getPosition(newEntry) would be inherited, client code can use these inefficient methods

b.) The revised List Base class can be set up so that unwanted methods - like add(newPosition, newEntry) and replace(givenPosition, newEntry) - cannot be inherited by subclasses

You've got a class that holds two ints and that can be compared with other IntPair objects: class IntPair { private int a; private int b; public IntPair(int a, int b) { this.a = a; this.b = b; } public int compareTo(IntPair other) { if (a < other.a) { return -1; } else if (a > other.a) { return 1; } else { if (b == other.b) { return 0; } else if (b > other.b) { return -1; } else { return 1; } } } } Let's denote new IntPair(5, 7) as [5 7]. You've got a list of IntPairs: [3 7], [4 6], [3 4] You sort them using IntPair.compareTo. What is their sorted order? a.) [3 4], [3 7], [4 6] b.) [3 7], [3 4], [4 6] c.) [4 6], [3 7], [3 4] d.) [4 6], [3 4], [3 7]

b.) [3 7], [3 4], [4 6]

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would be the state of the iterator after a first call to next()? a.) before bicep curls b.) between bicep curls and burpees c.) between burpees and lunges d.) between sit-ups and squats e.) between squats and tricep dips f.) after tricep dips

b.) between bicep curls and burpees

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would a first call to next() return? a.) null b.) bicep curls c.) burpees d.) squats e.) tricep dips f.) NoSuchElement Exception

b.) bicep curls

Given the method header: public<T extends Comparable<? super T>> int binarySearch( T[] ray, T target) Which would be the best header for a helper method? a.) private <T> int binarySearchHelper( T[] ray, T target, int first, int last) b.) private <T extends Comparable<? super T>> int binarySearchHelper(T [] ray, T target, int first, int last) c.) public <T extends Comparable<? super T>> int binarySearchHelper(T [] ray, T target, int first, int last)

b.) private <T extends Comparable<? super T>> int binarySearchHelper(T [] ray, T target, int first, int last)

Chris implements a standard sorting algorithm that sorts the numbers 64, 25, 12, 22, 11 like so: 64 25 12 22 11 11 25 12 22 64 11 12 25 22 64 11 12 22 25 64 11 12 22 25 64 Which sorting algorithm is this? a.) insertion sort b.) selection sort c.) bubble sort d.) merge sort

b.) selection sort

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would be the state of the list after the following sequence of iterator calls: next(), remove(), next(), remove()? a.) bicep curls, burpees, push-ups, sit-ups, squats, tricep dips b.) bicep curls, sit-ups, squats, tricep dips c.) bicep curls, burpees, squats, tricep dips d.) IllegalStateException

c.) bicep curls, burpees, squats, tricep dips

This is a notoriously inefficient algorithm traditionally taught to introduce sorting algorithms: a.) quick sort b.) merge sort c.) bubble sort d.) selection sort e.) insertion sort

c.) bubble sort

This sorting algorithm repeatedly examines neighboring elements, swapping those pairs that are out of order. a.) selection sort b.) insertion sort c.) bubble sort d.) quick sort e.) merge sort

c.) bubble sort

Given the following code skeleton for the private helper method: if (first > last) return ___________________; else { int mid = (first + last) / 2; if (ray[mid].equals(target)) return ___________________; if (ray[mid].compareTo(target) < 0) return ___________________; else return ___________________; } Select the order of the code to fill in the blanks: a.) mid -1 binarySearchHelper(ray,target,first,mid-1) binarySearchHelper(ray,target,mid + 1,last) b.) -1 mid binarySearchHelper(ray,target,first,mid-1) binarySearchHelper(ray,target,mid + 1,last) c.) -1 mid binarySearchHelper(ray,target,mid + 1,last) binarySearchHelper(ray,target,first,mid-1) d.) mid -1 binarySearchHelper(ray,target,mid + 1,last) binarySearchHelper(ray,target,first,mid-1)

c.) -1 mid binarySearchHelper(ray,target,mid + 1,last) binarySearchHelper(ray,target,first,mid-1)

What does the compareTo method return when the calling object and the parameter are equal? a.) less than 0 b.) greater than 0 c.) 0 d.) true e,.) false

c.) 0

Suppose you try to perform a binary search on a 5-element array sorted in the reverse order of what the binary search algorithm expects. How many of the items in this array will be found if they are searched for? a.) 5 b.) 0 c.) 1 d.) 2 e.) 3

c.) 1

Given array: private int[] counts = {7, 12, 3, 56, 11, 9, 18 } And the selection sort from the video demo What is the value of lh when the array is put in this state {3, 7, 9, 11, 56, 12, 18 } a.) 1 b.) 2 c.) 3 d.) 4

c.) 3

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node: If a binary tree of height 5 has nodes that either have 0 or 2 children and all leaves on the same level, how many nodes are in the tree? a.) 7 b.) 15 c.) 31 d.) 63

c.) 31

Suppose you try to perform a binary search on the unsorted array {1, 4, 3, 7, 15, 9, 24}. How many of the items in this array will be found if they are searched for? a.) 3 b.) 4 c.) 5 d.) 6 e.) 0

c.) 5

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node: If a binary tree of height 3 has nodes that either have 0 or 2 children and all leaves on the same level, how many nodes are in the tree? a.) 3 b.) 4 c.) 7 d.) 8

c.) 7

Which of the following are true? (Select all of that apply) a.) The add() method implementation for the List ADT is the same as the add() method implementation for the SortedList ADT b.) Bags are ordered and sorted. Lists are unordered and not necessarily sorted. c.) A SortedList implementation contains code which compares new elements being added to the SortedList to the elements previously added and stored within the SortedList. This comparison helps the add() method code determine the correct position to add the new element so as to preserve sorted order d.) Lists are ordered but not necessarily sorted. List ordering is based on the positions of the elements or Objects within the List, NOT on the value or state of the element or Object

c.) A SortedList implementation contains code which compares new elements being added to the SortedList to the elements previously added and stored within the SortedList. This comparison helps the add() method code determine the correct position to add the new element so as to preserve sorted order d.) Lists are ordered but not necessarily sorted. List ordering is based on the positions of the elements or Objects within the List, NOT on the value or state of the element or Object

Implementing SortedLists using the class definition below would result in which of the following? public class MySortedList> extends MyList implements SortedListInterface a.) MySortedList would inherit all of the methods from SortedListInterface, methods unique to the MyList would need to be implemented, some inherited methods would need to be modified b.) MySortedList would NOT inherit all of the methods from SortedListInterface, all methods would need to be implemented c.) MySortedList would inherit all of the methods from MyList, methods unique to the SortedListInterface would need to be implemented d.) MyList would inherit all of the methods from SortedListInterface, methods unique to the MySortedList would need to be implemented, some inherited methods would need to be modified PreviousNext

c.) MySortedList would inherit all of the methods from MyList, methods unique to the SortedListInterface would need to be implemented

If client code is traversing a list by using an iterator. The efficiency of traversal is: a.) O(1) b.) O(logn) c.) O(n) d.) O(n^2)

c.) O(n)

Suppose you have a list of numbers stored in consecutive locations in a Java array. What is the worst-case time complexity of finding a given element in the array using linear search? a.) O(1) b.) O(log n) c.) O(n) d.) O(n log n) e.) O(n^2)

c.) O(n)

The time complexity of linear search is: a.) O(1) b.) O(logn) c.) O(n) d.) O(2^n) e.) none of the above

c.) O(n)

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would be the state of the list and iterator after three calls to next() and then a call to remove? a.) overhead presses, planks, push-ups, sit-ups, squats, tricep dips b.) bicep curls, burpees, lunges, planks, push-ups, sit-ups, squats, tricep dips c.) bicep curls, burpees, overhead presses, planks, push-ups, sit-ups, squats, tricep dips d.) planks, push-ups, sit-ups, squats, tricep dips

c.) bicep curls, burpees, overhead presses, planks, push-ups, sit-ups, squats, tricep dips

Suppose you try to perform a binary search on the unsorted array {1, 4, 3, 7, 15, 9, 24}. Which element will not be found when you try searching for it? a.) 7 b.) 1 c.) 9 d.) 15 e.) 24

d.) 15

Based on the insertion sort code traced in the demo for a linked chain. Given a linked chain containing 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128, what is the state of the linked chain at the end of the fifth time through the while loop in insertionSort? a.) 4 -> 8 -> 16 -> 64 -> 256 -> 32 -> 128 b.) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128 c.) 4 -> 8 -> 16 -> 32 -> 256 -> 64 -> 128 d.) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128 e.) 4 -> 8 -> 16 -> 32 -> 64 -> 128 -> 256

d.) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128

What is the primary risk of implementing a SortedList by inheriting from the List class? a.) The contains(newEntry) and getPosition(newEntry) would be inherited, client code can use these inefficient methods b.) The clear() method would be inherited but would no longer work, client code using these methods would throw an Exception c.) no risk d.) Methods like add(newPosition, newEntry) and replace(givenPosition, newEntry) would be inherited, client code can use these methods in a manner that affects the sorted order

d.) Methods like add(newPosition, newEntry) and replace(givenPosition, newEntry) would be inherited, client code can use these methods in a manner that affects the sorted order

Java uses quicksort and mergesort under the hood for built-in sorting of arrays and lists. These algorithms have efficiency: a.) O(1) b.) O(n) c.) O(log n) d.) O(n log n) e.) O(n^2)

d.) O(n log n)

If client code is traversing a list by repeatedly using a get method and the underlying structure is a linked chain. The efficiency of traversal is: a.) O(1) b.) O(logn) c.) O(n) d.) O(n^2)

d.) O(n^2)

The time complexity of selection sort is: a.) O(1) b.) O(n) c.) O(n log n) d.) O(n^2) e.) none of the above

d.) O(n^2)

The worst-case time complexity of insertion sort is: a.) O(2) b.) O(n) c.) log(n log n) d.) O(n^2) e.) none of the above

d.) O(n^2)

A method with the header public static double getMax(Iterable<price> prices) can be called with a parameter that is: a.) an array b.) any type that implements Collection c.) from a foreach loop d.) any type that implements Iterable

d.) any type that implements Iterable

Which of the following statements about binary search algorithms is FALSE? a.) the data must be sorted b.) there must be a mechanism to access elements in the middle of the data structure c.) Binary search is inefficient when performed on a linked list d.) binary search can be implemented to take O(1) time in the worst case

d.) binary search can be implemented to take O(1) time in the worst case

Select the best choice below to fill in the blanks: When a __________ implements Comparator, the __________ named ____________ must be implemented. a.) method, class, compare b.) generic, object, compare c.) generic, type, compare d.) class, method, compare

d.) class, method, compare

An enhanced for statement can only be use on data structures that a.) have an iterator field variable b.) starting count at 0 c.) implement Collection d.) implement Iterable

d.) implement Iterable

What are the merits of insertion sort compared to bubble sort and selection sort? a.) it doesn't require as much extra storage b.) it copies elements only to their final locations c.) it requires less code d.) it is faster for already sorted data e.) it can be implement recursively

d.) it is faster for already sorted data

edge

the connection that links two nodes


Kaugnay na mga set ng pag-aaral

Ch 8 Intermediate Accounting Concepts

View Set

Chapter 35 Nursing Diagnosis and Planning

View Set

PSY 3341 (Exam #1 material), PSY 3341 Exam 2 Memory, PSY 3341 - Exam 2

View Set

SIE Mastery Exam 1 Review Questions

View Set

ohio life insurance exam missed questions and answers part 10

View Set