Question: Help please, Q. Fill in the code to complete the following method for computing a factorial. long factorial(int n) { if (n == 0) //

Help please,

Q. Fill in the code to complete the following method for computing a factorial.

long factorial(int n)

{ if (n == 0) // Base case return 1; else

return _____________; // Recursive call }

A) n * factorial(n - 1)

B) factorial(n) * factorial(n - 1)

C) n * (n - 1)

D) n

Q.

Rather than finding a new location for colliding data, a(n) _____ scheme stores the data in linked lists.

bucketing/separate chaining

double hashing

open addressing

linear probing

Q. What is the base case in the following recursive function?

void xMethod(int n)

{ if (n > 0)

{ cout << (n % 10) << endl; xMethod(n / 10); } }

A) There is no base case.

B) n != 0

C) n <= 0

D) n > 0

Q. In a preorder tree traversal, each node is processed ____ its children.

before

instead of

relative to the ordinal values of

after

Q. Suppose a list is {2, 9, 5, 4, 8, 1}. After the first pass of bubble sort, the list becomes:

2, 9, 5, 4, 1, 8

2, 1, 5, 4, 8, 9

2, 5, 4, 8, 1, 9

2, 5, 9, 4, 8, 1

2, 9, 5, 4, 8, 1

Q. Which of the following statements is true about this recursive function?

long f(int n)

{ return n * f(n - 1);

}

A) Invoking f(1) returns 1.

B) Invoking f(0) returns 0.

C) This function works perfectly for all n > 0.

D) The function runs infinitely and causes a crash.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!