# e2Answers - Part I Questionnumber 1 2 8 3 5 4 5 67 8 6 9 10...

This preview shows pages 1–5. Sign up to view the full content.

Part I Question number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Version A, number  here 3 8 5 13 14 4 1 6 2 12 7 9 10 11 Version B, number  here 12 2 11 8 7 4 10 3 5 13 1 6 14 9 Version C, number  here 5 12 3 2 9 1 13 11 8 14 4 10 6 7 How to interpret scramble: Question 1 on version A is question 3 here. Question 1 on version B is question 12 here. Question 1 on version C is question 5 here. For each question in part I, choose the best possible alternative and mark your choice on the bubble answer sheet. Only one choice per question is allowed. 1. Given the following method: static int doSomething(int a) { if (a > 10) return a; else return doSomething(a+1) + doSomething(a+5); } What is the value of b after this line of code executes? int b = doSomething(8); A. 11 B. 26 C. 42 D . 53 E. no value returned due to infinite recursion The call tree looks like:

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

View Full Document
2. Given the following two methods: static void f(int k) { g(k-1); } static void g(int k) { if (k == 0) return; f(k-1); } What describes all the values of x where the method call f(x) leads to infinite recursion? (Note: odd means 1,3,5, etc. and even means 2, 4, 6, etc.) A. No value of x causes infinite recursion B. x is odd or x < 0 C. x is even or x < 0 D. x is odd or x 0 E . x is even or x 0 If x==0, then you do g(-1) and you miss the base case and get infinite recursion. Whenever x 0 this heppens. If x = 2, then you do g(1), then f(0), then g(-1) and again miss the base case. This happens whenever x is even. 3. You are given a hash table using chained hashing where each entry in the hash table is a Sequence and new items are added at the head of the Sequence. The hash function is: h(key) = key % table size There are two versions of the hash table: I. hash table size is 7 II. hash table size is 4
Into each version, where the hash table is initially empty, you hash items with the keys: 28, 7, 21, 14 A . The number of items to search in the Sequence to find any one of the keys for version I is less than or equal to version II. B. The number of items to search in the Sequence to find any one of the keys for version I greater than or equal to version II C. The number of items to search in the Sequence to find any one of the keys for version I is always the same as version II D. The answer depends on the key to be found, e.g., sometimes one version searches fewer keys and sometimes the other version searches fewer keys. Version I gives: Version 2 gives: Here the Sequence is represented as a linked list. To find any value in version 1 takes less than or equal to work than version 2 since there is only one item at each entry in the hash table. 4. Given the following binary search tree

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

e2Answers - Part I Questionnumber 1 2 8 3 5 4 5 67 8 6 9 10...

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

View Full Document
Ask a homework question - tutors are online