WYSE Academic Challenge State Finals Computer Science 2007 Solution Set

Similar documents
WYSE Academic Challenge Regional Computer Science 2008 Solution Set

WYSE Academic Challenge Computer Science Test (State) 2015 Solution Set

Lecture Notes for Advanced Algorithms

WYSE Academic Challenge Computer Science Test (Regional) 2015 Solution Set

Department of Computer Science and Technology

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Assignment 1. Stefano Guerra. October 11, The following observation follows directly from the definition of in order and pre order traversal:

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

CS 216 Exam 1 Fall SOLUTION

CSE 230 Intermediate Programming in C and C++

Data Structures Question Bank Multiple Choice

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Analysis of Algorithms. CS 1037a Topic 13

Analysis of Algorithms

Binary Search Trees Treesort

CS 3410 Ch 7 Recursion

SELF-BALANCING SEARCH TREES. Chapter 11

Question Bank Subject: Advanced Data Structures Class: SE Computer

Chapter 4: Trees. 4.2 For node B :

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CS 221 Review. Mason Vail

Solutions to relevant spring 2000 exam problems

DDS Dynamic Search Trees

WYSE Academic Challenge 2002 Computer Science Test (Sectional) SOLUTION

Monday, April 15, We will lead up to the Analysis and Synthesis algorithms involved by first looking at three simpler ones.

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

Chapter 2: Basic Data Structures

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Sorting Pearson Education, Inc. All rights reserved.

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Midterm solutions. n f 3 (n) = 3

Lecture 26. Introduction to Trees. Trees

Assignment 8 CSCE 156/156H/RAIK 184H Spring 2017

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Overview of Sorting Algorithms

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CSCE 2014 Final Exam Spring Version A

16 Greedy Algorithms

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

Recursive Data Structures and Grammars

CS301 - Data Structures Glossary By

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

We assume uniform hashing (UH):

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

Course Review for Finals. Cpt S 223 Fall 2008

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CS-301 Data Structure. Tariq Hanif

Summer Final Exam Review Session August 5, 2009

Basic Data Structures (Version 7) Name:

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Computer Science E-22 Practice Final Exam

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Tree traversals and binary trees

Recitation 9. Prelim Review

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Computer Science 302 Spring 2007 Practice Final Examination: Part I

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

CSE100. Advanced Data Structures. Lecture 12. (Based on Paul Kube course materials)

Data Structure Advanced

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

O(n): printing a list of n items to the screen, looking at each item once.

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CMSC351 - Fall 2014, Homework #2

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

V Advanced Data Structures

Assignment 1 (concept): Solutions

Algorithms and Data Structures

DATA STRUCTURES AND ALGORITHMS

Binary Trees

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

1. O(log n), because at worst you will only need to downheap the height of the heap.

EE 368. Week 6 (Notes)

PRACTICAL LIST FOR EVEN SEMESTERS (PGDCA/MCA/MSC (CS))

INF2220: algorithms and data structures Series 1

Binary Trees, Binary Search Trees

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

DEEPIKA KAMBOJ UNIT 2. What is Stack?

Programming II (CS300)

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution

Lecture 6: Arithmetic and Threshold Circuits

Friday Four Square! 4:15PM, Outside Gates

17CS33:Data Structures Using C QUESTION BANK

Lecturers: Sanjam Garg and Prasad Raghavendra March 20, Midterm 2 Solutions

V Advanced Data Structures

UNIT III BALANCED SEARCH TREES AND INDEXING

Transcription:

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.