What will be displayed by the method call recurse

Assignment Help C/C++ Programming
Reference no: EM131065020

Question 1. Method A invokes method A itself. This is called _________.

indirect recursion

explicit recursion

direct recursion

one-step recursion

Question 2. What are the base cases in the following recursive method?

public static void recurse(int n)

{

if (n > 0)

{

System.out.print(n % 10);

recurse(n / 10);

}

}

Question 2 options:

n < 0

n <= 0

n > 0

no base cases

Question 3. What will be displayed by the method call recurse(1234)?

public static void recurse(int n)

{

if (n <= 0)

{

System.out.print(n % 10);

recurse(n / 10);

}

}

Question 3 options:

1234

4 3 2 1

Nothing

4321

Question 4. Analyze the following recursive method and indicate which of the following will be true.

public static long factorial(int n)

{

return n * factorial(n - 1);

}

Question 4 options:

Invoking factorial(2) returns 2.

Invoking factorial(1) returns 1.

The method runs infinitely and causes a StackOverflowError.

Invoking factorial(0) returns 0.

Question 5. Fill in the code to complete the following method for computing factorial.

// Return the factorial for a specified index

public static long factorial(int n)

{

if (n == 0)

return 1;

else

return _____________;

}

Question 5 options:

n * (n - 1)

n

n * factorial(n - 1)

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

Question 6. What will be displayed by the method call recurse(6)?

public static int recurse(int n)

{

if (n <= 1)

return 1;

else

return n + recurse(n - 2);

}

Question 6 options:

13

14

11

12

Question 7. The base case _________ the recursion.

Question 7 options:

stops

breaks

pauses

starts

Question 8. What is the output of the following program?

{

public static void main(String[] args)

{

System.out.println(countDown(2, 0));

}

public static int countDown(int n, int result)

{

if (n == 0)

return 0;

else

return countDown(n - 1, n + result);

}

}

Question 8 options:

1

3

0

2

Question 9. Which of the following statements about recursive methods is accurate?

Question 9 options:

They must have exactly 1 base case and exactly 1 recursive case

They must have at least 1 base case and at least 1 recursive case

They must have exactly 1 base case and at least 1 recursive case

They must have at least 1 base case and exactly 1 recursive case

Question 10. Which of the following is a possible disadvantage of recursion?

Recursive solutions can be less efficient than their iterative counterparts

Recursive solutions tend to have more local variables than their iterative counterparts

Recursive solutions tend to be longer than their iterative counterparts

Recursive solutions are more likely to go into infinite loops than their iterative counterparts

Question 11. To declare an interface named A with two generic types, use

public interface A(E) { ... }

public interface A<E, F> { ... }

public interface A<E> { ... }

public interface A(E, F) { ... }

Question 12. Will the following code have a runtime error?

Comparable date = new Date();

int i = date.compareTo("time");

Question 12 options:

Always

Never

Only when date contains an invalid date

Only when date is not the current date

Question 13. To create a list to store integers, use

Question 13 options:

ArrayList<Object> list = new ArrayList<Integer>();

ArrayList<Number> list = new ArrayList<Integer>();

ArrayList<int> list = new ArrayList();

ArrayList<Integer> list = new ArrayList();

Question 14. To create a generic type bounded by Number, use

Question 14 options:

<E extends Object>

<E extends Number>

<E>

<E extends Integer>

Question 15. Which of the following describes the benefit of using generic classes to implement collections?

Question 15 options:

It eliminates the need to downcast objects when they are removed from a collection

It eliminates the need to upcast objects when they are inserted into a collection

It eliminates the need to downcast objects when they are inserted into a collection

It eliminates the need to upcast objects when they are removed from a collection

Question 16. Suppose list list1 is [1, 2, 5] and list list2 is [2, 3, 6]. After list1.addAll(list2), list2 is __________.

Question 16 options:

[1, 5]

[1, 2, 3, 5, 6]

[2, 3, 6]

[1, 2, 2, 3, 5, 6]

Question 17. Suppose a list contains {red, red, red, red}. What is the list after the following code?

String element = "red";

for (int i = list.size() - 1; i >= 0; i--)

