Question
(1) public static int exampleRecursion (int n) { if (n == 0) return 0; else return exampleRecursion(n - 1) + n * n * n;
(1) public static int exampleRecursion (int n) {
if (n == 0)
return 0;
else
return exampleRecursion(n - 1) + n * n * n;
}
What does the code in the accompanying figure do?
(a) Returns the cube of the number n
(b) Returns the sum of the cubes of the numbers, 0 to n
(c) Returns three times the number n
(d) Returns the next number in a Fibonacci sequence
(2) How many base cases are in the code in the accompanying figure?
(a) zero (b) one (c) two (d) three
(3) What is the output of exampleRecursion(3) ?
(a) 25 (b) 32 (c) 36 (d) 42
(4) Consider the following list.
list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};
Suppose that sequential search as discussed in the book is used to determine whether 2 is in list. Exactly how many key comparisons are executed by the sequential search algorithm?
(a) 3 (b) 4 (c) 5 (d) 8
(5) Consider the following list.
list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};
Suppose that sequential search as discussed in the book is used to determine whether 95 is in list. Exactly how many key comparisons are executed by the sequential search algorithm?
(a) 1 (b) 8 (c) 9 (d) 10
(6) What is the minimum number of comparisons that have to be made to find 18 using a sequential search on the list shown in the accompanying figure?
list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};
(a) 1 (b) 2 (c) 3 (d) 4 (e) 5
(7) Based on the accompanying figure, in a sequential search, what is the minimum number of comparisons that have to be made if the search item was 10 ?
list = {20, 10, 17, 2, 18, 35, 30, 90, 48, 47};
(a) 0 (b) 1 (c) 7 (d) 8 (e) 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started