Quiz 5B Questions DSA

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

Select all of the following TRUE statements about QuickSort.

QuickSort easily lends itself to be a hybrid sort. QuickSort is usually implemented as a recursive algorithm. QuickSort is considered the fastest average time sort.

Which of the following is NOT true about using the compareTo() method in Java to sort things?

You could rewrite the body of your compareTo() method in order to sort a list in descending order instead of ascending order.

MergeSort can be described as a typical ________________________ algorithm.

divide and conquer

Considering the relationship between a Process and a Thread

A Process can contain multiple Threads

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 Selection sort?

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

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 Insertion sort?

2, 4, 6, 9, 12, 8, 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").

2, 7, 9, 4, 5, 1

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

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

Which of the following data structures would be most appropriate (i.e., most efficient) for an application that is required to: 1. Add numbers. 2. Remove the minimum number. 3. Remove the maximum number.

BinarySearch Tree

Which of the following data structures would be most appropriate (i.e., most efficient) for an application that is required to: 1. Add words. 2. Return a list of all the unique words in alphabetical order. 3. Return the number of times a given word has been added.

BinarySearch Tree

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

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

HashSet

Select all of the following TRUE statements about HeapSort.

HeapSort can be implemented with either a min or a max heap.

Select all of the following TRUE statements about MergeSort.

MergeSort is usually implemented as a recursive algorithm. MergeSort is a stable sort. MergeSort easily lends itself to be a hybrid sort. MergeSort is generally not an in-place sort.

What is the worst-case time for heapsort to sort an array of n elements?

O(n log n)

What is the worst-case time for mergesort to sort an array of n elements? You Answered

O(n log n)

For linear or sequential search, the average case time performance is:

O(n)

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 not an in-place sort but Solution 2 is.

In BinarySearch, the best case occurs when:

The item is located in the middle of the collection.

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. 1. An inversion is two items in a list that are out of relative order 2. The maximum number of inversions in a list is n + (n-1)*2 3. Each swap of two adjacent elements can fix at most one inversion 4. Therefore, if only one inversion is removed per operation, any algorithm is Θ(n2) or higher

Step 2

In BinarySearch, the worst case occurs when: (select all that apply)

The item is not in the collection. The item is located at the very beginning of the collection. The item is located at the end of the collection.

Let P be a QuickSort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds TRUE?

t1 > t2

A race condition, essentially, is when

the order the threads complete determines the outcome of the program.

What course of action should be followed when a thread has been interrupted (due to an exception)?

the thread should execute the code in the appropriate catch block


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

Chapter 39: Caring for Clients With Head and Spinal Cord Trauma

View Set

Mood Disorders, CONVERSION DISORDER, post-traumatic stress disorder (PTSD), Chapter 15 Psychological Disorders, Psychology vocab ch. 12, psychological disorders, Schizophrenia, Psych: Module 4

View Set

Chapter 15: An Overview of Growth, Development, and Nutrition

View Set

3.13: Unit Test: How important Ideas are Expressed

View Set