CS 5B (Test-Like Questions)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following statements about the BinarySearch algorithm is NOT true? The worst case run time is O(n). The algorithm can be implemented iteratively or recursively. The best case run time is O(1). The algorithm runs in O(log n) time.

The worst case run time is O(n).

In BinarySearch, the best case occurs when: The item is located next to the middle item in the collection. The item is located at the very beginning of the collection. The item is located in the middle of the collection. e very end of the collection.

The item is located in the middle of the collection.

Assume values is an array of integers that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 After transforming the array into a heap, what is the contents of the array? 18, 12, 8, 9, 6, 2, 4 2, 4, 8, 9, 6, 12, 18 18, 6, 12, 2, 4, 8, 9 18, 12, 9, 8, 6, 2, 4

18, 6, 12, 2, 4, 8, 9

In general, how many different ways are there to search for a specific item within a collection of items? 1 4 2 3

2

We used an argument that involved a decision tree to prove that any comparison sort (like insertion sort or quicksort) has worst-case time complexity that is Ω(n log n). Which of the following statements are true about this lower-bounds argument? A. The internal nodes (i.e. non-leaf nodes) of the decision tree represent a comparison between two items in the list. B. The decision tree must have n(n-1)/2 leaves because that is the maximum number of inversions for a list of size n. C. The worst-case number of comparisons the sort must do is the length of the longest possible path from the root to a leaf. A and C are true Only A is true A and B are true Only C is true Only B is true B and C are true

A and C are true

What is the worst-case time for quicksort to sort an array of n elements? O(n) O(n log n) O(log n) O(n²)

Correct Answer O(n²)

Which of the following sorts always has a run time of O(n2)? Heap sort Selection sort Bubble sort Insertion sort

Correct Answer Selection sort

Which of the following data structures would be most appropriate (i.e., most efficient) for an application that is required to: Add "observed" words. Add "known" words. Return how many "observed" words are present in "known". HashSet TreeMap HashMap TreeSet Priority Queue

Correct Answer HashSet

What is the worst-case time for mergesort to sort an array of n elements? O(n log n) O(n) O(n²) O(log n)

Correct Answer O(n log n)

To utilize the built-in sorting functions of Java supplied frameworks, a class must implement sort Comparable Comparator compare

Comparable

Which of the following statements about merge or Mergesort are true? A. Mergesort is a stable sort because, if there are two identical values in the first and second sublist being merged, it is simple for merge to make sure the value in the first sublist is copied to the merged list before the second value is copied. B. Mergesort will always use merge to combine two sublists that have equal sizes or sublists where one sublist has one more item than the other. C. When merge finds there is not another element in the first sublist to compare to an element in the second sublist, it will always need to copy the remaining elements from the second sublist into the merged array. Only A is true A and B are true B and C are true A and C are true Only B is true A, B, and C are true

Correct Answer A, B, and C are true

Which of the following are TRUE statements about the time-complexity of QuickSort? A. If the input is sorted in random order, this will always lead to the worst-case for quicksort. B. If the input is sorted in ascending order, this may lead to the worst-case for quicksort depending on how partition is implemented. C. We'll get a Θ(n2) time complexity for quicksort if partition always uses a partition value that is the maximum value element in the sublist being processed. Only A is true Only B is true B and C are true A and B are true Only C is true A and C are true

Correct Answer B and C are true

Which of the following statements is TRUE about the biggest difference between the two different implementations of HeapSort we saw in class? **Solution 1 involved push() to the heap n times and then poll() from the heap n times. Solution 2 used a two-step process to transform the collection into a heap and then removing from the heap n-1 times. Solution 1 is a stable sort but Solution 2 is not. Solution 1 is not an in-place sort but Solution 2 is. Solution 2 requires one less call to poll(). There is essentially no difference between the 2 solutions.

Correct Answer Solution 1 is not an in-place sort but Solution 2 is.

The following multiple choice items explain the lower bounds argument covered in class that shows adjacent sorts must have a worst-case complexity of Ω(n2), but one of the steps contains an error. Select the item containing the error. An inversion is two items in a list that are out of relative order The maximum number of inversions in a list is n + (n-1)*2 Each swap of two adjacent elements can fix at most one inversion Therefore, if only one inversion is removed per operation, any algorithm is Θ(n2) or higher Step 4 Step 1 Step 3 Step 2

Correct Answer Step 2

