Carrona Chapter 10

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

5) What is a growth-rate function?

Answer: A growth-rate function is a mathematical function used to specify an algorithm's order in terms of the size of the problem.

4) What is measured by an algorithm's growth rate?

Answer: An algorithm's growth rate measures how fast an algorithm's time requirement grows as a function of the problem size.

10) What is an external sort?

Answer: An external sort is a sorting algorithm that is used when the collection of data will not fit in the computer's main memory all at once but must reside on secondary storage such as a disk.

9) What is an internal sort?

Answer: An internal sort is a sorting algorithm that requires the collection of data to fit entirely in the computer's main memory.

2) What does the area analysis of algorithms focus on?

Answer: Analysis of algorithms is the area of computer science that provides tools for contrasting the efficiency of different methods of solution.

7) What is determined by average-case analysis?

Answer: Average-case analysis determines the average amount of time that an algorithm requires to solve problems of size n.

12) In the worst case, how many comparisons are required in the bubble sort?

Answer: In the worst case, the bubble sort requires n * (n - 1)/2 comparisons.

15) Compare the efficiencies of the quicksort and the mergesort in the worst case.

Answer: In the worst case, the quicksort is significantly slower than the mergesort. In the worst case, the quicksort is O(n2), while the mergesort is O(n * log2n).

17) Suppose we have three algorithms, and their orders are O(n2), O(2n) and O(log2 n). Arrange these orders in increasing magnitude.

Answer: O(log2 n) < O(n2) < O(2n).

18) Consider the following nested loop. What is the order of the algorithm? for (int i = 0; i < n; ++i) for (j = 1; j < n; j *= 2)

Answer: O(n log2 n)

19) Consider the following nested loop. What is the order of the algorithm? for (int i = 0; i < n; ++i) for (int j = i; j < n; ++j) for (int k = 1; k < 100; ++k) ...

Answer: O(n2)

1) What measurements are parts of a program's efficiency?

Answer: The amount of computer time and space that the program requires to execute.

8) When choosing between two algorithms, under what conditions can the efficiencies of the algorithms be ignored?

Answer: The efficiencies of the algorithms can be ignored if the problem size will always be small.

20) Suppose we wish to sort an array of 3-digit integers using radix sort. We will make three passes over the elements of the array. What occurs during the first pass?

Answer: The elements are sorted according to their 1's (rightmost) digit.

13) What is the drawback of the mergesort with respect to storage?

Answer: The mergesort requires an auxiliary array whose size equals the size of the original array. For languages, such as C++, which store the data items in the array, this requirement might not be acceptable in situations where storage is limited.

14) How does the quicksort partition an array?

Answer: The quicksort partitions an array into items that are less than the pivot and those that are greater than or equal to the pivot.

11) What is the sort key of a record?

Answer: The sort key is the part of a record that determines the sorted order of the entire record within a collection of records. A sorting algorithm uses a sort key to order records within a collection of records.

3) List the three factors which can cloud the comparison of algorithms performed by implementing the algorithms in Java and running the programs.

Answer: The three factors are differences in the implementation of the algorithms, differences in the computers used to run the programs, and differences in the test data.

6) What is determined by worst-case analysis?

Answer: Worst-case analysis determines the maximum amount of time that a given algorithm requires to solve problems of size n.

16) If an algorithm requires 2n3 + 17n2 + 54n + 512 operations to perform, where n is the size of the input data, then we say the order of the algorithm is O(_____).

Answer: n3

1) The analysis of an algorithm must take into consideration the computer that will be used to run a program that implements the algorithm.

False

3) According to the following statements: Algorithm A requires time proportional to n Algorithm B requires time proportional to n2 algorithm B's time requirement - as a function of the problem size n - increases at a slower rate than algorithm A's time requirement.

False

4) The values of the growth-rate function O(log2n) grow faster than the values of the growth-rate function O(n).

False

7) The efficiency of the selection sort depends on the initial arrangement of the data.

False

10) To sort numeric data, the radix sort treats a number as a character string.

True

2) An algorithm's time requirements can be derived as a function of the problem size.

True

5) The recursive binary search algorithm is a logarithmic algorithm.

True

6) Low-order terms can be ignored in an algorithm's growth-rate function.

True

8) For large arrays, the insertion sort is prohibitively inefficient.

True

9) The mergesort is a recursive sorting algorithm.

True

16) A growth-rate function of ______ implies a problem whose time requirement is constant. a) 1 b) n c) 2n d) log2n

a) 1

29) Each merge step of the mergesort requires ______ major operations. a) 3 * n - 1 b) 4 * n - 1 c) (n - 1)/2 d) n - 1

a) 3 * n - 1

19) A quadratic algorithm has the growth-rate function ______. a) O(n2) b) O(n3) c) O(2n) d) O(log2n)

a) O(n2)

30) The quicksort is ______ in the worst case. a) O(n2) b) O(n3) c) O(n * log2n) d) O(log2n)

a) O(n2)

10) Which of the following can be used to compare two algorithms? a) growth rates of the two algorithms b) implementations of the two algorithms c) test data used to test programs which implement the two algorithms d) computers on which programs which implement the two algorithms are run

a) growth rates of the two algorithms

6) Assuming a linked list of n nodes, the code fragment: Node curr = head; while (curr != null) { System.out.println(curr.getItem()); curr.setNext(curr.getNext()); } // end while requires ______ write operations. a) n b) n - 1 c) n + 1 d) 1

a) n

1) Which of the following is NOT part of the human cost of developing a computer program? a) the efficiency of a program b) the readability of a program c) the modifiability of a program d) the maintainability a program

a) the efficiency of a program

24) Given the following array: 4 15 8 3 28 21 which of the following represents the array after the second swap of the selection sort? a) 4 3 8 15 21 28 b) 4 15 8 3 21 28 c) 3 4 8 15 21 28 d) 21 4 3 8 15 28

b) 4 15 8 3 21 28

21) In the best case, a sequential search is ______. a) O(n) b) O(1) c) O(log2n) d) O(n2)

b) O(1)

13) If a problem of size n requires time that is directly proportional to n, the problem is ______. a) O(1) b) O(n) c) O(n2) d) O(2n)

b) O(n)

14) The value of which of the following growth-rate functions grows the fastest? a) O(n) b) O(n2) c) O(1) d) O(log2n)

b) O(n2)

11) Algorithm efficiency is typically a concern for ______. a) small problems only b) large problems only c) medium sized problems only d) problems of all sizes

b) large problems only

9) Consider an algorithm that contains loops of the form: for (x = 1 through n ) { for (y = 1 through x) { for (z = 1 through 10) { Task T } // end for } // end for } // end for If task T requires t time units, the loop on y requires ______ time units. a) 10 * t b) (10 * t) + x c) 10 * t * x d) t * x

c) 10 * t * x

15) The value of which of the following growth-rate functions grows the slowest? a) O(n) b) O(n2) c) O(1) d) O(log2n)

c) O(1)

20) An exponential algorithm has the growth-rate function ______. a) O(n^2) b) O(n^3) c) O(2^n) d) O(log2n)

c) O(2^n)

22) In the worst case, a binary search is ______. a) O(n) b) O(1) c) O(log2n) d) O(n2)

c) O(log2n)

18) A linear algorithm has the growth-rate function ______. a) O(log2n) b) O(2n) c) O(n) d) O(1)

c) O(n)

25) Given the fact that a selection sort of n items requires n2/2 + 5 * n/2 - 3 major operations, the selection sort is ______. a) O(n) b) O(1) c) O(n2) d) O(n2/2)

c) O(n2)

26) The ______ compares adjacent items and exchanges them if they are out of order. a) selection sort b) binary search c) bubble sort d) quicksort

c) bubble sort

4) Assuming a linked list of n nodes, the code fragment: Node curr = head; while (curr != null) { System.out.println(curr.getItem()); curr.setNext(curr.getNext()); } // end while requires ______ assignments. a) n b) n - 1 c) n + 1 d) 1

c) n + 1

5) Assuming a linked list of n nodes, the code fragment: Node curr = head; while (curr != null) { System.out.println(curr.getItem()); curr.setNext(curr.getNext()); } // end while requires ______ comparisons. a) n b) n - 1 c) n + 1 d) 1

c) n + 1

23) The selection sort is continued until ______ of the n items in an array have been swapped. a) n/2 b) n - 2 c) n - 1 d) n

c) n - 1

27) A bubble sort requires at most ______ passes to sort an array of n items. a) n/2 b) n - 2 c) n - 1 d) n

c) n - 1

12) Given the statement: Algorithm A requires time proportional to f(n) Algorithm A is said to be ______. a) in class f(n) b) of degree f(n) c) order f(n) d) equivalent to f(n)

c) order f(n)

2) Algorithm analysis should be independent of all of the following EXCEPT ______. a) the programming style used in the implementation of the algorithm b) the computer used to run a program which implements an algorithm c) the number of significant operations in an algorithm d) the test data used to test a program which implements an algorithm

c) the number of significant operations in an algorithm

7) The solution to the Towers of Hanoi problem with n disks requires 2n - 1 moves. If each move requires the same time m, the solution requires ______ time units. a) 2n - 1 b) (2n - 1) + m c) (2n - 1) / m d) (2n - 1) * m

d) (2n - 1) * m

8) Consider an algorithm that contains loops of the form: for (x = 1 through n ) { for (y = 1 through x) { for (z = 1 through 10) { Task T } // end for } // end for } // end for If task T requires t time units, the innermost loop on z requires ______ time units. a) y b) 10 c) z * t d) 10 * t

d) 10 * t

17) Which of the following growth-rate functions indicates a problem whose time requirement is independent of the size of the problem? a) O(n) b) O(log2n) c) O(2n) d) O(1)

d) O(1)

28) In the worst case, the insertion sort's comparison occurs ______ times. a) n b) n - 1 c) (n - 1) / 2 d) n * (n - 1)/2

d) n * (n - 1)/2

3) An algorithm's execution time is related to the number of ______ it requires. a) parameters b) test data sets c) data fields d) operations

d) operations


Set pelajaran terkait

Real Estate 100 - Chapter 1 - Real Estate License Requirements

View Set

CH 55 Med Surg Assessment of integumentary Function

View Set

The CE Shop Real Estate Course Final

View Set

Chapter 04: Prenatal Care and Adaptations to Pregnancy

View Set