Data Structures Test 2

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

6.2) It is an error to dequeue data from a(n) _______ queue. Empty Array-based Linked Full

Empty

6.2) It is an error to pop data from a(n) _______ stack. Linked Array-based Empty Full Initialized

Empty

7.3) In order to do an exact-match search, the key values must define a total order True False

False

7.3) One good general-purpose solution to the problem of getting a key from a record is to define a special method such as ".key()" True False

False

7.3) {Most programming languages will let us re-define "<" and ">" to handle comparison of arbitrary objects| We can generally rely on "<" and ">" to let us compare arbitrary record types} True False

False

7.5) Selection 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 False

False

6.2) The Stack is best characterized as: First come, First Served Just-in-Time First-In, First-Out Last-In, First-Out

Last-In, First-Out

6.2) One difference between a queue and a stack is: Queues use two ends of the structure; stacks use only one Queues require linked lists, but stacks do not Stacks use two ends of the structure, queues use only one Stacks require linked lists, but queues do not

Queues use two ends of the structure; stacks use only one

6.2) Stack A has entries a, b, c (in that order with a on top), while Stack B is initially empty. When an entry is popped out of stack A, it can be printed immediately or pushed to stack B. When an entry is popped out of stack B, it can only be printed. Which of the following permutations of a, b, c is not possible to print? c a b b c a b a c a b c

c a b

7.4) What is the best-case time for Insertionsort to sort an array of n records? Θ(nlogn) Θ(logn) Θ(n​^2​​) Θ(n)

Θ(n)

7.4) What is the running time of Insertion Sort when the input is an array that has already been sorted? Θ(n) Θ(n​^2​​) Θ(logn) Θ(nlogn)

Θ(n)

7.4) What is the running time of Insertion Sort when the input is an array where all record values are equal? Θ(n​^2​​) Θ(n) Θ(n​^n​​) Θ(logn) Θ(nlogn)

Θ(n)

7.4) If I is the number of inversions in an input array of n records, then Insertion Sort will run in what time? Θ(I) Θ(I−n) Θ(n^​2​​) Θ(n+I)

Θ(n+I)

7.6) What is the worst-case time for Bubble Sort (as the algorithm is presented in this module) to sort an array of n records? Θ(n^​2​​) Θ(nlogn) Θ(n​​) Θ(logn) Θ(n)

Θ(n^​2​​)

7.4) What is the average-case time for Insertion Sort to sort an array of n records? Θ(nlogn) Θ(n​^2​​) Θ(n) Θ(logn)

Θ(n​^2​​)

7.4) What is the worst-case time for Insertion Sort to sort an array of n records? Θ(nlogn) Θ(n​^2​​) Θ(n) Θ(logn)

Θ(n​^2​​)

7.4) When implementing Insertion Sort, a binary search could be used to locate the position within the first i-1i−1 records of the array into which record ii should be inserted. In this implementation, the worst case time will be: Θ(n) Θ(logn) Θ(n​^2​​) Θ(nlogn)

Θ(n​^2​​)

7.5) What is the best-case time for Selection Sort to sort an array of n records? Θ(logn) Θ(n) Θ(nlogn) Θ(n​^2​​)

Θ(n​^2​​)

7.5) What is the running time of Selection Sort when the input is an array that has all equal values? Θ(logn) Θ(n​^2​​) Θ(nlogn) Θ(n)

Θ(n​^2​​)

7.5) What is the worst-case time for Selection Sort to sort an array of n records? Θ(nlogn) Θ(n​^2​​) Θ(n) Θ(logn)

Θ(n​^2​​)

7.6) What is the best-case time for Bubble Sort (as the algorithm is presented in this module) to sort an array of nn records? Θ(nlogn) Θ(n) Θ(n​^2​​) Θ(nn​​) Θ(logn)

Θ(n​^2​​)

7.6) What is the running time for Bubble Sort when the input array has values that are in reverse sort order? Θ(nlogn) Θ(n​^2​​) Θ(logn) Θ(n)

Θ(n​^2​​)

7.6) 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? Θ(nlogn) Θ(n​^2​​) Θ(logn) Θ(n)

Θ(n​^2​​)

7.6) What is the running time of Bubble Sort when the input is an array where all record values are equal? Θ(nlogn) Θ(n​^2​​) Θ(logn) Θ(n)

Θ(n​^2​​)

7.4) In the worst case, the total number of comparisons for Insertion Sort is closest to: (n^2)/2 n n^2​​ nlogn

(n^2)/2

7.5) In the worst case, the total number of comparisons for Selection Sort is closest to: n^2 (n^2)/4 (n^2)/2 n n-1

(n^2)/2

7.6) In the worst case, the total number of comparisons for Bubble Sort is closest to: 2n^2 2n^2 (n^2)/2 (n^2)/4 n/2 n^2​​ n/4 n

(n^2)/2

6.2) The following sequence of operations is performed on a queue: enqueue(1), enqueue(2), dequeue, enqueue(1), enqueue(2), dequeue, dequeue, dequeue, enqueue(2), dequeue. The values will be output in this order: 1,2,1,1,2 2,1,2,2,1 2,1,2,2,2 1,2,1,2,2 2,2,1,2,2 2,2,1,1,2

1,2,1,2,2

7.5) Suppose that Selection Sort is given an input of 100 records, and it has completed 46 iterations of the main loop. How many records are now guaranteed to be in their final position (never to be moved again by the sort)?

46

6.2) If the characters 'D', 'C', 'B', 'A' are placed in a stack (in that order), and then removed one at a time, in what order will they be removed? DCAB DCBA ABCD ABDC

ABCD

