In the nested for loop, lines 8-11, j will not increment to the point where any elements will be written in beyond the last element of array A, because:
```
1 COUNTING-SORT( A )
2 make an Array C of length k + 1
3 for each i, from 0 to k
4 C[ i ] = 0
5 for each j, from 0 to the length of A - 1
6 C[ A[ j ] ]++
7 j = 0
8 for each i from 0 to k
9 for each m from 1 to C[ i ]
10 A[ j ] = i
11 j++
```
A. C[i] will be 0 much of the time, so lines 10-11 will be seldom executed
B. k will not be that large, or we wouldn’t be using counting sort
C. All the C[i], from i = 0 to i = k, when added together, will give the total number of elements in array A
D. j won’t be incremented beyond m, which is much smaller than the index of the last element of A
C
You might also like to view...
Answer the following statements true (T) or false (F)
1) The statement always displays x is 10, regardless of the value of x when the statement is encountered. ``` if (x = 10) cout << "x is 10" << endl; ``` 2) The value of the expression is true. ``` 15< 20 || 20 >= 20 ``` 3) C++ has a data type named bool whose only values are true and false. 4) Evaluating only as much of an expression as is necessary is called short-circuit evaluation. 5) The code fragment on the left always gives p the same value as the code fragment on the right. ``` if (x > 15) if (x > 15) p = p * x; p = p * x; if (x > 30) else if (x > 30) p = 2 * p * x; p = 2 * p * x; ```
Adobe Flash video files have the ________ file extension
A) .asf B) .bmp C) .swf D) .avi
Identify the letter of the choice that best matches the phrase or definition.
A. Each record is made up of one or more of these. B. Used to identify the fields. C. Appears at the top of each column in a table and contains the field name. D. The data entered into a field. E. A complete set of data.
Answer the following statements true (T) or false (F)
1. The ADTs sorted list and list are completely different in their implementations. The addition to a sorted list is an O(n) operation. 2. It is not possible to use the ADT list when implementing an ADT sorted list. 3. The copy constructor creates a new list and then copies the entries in the given sorted list to the new list. 4. The implementation of the sorted list using containment is both easy to write and efficient if the underlying list uses a chain of linked nodes. An is-a relationship implies public inheritance.