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

Info iconThis 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; }
Background image of page 1

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

View Full DocumentRight 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; }
Background 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. a)
Background image of page 3

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

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

This note was uploaded on 04/04/2011 for the course CORE 101 taught by Professor Poop during the Spring '08 term at Rensselaer Polytechnic Institute.

Page1 / 10

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online