7.2) Which of these is the best definition for a stable sorting algorithm? An algorithm that is as fast as the best one known An algorithm that always gives the right answer An algorithm that always gives the same order for duplicate keys from run to run An algorithm that does not change the relative ordering of records with identical keys

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

7.4) 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 None of the above

Both of the above

6.2) If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? DCBA DCAB ABDC ABCD

DCBA

6.2) It is an error to enqueue data onto a(n) _______ queue. Empty Linked Full Initialized Array-based

Full

6.2) It is an error to push data onto a(n) _______ stack. Linked Empty Array-based Initialized Full

Full

7.5) The order of the input records has what impact on the number of comparisons required by Selection Sort (as presented in this module)? There is a constant factor difference None There is a big difference, the asymptotic running time can change

None

7.6) The order of the input records has what impact on the number of comparisons required by Bubble Sort (as presented in this module)? There is a big difference, the asymptotic running time can change There is a constant factor difference None

None

7.4) 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 ii should be inserted. Using binary search will: None of these answers is correct Not speed up the asymptotic running time because shifting the records to make room for the insert will require Θ(i) time Speed up the asymptotic running time because the position to insert will be found in Θ(logi) time Speed up the asymptotic running time because shifting the records to make room for the insert will require Θ(i) time

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

6.2) In the linked implementation of a queue, a new item would be added to the: Front None of these Rear Current Position

Rear

7.5) Which statement best characterizes Selection Sort (as the code is written in this module)? Recall that a stable sorting algorithm maintains the relative order of records with equal keys. Selection Sort is stable Selection Sort is not stable Selection Sort is not stable, but with minor modifications it could be made so

Selection Sort is not stable, but with minor modifications it could be made so

7.2) Which of these will NOT affect the RELATIVE running times for two sorting algorithms? The allowable range for the record values The CPU speed The amount by which the values are out of order The number of records

The CPU speed

7.4) When is Insertion Sort a good choice for sorting an array? None of these situations The array contains only a few records Each record requires a small amount of memory The array contains many records

The array contains only a few records

7.4) When is Insertion Sort a good choice for sorting an array? Each record requires a small amount of memory The array has only a few records out of sorted order The processor speed is fast We need a reasonably fast algorithm with a good worst case

The array has only a few records out of sorted order

7.3) Defining a record's key field is a property of: The record The context of the search Both Neither

The context of the search

6.2) Which value of a queue is accessible? The highest-valued item The root The rear item The bottom item The lowest-valued item The top item The front item

The front item

7.2) Which of these is a traditional measure for the cost of a sorting algorithm? The number of comparisons The amount by which the values are out of order The memory size The number of records

The number of comparisons

7.2) Which of these is a traditional measure for the cost of a sorting algorithm? The memory size The amount by which the values are out of order The number of records The number of swaps

The number of swaps

6.2) Which value of a stack is accessible? The front item The bottom item The root The rear item The top item The lowest-valued item The highest-valued item

The top item

7.4) The order of the input records has what impact on the number of comparisons required by Insertion Sort (as presented in this module)? None There is a big difference, the asymptotic running time can change There is a constant factor difference

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

7.6) When is Bubble Sort a good choice for sorting an array? The array has only a few items out of place Each component of the array requires a small amount of memory Each component of the array requires a large amount of memory There is no situation where Bubble Sort is the best choice over all of the others in this chapter

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

7.3) In order to be able to sort, the key values must define a total order True False

True

7.3) One good general-purpose solution to the problem of getting a key from a record is to store Key/Value pairs in the search structure True False

True

7.3) The problem with using a ".key()" method to get the key from a record is that we can't use this same method to get different fields for different searches True False

True

7.4) 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 False

True

7.5) Selection sort is simple, but less efficient than the best sorting algorithms. True False

True

7.6) 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 False

True

7.5) When is Selection Sort a good choice to use for sorting an array? None of these answers When the array has only a few elements out of place When the cost of a swap is large, such as when the records are long strings When each component of the array requires a small amount of memory

When the cost of a swap is large, such as when the records are long strings

7.2) Sometimes, the constant factors in an algorithm's runtime equation are more important than its growth rate. When the problem is sorting, this can happen in which situation? When there are lots of records When the records are nearly sorted When the CPU is really fast When the records are nearly reverse sorted When we are sorting lots of small groups of records. When the amount of available space is small

When we are sorting lots of small groups of records.

7.4) In which cases are the growth rates the same for Insertion Sort? Worst and Best only Worst, Average, and Best Worst and Average only Best and Average only

Worst and Average only

7.5) In which cases are the time complexities the same for Selection Sort? Worst and Best Best and Average Worst and Average Worst, Average and Best

Worst, Average and Best

7.6) In which cases are the time complexities the same for Bubble Sort (as the algorithm is presented in this module)? Worst and Average Worst and Best Worst, Average and Best Best and Average

Worst, Average and Best

7.5) In the average case, the total number of swaps done by Selection Sort is closest to: nlogn (n^2)/2 n n^2

n

7.5) In the worst case, the total number of swaps done by Selection Sort is closest to: (n^2)/2 n^2​​ nlogn n

n

7.5) In the worst case, the total number of swaps done by Selection Sort is closest to: n^2 (n^2)/2 nlogn n

n

7.5) How many times does Selection Sort call the swap function on an array of n records? n^2 n-1 1 It depends on the order of the records n nlogn

n-1


Kaugnay na mga set ng pag-aaral

UNIT 12- Civil Rights Movement, 1960s, & the Vietnam War Ch. 25,26,27

View Set

Liste de pays et capitales pour géo

View Set

Skin Integrity and Wound Care PREPU

View Set

作文好词好句 高兴 & 生气

View Set