Final0 - Computer Science I Fall 2008 Final exam 1 8 2 10 3...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science I Fall 2008 Final exam 1 2 3 4 5 6 7 8 9 10 11 12 8 10 12 8 6 1 2 6 24 10 9 4 Closed book, closed notes, no computers or calculators of any kind. There should be an empty space on both sides of each student. Name: RCS login: Circle your lab section: (01 MTh 10:00) (02 MTh 12:00) (03 MTh 2:00) (04 MTh 4:00) (05 MTh 6:00) (06 MTh 10:00) (07 TF 10:00) (08 TF 12:00) (09 MTh 12:00) (10 TF 2:00) (11 MTh 4:00) (12 MTh 6:00) 1. Show the output displayed by the following program as it would appear on the screen of a computer. (8 points) #include <iostream> using namespace std; int main () { int a[6][4]; int b, c, d; for (b=3; b >= 0; b--) { for (c = 0; c < 6; c++) { if ((b+c)% 3 == 0 ) { a[c][b] = b; } else { a[c][b] = -b; } } } for (d = 0; d < 4; d++) { cout << a[5][d] << endl; } return 0; }
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
0 1 -2 -3 2. Write functions to do the following. a. Compute the sum of the bottom row of a 150 x 50 integer array and return the result (5 points). b. Compute the sum of the back diagonal of a 150 x 150 integer array (a[0][149] + a[1][148] to a[149][0]). (5 points). int sum(int array[] [50]){ int sum = 0; for (int i=0; i<150; i++) { sum+= array [i][49]; } Retrun sum; } Int sum (int array[] [150]) Int sum = 0; For (int i=0; i<150; i++) { Sum+=array [i][ 149 -i]; } } Return sum; }
Image of page 2
3. Consider an unsorted list with 1,000 numbers stored in a one-dimensional array. And assume log (1,000) = 10 a) In the average case, approximately how many numbers in the list will have to be examined to find a number using linear search? (4 points) 500 b) In the average case, approximately how many operations must be performed to sort the list using Quick Sort. (4 points) 10000 c) If only two adjacent items are out of order, approximately how many operations must be performed to sort the list using Bubble Sort. (4 points) 2000 4. Consider the following list of 10 integer numbers stored in a one-dimensional array: 4 8 17 29 36 41 46 49 53 79 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Suppose that you use binary search to search this list.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern