Chapter 23 Flashcards
The best-time complexity for insertion sort is _____________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
C.O(n)
The worst-time complexity for insertion sort is _____________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
E.O(n*n)
Suppose a list is {2, 9, 5, 4, 8, 1}. After the first pass of bubble sort, the list becomes
A. 2, 9, 5, 4, 8, 1 B. 2, 9, 5, 4, 1, 8 C. 2, 5, 9, 4, 8, 1 D. 2, 5, 4, 8, 1, 9 E. 2, 1, 5, 4, 8, 9
D.2, 5, 4, 8, 1, 9
The best-time complexity for bubble sort is
_____________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
C.O(n)
The worst-time complexity for bubble sort is _____________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
E.O(n*n)
The time to merge two sorted lists of size n is _________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
C.O(n)
The worst-time complexity for merge sort is _________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
D.O(nlogn)
The average-time complexity for merge sort is _________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
D.O(nlogn)
Suppose you choose the first element as a pivot in the list {5 2 9 3 8 4 0 1 6 7}. Using the partition algorithm in the book, what is the new list after the partition?
A. 5 2 9 3 8 4 0 1 6 7 B. 4 2 3 0 1 5 6 7 9 8 C. 4 2 1 3 0 5 8 9 6 7 D. 2 3 4 0 1 5 9 8 6 7 E. 2 3 4 0 1 5 6 7 8 9
C.
4 2 1 3 0 5 8 9 6 7
The worst-time complexity for quick sort is _________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
E.O(n*n)
The average-time complexity for quick sort is _________.
A. O(1) B. O(logn) C. O(n) D. O(nlogn) E. O(n*n)
D.O(nlogn)
Using the partition algorithm to partition an array {5, 8, 10, 3, 4, 19, 2} for a quick sort, what is the resulting array after the partition?
A. {5, 8, 10, 3, 4, 19, 2} B. {2, 3, 4, 5, 8, 10, 19} C. {2, 3, 4, 5, 10, 19, 8} D. {3, 2, 4, 5, 10, 19, 8} E. {3, 2, 4, 5, 8, 10, 19}
D.{3, 2, 4, 5, 10, 19, 8}
To remove the root, you need to start a process by first placing _______ to the place of the root and move it down to maintain the heap property.
A. one of the root's children B. the larger child of the root C. the smaller child of the root D. the last node in the heap
D.the last node in the heap
To add a new node, you need to start a process by first placing it as _______ and move it up to maintain the heap property.
A. the new root B. the last node in the heap C. the left child of the root D. the right child of the root
B.the last node in the heap
A heap is represented using an array. Is the array {1 2 4 5 9 3} a heap?
A. Yes B. No
B. No