WYSE Academic Challenge State Finals Computer Science 2007 Solution Set 1. Correct answer: C. a) PGP is for encrypting documents, traditionally used for email. b) SSH is used to gain secure access to a server. d) WEP is a flawed protocol for encrypting wireless network traffic. 2. Correct answer: D. The first three items: a small loop, a small set of variables, or a linear search, will all access memory locations that are very close to each other. However, when accessing a new function, it must be loaded into memory before it can be run, so the locality is lost while the data/function is found on secondary storage and loaded into memory. 3. Correct answer: C. Email, web, and streaming audio all follow the traditional client server model. P2P applications, such as Kazaa, involve transfer of data from one peer to another peer. Some P2P applications may have no central server coordinating the communication at all. 4. Correct answer: B. 11110111 is equivalent to 11110111 (-9) - 00011101 + 11100011 (-29) 11011010 (-38) The bit that is carried does not matter when using 2's compliment. 5. Correct answer: A. There are 23 binary digits that can be used to determine the significant portion of the number itself (not the exponent). This yields, 2 23 or 8,388,608 different combinations which when normalized makes each combination carry a significance of 1/2 23 1.2 x 10-7. This will represent 6 decimal digits accurately, but not quite 7. 6. Correct answer: A. (A and B and not D) or (A and B and D) or not(a and B and D) Substituting the value of false for D yields the following expression. (A and B and true) or (A and B and false) or not(a and B and false) The 1 st expression depends only upon A and B since third item is always true. (A and B) or (A and B and false) or not(a and B and false) 2 nd and 3 rd expressions simplify to false, as any logical AND with a false is false. (A and B) or false or not(false) Invert 3 rd expression. (A and B) or false or true Any logical OR with a true component is always true. true
7. Correct answer: D. PUSH F, PUSH E, MUL results in E*F on the stack PUSH D, SUB results in D-E*F on the stack POP X results in an empty stack and x = D-E*F PUSH C, PUSH B, MUL results in B*C on the stack PUSH A, ADD results in A + B*C on the stack PUSH X, DIV results in (A + B*C) /(D - E*F) on the stack POP X results in X = (A + B*C) /(D - E*F) 8. Correct answer: C. The expression can be rewritten as: ( (not B and C) and not (A or C) ) or (A xor C) ( (true and C) and not (true or C) ) or (true xor C) substitute values for A and B ( C and not (true or C) ) or (true xor C) 1 st expression depends only on C ( C and not (true) ) or (true xor C) 2 nd expression is always true ( C and false ) or (true xor C) invert true (false) or (true xor C) and expression always false true xor C false does not affect or not C true xor just inverts value See truth table for exclusive or - xor X Y X xor Y F F F F T T T F T T T F 9. Correct answer: E. This is a recursive function call. Prove by induction. If y <= 0 the function clearly returns 0. Base Case: y = 1, func(x,1) = x*(func(x,0) + 1) = x*(0 + 1) = x 1 Assume: func(x, n) returns (x + x 2 +... + x n ) Inductive Step: func(x, n+1) = x*(func(x, n) + 1) = x*((x + x 2 +... + x n ) + 1) Therefore func(x,n+1) = x + x 2 +... + x n+1 While very close to D, it is not exactly D. It is actually one degree higher. 10. Correct answer: B. The function performs a binary search of a list that is sorted in decreasing order, returning the index of the number in the array. If the array does not contain the item, it returns a -1, which is not a valid index for the array. Tracing the code for this example l h m f 0 7? -1 0 7 3-1 m:=(l+h)/2 0 2 3-1 h := m-1 0 2 1-1 m:=(l+h)/2 0 2 1 1 item found
11. Correct answer: C. A binary search cuts the list in half each time. Its rate of growth with respect to the number of items in the list is the inverse of exponential, it is logarithmic. In the worst case, it makes log 2 n comparisons when the list has n items, although the item being searched for may be found quicker than this. 12. Correct answer: E. Trace through the code: i j 0 0 0 1 increment j and then print j 1 0 2 increment j and then print j 2 0 3 increment j and then print j 3 0 4 increment j and then print j 4 0 5 increment j and then print j 5 2 5 i:= i+2 4 5 in for loop i:=i+2 4 0 reset j to zero before while loop 4 5 j := j + i +1 and then print j 5 6 5 i:=i+2 8 5 in for loop i:=i+2 8 0 reset j to zero before while loop 8 9 j:=j + i + 1 and then print j 9 10 9 i:=i+2 12 9 in for loop update i print i, then print j PRINTS: 1234559129 13. Correct answer: A. A heap can be used to represent a priority queue. It does not work for a general stack. It is a type of tree and does not represent an ordered array. The most appropriate answer is A. - - Go To Next Page - -
14. Correct answer: B. The static variable is shared by the multiple instances of function func, but it is initialized once to 0. So tracing the call: func(3) 3 1 0 function executes r:= 3 + func(1) func(1) 1 1 0 function executes r:= 1 + func(-1) func(-1) -1 1 0-1 1 1 increment i, note i will now be 1 for all prints -11 return 1 resume func(1) 1 2 1 1 2 2 increment i, note i changes for func(3) as well prints 12 return 2 resume func(3) 3 5 2 3 5 3 increment i print 33 return 5 PRINTS: -111233 15. Correct answer: B. If m = x then a := x-m+1 =x x + 1= 1, then the loop is multiplying all of the integers from x to 1. 16. Correct answer: E. At each iteration the value of i is approximately doubled, therefore at say, iteration x we have that i is approximately equal to 2 x >=n log 2 2 x >= log 2 n x*log 2 2 >= log 2 n x >= log 2 n. Therefore the algorithm is on order of log 2 n i.e. O(log 2 n) 17. Correct answer: B. An array implementation of a binary tree has the root in element 1 and left child of node i in element 2*i and the right child in element 2*i+1. 18. Correct answer: A. This code computes the determinant of a 3x3 matrix. (2*4*9) (2*8*2) + (-1*8*7) - (-1*3*9) + (1*3*2) (1*4*7) 72 32-56 + 27 + 6-28 -11 19. Correct answer: E. This code actually removes the front element of the queue.
20. Correct answer: B. The R+1 advances the element and the mod M circles back after reaching the maximum element. The question makes no assumption about a full queue. 21. Correct answer: A. Algorithm 1 requires 1802 and algorithm 2 requires 2122 steps. 22. Correct answer: D. 2*N 2 + 2 = 66*N + 142, 2*N 2-66*N 140 = 0, N 2-33*N 70 = (N + 2)*(N-35) The 2 zeros of the function are N=-2 and N=35. Since the size of an input cannot be negative the answer is D. 23. Correct answer: A. Parsing the pre-order from left to right we see A is the root, then looking at the inorder traversal every thing to the left of A is in the left child and everything to the right is in the right child. The next element from the pre-order traversal is B and it is to the left in the in-order traversal so it is the root of the left subtree of A. Continuing reconstructs the tree and the answer is A. 24. Correct answer: D. Examining the code: INSTRUCTION ACTION d now points to b d := &b; a.data := 5; a's data is 5 b.data := 7; b's data is 7 c.data := 10; c's data is 10 a.next := &c; a now points to c b.next := &a; b now points to a, b now first c.next := NULL; c points to nothing, no circular list (*d).data := 9; change data on what d points to (b) to 9 Since b is the first item in the list, followed by a and then c, the order is 9 5 10. 25. Correct answer: B. Examine each section of the first three sets of code: INSTRUCTION ACTION a) tmp := new node; create new node (*tmp).data := 2; put 2 into new node (*tmp).next := tail; point new node a tail tail := tmp; point tail at new node The very end of the list will not point to NULL, it will point to the element that contains 11 as the next pointer for tmp was assigned to tail before tail was shifted. The structure of the list is compromised as now you can never tell where the end of the list is. b) (*tail).next := new node; create new node at very end of list tail := (*tail).next; point tail to new node just created (*tail).data := 2; put 2 into new node (*tail).next := NULL; make sure last item points to NULL WORKS c) tmp := new node; create new node (*tail).data := 2; put 2 into last item in list, overwriting the 11 (*tmp).next ;= (*tail).next; point the new item to what tail points to, NULL (*tail).next ;= tmp; point tail to the new item just added This does not work for two reasons. Part of the old list is overwritten. No new data goes into the new node created.
26. Correct answer: C. This nested loop adds up the sum of all the factorials less than or equal to a given number if the number is positive. The inner loop computes the factorial of j and stores it in s1: BASE CASE: j = 1. Loop runs once, s1 stays 1 ASSUME: loop works for n, leaving s1 = n! ITERATIVE STEP: The for loop will now work n+1 times, but for the first n times it iterates, s1 = n! and then: s1 = s1*(n+1) = n!*(n+1) = (n+1)! The outer loop adds up the s1's computed each for i=1 to and including x. 4! + 3! + 2! + 1! = 24 + 6 + 2 + 1 = 33 27. Correct answer: D. Message passing is a way to invoke a member function in object oriented programming. 28. Correct answer: D. This is an example of operator overloading. 29. Correct answer: C. Although the symbol being used is *, the functionality is the addition of 2 dimensional arrays representing matrices. 30. Correct answer: A. A subclass is a class that inherits properties from a superclass.