Sorting

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

The array-based implementation for Mergesort uses how many arrays?

2

The order of the input records has what impact on the number of comparisons required by Mergesort (as presented in this module)?

None

When implementing Insertion Sort, a binary search could be used to locate the position within the first i−1 records of the array into which record i should be inserted. Using binary search will:

Not speed up the asymptotic running time because shifting the records to make room for the insert will require Θ(i) time

After Quicksort completes the partition function, where is the pivot?

The last position in the partition

Which of these is a traditional measure for the cost of a sorting algorithm?

The number of comparisons and the number of swaps

The order of the input records has what impact on the number of comparisons required by Insertion Sort (as presented in this module)?

There is a big difference, the asymptotic running time can change

The order of the input records has what impact on the number of comparisons required by Quicksort (as presented in this module)?

There is a big difference, the asymptotic running time can change

When is Bubble Sort a good choice for sorting an array?

There is no situation where Bubble Sort is the best choice over all of the others in this chapter

You must merge 2 sorted lists of size m and n, respectively. The number of comparisons needed in the worst case by the merge algorithm will be:

m + n - 1

In the worst case, the total number of comparisons for Mergesort is closest to:

n log n

How many ways can n distinct values be arranged?

n!

The total number of pairs of records among n records is:

n(n−1)/2

In the worst case, the total number of comparisons for Bubble Sort is closest to:

n^2 / 2

In the worst case, the total number of comparisons for Insertion Sort is closest to:

n^2 / 2

If I is the number of inversions in an input array of n records, then Insertion Sort will run in what time?

Θ(n + I)

What is the average-case time for Mergesort to sort an array of n records?

Θ(n log n)

What is the best-case cost for Quicksort to sort an array of n elements?

Θ(n log n)

What is the running time of Mergesort when the input is an array where all record values are equal?

Θ(n log n)

What is the running time of Insertion Sort when the input is an array that has already been sorted?

Θ(n)

What is the running time of Insertion Sort when the input is an array where all record values are equal?

Θ(n)

What is the worst-case cost for Quicksort's partition step?

Θ(n)

(For the version of the algorithm as presented in this module:) What is the running time of Quicksort when the input is an array where all record values are equal?

Θ(n^2)

The average number of inversions in an array of n records is n(n-1)/4. This is:

Θ(n^2)

What is the best-case time for Bubble Sort (as the algorithm is presented in this module) to sort an array of n records?

Θ(n^2)

What is the running time for Bubble Sort when the input array has values that are in reverse sort order?

Θ(n^2)

What is the running time for Insertion Sort when the input array has values that are in reverse sort order?

Θ(n^2)

What is the running time of Bubble Sort (as the algorithm is presented in this module) when the input is an array that has already been sorted?

Θ(n^2)

What is the running time of Bubble Sort when the input is an array where all record values are equal?

Θ(n^2)

What is the worst-case cost for Quicksort to sort an array of n elements?

Θ(n^2)

What is the worst-case time for Insertion Sort to sort an array of n records?

Θ(n^2)

Which of these will NOT affect the RELATIVE running times for two sorting algorithms? The number of records

The CPU speed

When is Insertion Sort a good choice for sorting an array?

-The array contains only a few records. -The array has only a few records out of sorted order

We know that the worst case for Insertion Sort is about n^2/2 , while the average case is about n^2/4. This means that:

-The growth rates are the same -The runtime in the average case is about half that of the worst case (Both of the above)

Quicksort's worst-case case cost is O(n^2) and its average-case cost is O(n log n). This means that the fraction of input cases with cost O(n^2) must:

Drop as n grows

The order of the input records has what impact on the number of comparisons required by Bubble Sort (as presented in this module)?

None

Which of these is the best definition for a stable sorting algorithm?

An algorithm that does not change the relative ordering of records with identical keys

An exchange sort is:

Any sort where only adjacent records are swapped

In which cases are the time complexities the same for Quicksort?

Best and Average only

(True or False) Consider an array A of n records each with a unique key value, and Ar the same array in reverse order. There are a certain number of pairs, where an arbitrary position i and position j is a pair. Between these two arrays, exactly half of these pairs must be inverted.

False

(True or False) Quicksort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys.

False

If I is the number of inversions in an input array of n records, then {Insertion|Bubble} Sort will require how many swaps?

I

When selecting a pivot value, a simple thing to do is to always pick from the same place in the partition. If we use this approach, does it matter whether we always pick from the first position in the partition, the last position in the partition, or the middle position in the partition?

It is much better to pick the middle value

A disadvantage of Quicksort is:

Its worst-case running time is Θ(n^2)

What is the most complicated part of the Mergesort algorithm?

Merging the sorted halves back together

(True or False) Bubble Sort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys.

True

(True or False) Consider an array A of n records each with a unique key value, and Ar ​​ the same array in reverse order. Any given pair of records must be an inversion in exactly one of A or Ar ​​ .

True

(True or False) Insertion Sort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys.

True

(True or False) Mergesort is easier to implement when operating on a linked list than on an array.

True

When is Mergesort a good choice for sorting an array?

We need a reasonably fast algorithm with a good worst case cost

An inversion is:

When a record with key value greater than the current record's key appears before it in the array

Sometimes, the constant factors in an algorithm's runtime equation are more important thant its growth rate. When the problem is sorting, this can happen in which situation?

When we are sorting lots of small groups of records.

In which cases are the growth rates the same for Insertion Sort?

Worst and Average only

In which cases are the growth rates the same for Insertion sort?

Worst and Average only

In which cases are the time complexities the same for Bubble Sort (as the algorithm is presented in this module)?

Worst, Average and Best

In which cases are the time complexities the same for Mergesort?

Worst, Average and Best


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

Interpersonal Communication Midterm

View Set

Audit Chapter 10, Audit Chapter 11, Auditing Chapter 9, Auditing Chapter 7 - Exam 2

View Set

Fundamentals Nursing Prep U Chapter 23 Asepsis and Infection Control

View Set