if (list.get(i).equals(element))

list.remove(element);

Question 17 options:

[red]

[red, red]

[]

[red, red, red]

Question 18. Which of the following is correct to sort the elements in a list aList?

Question 18 options:

Arrays.sort(aList)

new LinkedList<String>(new String[]{red, green, blue})

Collections.sort(aList)

aList.sort()

Question 19. Which of the following best describes all objects of type List?

Question 19 options:

They define an ordered collection that prohibits duplicates

They define an ordered collection that allows duplicates

They define an unordered collection that allows duplicates

They define an unordered collection that prohibits duplicates

Question 20. Which of the following problems would be a good candidate for using a stack?

Question 20 options:

A print spooler that dispatches jobs based on shortest job first

An inventory system that processes product records by product number

A program that is designed to evaluate expressions

A task scheduler that schedules tasks in the order that they are received

Reference no: EM131065020

Questions Cloud

Determine the angles ?p1 and ?p2 defining the orientations : Determine the angles θp1 and θp2 defining the orientations of the principal axes through the centroid C for the right triangle
Physicians and for-profit healthcare organizations : Please help: some physicians and for-profit healthcare organizations in your area are refusing to treat Medicare and Medicaid patients for a variety of reasons.
Determine the angles ?p1 and ?p2 defining the orientations : Determine the angles θp1 and θp2 defining the orientations of the principal centroidal axes and the corresponding principal
The tax consequences of catching the ball : I am the lucky fan who just caught a historic baseball that has instantly appreciated in value as it left the ballpark. What are the tax consequences of catching the ball? research and answer the following questions: Is the catch of the ball taxab..
What will be displayed by the method call recurse : Which of the following problems would be a good candidate for using a stack? Which of the following best describes all objects of type List?
Determine the critical load pcr for the structure : The figure shows an idealized structure consisting of one or more rigid bars with pinned connections and linearly elastic springs.
In a situation similar to larry buckingham : Prepare a case analysis (8 pages max) utilizing the case study framework below. Please do not make relevant and appropriate use of data included in the case study. There is no need to conduct additional research, utilize the information presented ..
What is the credit union maximum expected profit : A department store in a small town is in the process of budget planning and will be building a decision tree to select the best option among its available marketing channels. What is the credit union maximum expected profit
Compare different types of partitions-disks and volumes : You are tasked to design Windows 2008 servers to host a database and the company's Web application that will be used heavily by 1,000 employees. The goals are to minimize the downtime, provide the best possible performance for both the application..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Compare the amplitude of the two sinewaves

Store the 600 sample values of x[n] in file filex and store the 600 sample values of y[n] in file filey. Graph x[n] and y[n] on the same graph using Excel. Compare the amplitude of the two sinewaves x [n] and y[n].

  Program that allows the user to enter the last names

The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate.

  Complete the 8 queens 2 dimensional array

Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better unde..

  Reading of coefficients

Reading of coefficients a, b, c shall be done by a function named readCoeffs(). They shall be entered as double's from the keyboard by an operator, after prompt, as follows.

  Write two short c programs and solve four exam-style

write two short c programs and solve four exam-style problems. details on the programs are as follows.program

  How to implement a state transition diagram

An Automated External Defibrillator (AED) is used in first aid ere someone has had a heart attack and needs to be kept alive until an ambulance arrives.

  Design and run a program that takes a numerical score

In this program, create two void functions titled getScore and printGrade with an int argument. The function getScore should have a Reference parameter and printGrade should have a Value parameter.

  Write some code that puts a zero in every element of q

Given a two-dimensional array of integers named q, with 2 rows and 4 columns, write some code that puts a zero in every element of q. Declare any variables needed to help you.

  What is the output

Suppose that x and y are int variables, z is a double variable, and ch is a char variable. Suppose the input statement is.

  Program for search the telephone number

To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN.

  Describe your experiences on writing your first c program

Describe your experiences on writing and testing your first C program. Gives examples of where you got stuck?. What difficulties you faced? What did you learn from this experience?

  Program that prompts the user to enter the year

Write a program that prompts the user to enter the year and the month and displays on the console the calendar table for the month.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd