1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ololo11 [35]
3 years ago
8

For the recursive method below, list the base case and the recursive statement, then show your work for solving a call to the re

cur() method using any parameter value 10 or greater.
public static int recur(int n)
{
if(n < 1)
{
return 3;
}
else
{
return recur(n / 5) + 2;
}
}

Computers and Technology
1 answer:
Paul [167]3 years ago
3 0

Answer:

(a): The base case: if(n<1)

(b): The recursive statement: recur(n / 5)

(c): Parameter 10 returns 7

Explanation:

Given

The above code segment

Solving (a): The base case:

The base case is that, which is used to stop the recursion. i.e. when the condition of the base case is true, the function is stopped.

In the given code, the base case is:

<em>if(n<1)</em>

Solving (b): The recursive statement:

The recursive statement is the statement within the function which calls the function.

In the given code, the recursive statement is:

<em> recur(n / 5)</em>

<em />

Solving (c): A call to recur() using 10

The base case is first tested

if (n < 1); This is false because 10 > 1

So, the recursive statement is executed

<em>recur(n/5) +2=> recur(10/5)+2 => recur(2)+2</em>

2 is passed to the function, and it returns 2

if (n < 1); This is false because 2 > 1

So, the recursive statement is executed

<em>recur(n/5) +2=> recur(2/5)+2 => recur(0)+2</em>

2 is passed to the function, and it returns 2

<em />

if (n < 1); This is true because 0 < 1

This returns 3

So, the following sum is returned

Returned values = 2 + 2 + 3

Returned values = 7

You might be interested in
For this programming assignment you will implement the Naive Bayes algorithm from scratch and the functions to evaluate it with
DanielleElmas [232]

Bayes’ Theorem provides a way that we can calculate the probability of a piece of data belonging to a given class, given our prior knowledge.

P(class|data) = (P(data|class) * P(class)) / P(data)

Where P(class|data) is the probability of class given the provided data.

Explanation:

  • Naive Bayes is a classification algorithm for binary  and multiclass classification problems.
  • It is called Naive Bayes or idiot Bayes because the calculations of the probabilities for each class are simplified to make their calculations tractable.

This Naive Bayes tutorial is broken down into 5 parts:

Step 1: Separate By Class :  Calculate the probability of data by the class they belong to, the so-called base rate. Separate our training data by class.

Step 2: Summarize Dataset : The two statistics we require from a given dataset are the mean and the standard deviation

The mean is the average value and can be calculated using :

mean = sum(x)/n * count(x)

Step 3: Summarize Data By Class : Statistics from our training dataset organized by class.

Step 4: Gaussian Probability Density Function : Probability or likelihood of observing a given real-value. One way we can do this is to assume that the values are drawn from a distribution, such as a bell curve or Gaussian distribution.

Step 5: Class Probabilities :  The statistics calculated from our training data to calculate probabilities for new data.  Probabilities are calculated separately for each class. This means that we first calculate the probability that a new piece of data belongs to the first class, then calculate the second class, on for all the classes.

8 0
3 years ago
Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6
galina1969 [7]

Answer:

The function in C++ is as follows:

int isSorted(int ar[], int n){

if (n == 1 || n == 0){

 return 1;}

if (ar[n - 1] < ar[n - 2]){

 return 0;}

return isSorted(ar, n - 1);}

Explanation:

This defines the function

int isSorted(int ar[], int n){

This represents the base case; n = 1 or 0 will return 1 (i.e. the array is sorted)

if (n == 1 || n == 0){

 return 1;}

This checks if the current element is less than the previous array element; If yes, the array is not sorted

if (ar[n - 1] < ar[n - 2]){

 return 0;}

This calls the function, recursively

return isSorted(ar, n - 1);

}

6 0
3 years ago
Headphones are an example of _____.
katen-ka-za [31]
The Answer Is An Output Device 


3 0
3 years ago
Read 2 more answers
Create a directory called projects directly inside /home/fparker. Change the owner of /home/fparker/projects to the fparker user
AlekseyPX
Cd /home/fparker
mkdir projects
chown /home/fparker/projects fparker:fparker
adduser ljenkins (set password to password123 in menu)

Use either “fdisk” or “parted” to format the disk, I can’t completely answer that part of the question without knowing the hierarchy of the file system)
4 0
2 years ago
Write a MIPS program to continuously generate the following series of integers: 1, 2, 3, 6, 9, 18, 27, 54, 81, and so on. Use st
Pachacha [2.7K]

Answer:

Explanation:

Here is a working solution in MIPS

.data

space: .asciiz ", "

.text

li $t1, 1       #Start at 1

li $t2, 1       #Store last value

li $t4, 1000    #terminate at 1000

li $t7, 2       #For division (divide by 2)

loop:

li $v0, 1

add $a0, $t1, $zero #print $t1

syscall

div $t1, $t7      #divide $t1 by 2

mfhi $t5          #get the remainder

move $t6, $t1     #hang on to what $t1 was originally

beqz $t5, even    #if the remainder is 0, it's even

add $t1,$t1,$t1    #it's odd, so add to itself

move $t2, $t6      #store what $t1 was originally to last value

bgt $t1, $t4, done #if the number is over 1000, we're done

li $v0, 4           #Print a comma and space

la $a0, space

syscall

j loop

even:

add $t1,$t1,$t2    #set $t1 = $t1 + Last value ($t2)

move $t2, $t6      #store what $t1 was originally to last value

bgt $t1, $t4, done #if the number is over 1000, we're done

li $v0, 4           #Print a comma and space

la $a0, space

syscall

j loop

done:

3 0
4 years ago
Other questions:
  • Which of these molecules has the same number of shared and unshared electron pairs?CCl2F2Br2HClPF3H2S
    9·2 answers
  • How to make a sad face on keyboard using alt?
    5·2 answers
  • Maggie is preparing a document.she wants to open the help menu to sort out a formatting problem.which key should she press to op
    15·2 answers
  • Declare an array named tax rates of five elements of type double and initialize the elements (starting with the first) to the va
    12·1 answer
  • Sadie helman runs a web site for amateur snowboarders. she likes to post videos and music related to snowboarding on her site as
    12·1 answer
  • In their legacy system. Universal Containers has a monthly accounts receivable report that compiles data from Accounts, Contacts
    6·1 answer
  • In python
    9·1 answer
  • Which of the following statements is FALSE?
    10·2 answers
  • I need to convert seconds since Unix Epoch so like the year, month, day, hour, minute, and second but I cannot figure it out. If
    14·1 answer
  • According to the video, which tasks do Police Patrol Officers perform? Select all that apply.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!