HTTP/1.0 200 OK Content-type: text/html Test 11 -- Arrays

,6/8 17:55 CDT,Due date-->9/20/2000 10:00 CDT

  1. Which of the following subscripts accesses the 10th array element?
    1) [9] 2) [10] 3) {9} 4) {10}

  2. For x={3,4,5,6,7}, give the array reference for the fifth element.

  3. If you pass only an array as a parameter to a procedure, how does the procedure determine the number of elements?

  4. How many dimensions does x={{0,1}, {4}, {5,6,7}} have?
    1) 0 2) 1 3) 2 4) 3

  5. For Question 4, what does x[1] reference?
    1) nil 2) {0,1} 3) {0} 4) syntax error

  6. For Question 4, what does x[1,2] reference?
    1) nil 2) 1 3) 4 4) syntax error 5) 0

  7. For Question 4, what does x[1][2] reference?
    1) nil 2) 1 3) 4 4) syntax error 5) 0

  8. For Question 4, what does x[2][1] reference?
    1) nil 2) 1 3) 4 4) syntax error 5) 0

  9. Can the bounds of an array be increased at runtime
    1) yes 2) no

  10. How can you parameterize array creation so that the entire program can adapt to different problem sizes?

  11. How would you improve the following code?
    result=liters*3.0865;

  12. Can the same array store more than one element data type?
    1) yes 2) no

  13. For Question 4, check all the legal subscript references.
    1) x[3] 2) x[x[1]] 3) x[6.7] 4) x[true] 5) x["6"]

  14. All arrays are passed to procedures
    1) by value 2) by reference

  15. void p(int x[]){cout<<x[2];};
    void main(){
    int x[10],i;
    for (i=0;i<10;i++)x[i]=i+1;
    p(x);
    };
    What prints?
    1) 1 2) 2 3) 3 4) 4

  16. Answer the following questions for x={{0,1,3}, {4,8,9}, {5,6,7}}.
  17. How many rows does x have?

  18. How many columns does x have?

  19. How many initialized elements does x have?

  20. What is the subscript of the first element?

  21. Write a single statement that sets each element in the second row to 6.

  22. In the worst case, searching a 40-element, unordered, integer array for a matching value takes how many comparisons?
    1) 80 2) 20 3) 40 4) 33

  23. In the best case, searching a 40-element, unordered, integer array for a matching value takes how many comparisons?
    1) 13 2) 20 3) 10 4) 1

  24. In the worst case, searching a 64-element, sorted, integer array for a matching value takes how many comparisons?
    1) 6 2) 12 3) 64 4) 32

  25. Sort the sequence 23 7 9 11 2 18 56 4 into ascending order by hand.

  26. Using a binary search for 7 in the sorted sequence 1 2 3 4 5 6 7 8 9, which element index is compared first?
    1) 1 2) 9 3) 5 4) 0 5) 6

  27. Using a binary search for 7 in the sorted sequence 1 2 3 4 5 6 7 8 9, which element index is compared second?
    1) 1 2) 9 3) 4 4) 0 5) 7

  28. Using Interchange Sort, determine the state of the sequence 23 7 9 11 2 18 56 4 after the first pass through the array.

  29. Using Interchange Sort, determine the state of the sequence 23 7 9 11 2 18 56 4 after the second pass through the array.