---------------------------------------- ** On paper portion. Last Name: First Name: FOR EVERY PROBLEM, SHOW YOUR WORK... NOTE: do the last problem last, if too many people run out of time we won't count the last problem (#9). NOTE: for #8, only do 2 of the 3 parts, I'll only count 2 of them. Points: 1/2 pt each for 3b, 6a, 6b, 6c, 6d, 7a, 7b, 7c, 7d 1 pt each for 1a, 1b, 2a, 2b, 3c, 3d 2 pts each for 3a, 4, 5, 8a, 8b, 8c, 9 Total points: 24.5 NOTE: parts that are 1/2 pt will be graded all or nothing (no partial credit. parts that are 1 pt will be graded as right, wrong, or 1/2 credit. parts that are 2 pts will be graded as 0, 1/2, 1, 1.5, 2. 1a) Convert 8 from decimal to binary. 1b) Convert 0100 0110 from binary to decimal. What is this as an ASCII character? 2a) What is the range of values that can be stored in a 6 bit unsigned integer? 2b) Give a formula for the range of values that can be stored in a 32 bit unsigned integer. 3a) Fill in the table of big-O running times, where n is the # of numbers. NOTE: the order of the rows is not the same as on the sample exam. Algorithm Running time ------------------------------------------------- Selection sort Insertion sort Linear search Merge sort Quick sort Binary search 3b) What is the value of log_2(1024)? (Note that 1024 = 2^10)? NOTE: _ means subscript, ^ means superscript. 3c) Compute the running time (# of steps) of linear search when n=1024: 3d) Compute the running time (# of steps) of merge sort when n=1024: 4) Given the following list of numbers, show what the list looks like after each step of selection sort. 2 8 5 6 7 1 3 4 5) Decrypt the following message using the caesar cipher and a shift value of 4. csy teww 6) For each of the following, what is the final value of x? 6a) int x = 1 + 4 * 3; 6b) float x = 11 / 4 * 3.0; 6c) char x = 'c'; x += 3; 6d) int x = 14 % 5; 7) For each of the following boolean expressions, determine whether it is true or false. 7a) (10 == 3 || 3 != 10) 7b) (strcmp("hi","HI") == 0) 7c) ('a' < 'b' && 'b' != 'a') 7d) ! ( strcmp("hi","HI") == 0) 8) Be the computer. For each of the following, keep track of the values of all the variables as the code runs - as we have done on the board in class. NOTE: CHOOSE ONLY 2 OF THESE TO DO, ONLY 2 WILL COUNT! 8a) int decrease(int x) { return x - 1; } int isZero(int x) { if (x == 0) return 1; else return 0; } int main() { int y = 3; y = decrease(y); printf("%i\n", y); y = isZero(y); printf("%i\n", y); } 8b) char msg[10] = "great"; int i; for(i=0; msg[i] != '\0'; i++) { if (msg[i] < 'k') msg[i] = '#'; } printf("%s\n", &msg); 8c) char msg[10] = "12.45+7"; int i=0; while (isdigit(msg[i])) { i++; } msg[i] = '\0'; int x = atoi(msg); printf("%i\n", x); 9) Memorize program. Write down the code for basic_smallest.c Assume you have an array of 10 integers in a variable calls numbers. Write the code for the main function to determine the smallest number in the array, and print that number. NOTE: JUST WRITE THE MAIN FUNCTION. HERE's A START... #include #include int main() { // first, declare the numbers array... // second, write a loop to determine the smallest... }