Which of the following is NOT true about the second, more difficult implementation of HeapSort we saw in class? **We are talking about the solution in which the list you want to sort is used as the heap itself. We are NOT talking about the version in which you push() to the heap n times and then poll() from the heap n times. This implementation is stable, because we always make sure to percolate items with the same key up past its parent only if the child element is a "left child". This implementation makes use of the heapify() method, because the list must be converted to a heap first. This implementation does not discard the item that is removed from the heap, but rather places at the back of the array (list) to place it in sorted order. This implementation uses a max-heap instead of a min-heap when sorting the list in ascending order. This implementation is truly in-place, as it does not use recursion and doe

Correct Answer This implementation is stable, because we always make sure to percolate items with the same key up past its parent only if the child element is a "left child".

If two threads are not sharing data, a race condition cannot exist True False

Correct Answer True

Assume values is an array of integers that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 Which of the following lists of numbers would accurately show the array after the fourth pass of Bubble sort? 4, 2, 8, 6, 9, 12, 18 4, 2, 9, 6, 8, 12, 18 2, 4, 6, 8, 9, 12, 18 4, 2, 6, 8, 9, 12, 18 4, 9, 2, 6, 8, 12, 18

Correct! 2, 4, 6, 8, 9, 12, 18

A vector contains the numbers <7, 2, 9, 5, 4, 1> and Insertion Sort is run on this list. Which of the following list orderings will never occur during any step of the sorting process? We are only concerned with the state of the list at the beginning of each iteration of the outer loop (after each element is fully "inserted"). 1, 2, 4, 5, 7, 9 2, 5, 7, 9, 4, 1 2, 4, 5, 7, 9, 1 2, 7, 9, 5, 4, 1 2, 7, 9, 4, 5, 1

Correct! 2, 7, 9, 4, 5, 1

Considering the relationship between a Process and a Thread Processes and Threads are unrelated A Process can contain multiple Threads A Thread can contain multiple Processes

Correct! A Process can contain multiple Threads

Assume we're calling Partition on an array with integer values from 0 to 6. When Partition is finished, it will have re-arranged the items in the array, and it will return an index in the array where the partition value is now located. Each of the items A-D below show an arrangement of the items in the array, the index of the partition value, and its value. Which of these are valid values that could be the result of executing a correctly implemented Partition algorithm? (Note: the index of the first item is 0, as we always do for Java arrays.) A. {0, 1, 2, 3, 4, 5, 6}, index=3, partition value=3 B. {1, 0, 2, 3, 6, 5, 4}, index=3, partition value=3 C. {1, 0, 3, 6, 2, 4, 5}, index=2, partition value=3 D. {4, 0, 3, 1, 2, 6, 5}, index=0, partition value=4 A and B are both valid All except D are valid Only B is valid All except C are valid Only A is valid B and C are valid

Correct! A and B are both valid

Which of the following statements about QuickSort and Mergesort are true? A. Mergesort is not an example of the divide and conquer algorithm design strategy because it only does Θ(1) work to divide the problem into two subproblems. B. Quicksort has a better space-complexity than mergesort because partition() has space-complexity of Θ(1) while merge() has space-complexity of Θ(n). C. Both sorts can be made into hybrid sorts by using a non-recursive sort like insertion sort to process subproblems smaller than a certain size. B and C are true Only B is true A and C are true A and B are true Only A is true Only C is true

Correct! B and C are true

Which of the following data structures would be most appropriate (i.e., most efficient) for an application that is required to: Add numbers. Remove the minimum number. Remove the maximum number. ArrayList BinarySearch Tree Linked List Hash Table Priority Queue

Correct! BinarySearch Tree

Which of the following data structures would be most appropriate (i.e., most efficient) for an application that is required to: Add a post written by a given user. Undo the last post written by a given user. Return a list of all posts written by a given user in the order that they were added. Stack Queue Linked List ArrayList AVL Tree

Correct! Linked List

MergeSort can be described as a typical ________________________ algorithm. divide and conquer division in-place sorting recursive with multiple base cases

Correct! divide and conquer

When a new Thread is instantiated from a Java program, that Thread will terminate when the run method supplied with the Runnable object completes the Thread is interrupted at the end of the main method that started the Java program at the end of the method that instantiates the Thread

Correct! the run method supplied with the Runnable object completes


संबंधित स्टडी सेट्स

CCNA1 v7 - ITN - Modules 1 - 3: Basic Network Connectivity and Communications Exam Answers

View Set

chapter 6-8: Budgeting, cost allocation and practices

View Set

Research Methods in Psyc; Chapter 5: Identifying Good Measurements, Chapter 6 - Surveys & Observations: Describing What People Do

View Set

Chapter 34: Management of Patients with Hematologic Neoplasms

View Set

Mathematics Knowledge ASVAB, AVSAB Mathematics Knowledge

View Set